public async void Invoke_ServiceReturnsUnsuccessfulStatusCode_ThrowsException( [Frozen] DummyContext context, [Frozen] HttpResponseMessage responseMessage, [Frozen] FakeHttpMessageHandler fakeHttpMessageHandler, [Frozen] HttpClient fakeHttpClient, [Frozen] IHttpClientFactory clientFactory, ShortUrlHandler sut) { responseMessage.StatusCode = HttpStatusCode.InternalServerError; context.Request.Path = new PathString("/2"); clientFactory.CreateClient("urlshorteningservice").Returns(fakeHttpClient); await Assert.ThrowsAsync <HttpRequestException>(async() => await sut.Invoke(context)); }
public async void Invoke_ServiceReturnsSuccessfulStatusCodeWithOriginalUrl_RedirectsToOriginalUrl( [Frozen] DummyContext context, [Frozen] HttpResponseMessage responseMessage, [Frozen] FakeHttpMessageHandler fakeHttpMessageHandler, [Frozen] HttpClient fakeHttpClient, [Frozen] IHttpClientFactory clientFactory, string url, ShortUrlHandler sut) { responseMessage.StatusCode = HttpStatusCode.OK; responseMessage.Content = new StringContent(url); context.Request.Path = new PathString("/2"); clientFactory.CreateClient("urlshorteningservice").Returns(fakeHttpClient); await sut.Invoke(context); context.Response.Received().Redirect(url); }