Skip to content

Instantly share code, notes, and snippets.

@barrett777
Forked from Jaecen/AlwaysReturns.cs
Created February 22, 2017 00:54
Show Gist options
  • Select an option

  • Save barrett777/3798bfd2b5f22e6c9419fb2c6591c185 to your computer and use it in GitHub Desktop.

Select an option

Save barrett777/3798bfd2b5f22e6c9419fb2c6591c185 to your computer and use it in GitHub Desktop.

Revisions

  1. @Jaecen Jaecen created this gist Feb 22, 2017.
    20 changes: 20 additions & 0 deletions AlwaysReturns.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    using System.Net;
    using System.Net.Http;
    using System.Threading;
    using System.Threading.Tasks;

    namespace DotUpgrade.Test
    {
    class AlwaysReturns : HttpMessageHandler
    {
    readonly HttpStatusCode StatusCode;

    public AlwaysReturns(HttpStatusCode statusCode)
    {
    StatusCode = statusCode;
    }

    protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    => Task.FromResult(new HttpResponseMessage(StatusCode));
    }
    }
    17 changes: 17 additions & 0 deletions SampleTests.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    using System.Net;
    using System.Net.Http;
    using Xunit;

    namespace DotUpgrade.Test
    {
    public class SampleTests
    {
    [Fact]
    public void Should_Return_Indicated_Code()
    {
    var httpClient = new HttpClient(new AlwaysReturns(HttpStatusCode.Conflict));
    var response = httpClient.GetAsync("http://www.google.com").Result;
    Assert.Equal(HttpStatusCode.Conflict, response.StatusCode);
    }
    }
    }