public async Task SendAsync_ExistsInCassette_DoesNotCallInnerHttpHandler() { var cassette = new Cassette(); var record = new CassetteRecord( new CassetteRecordRequest( HttpMethod.Get.Method, new Uri("http://*****:*****@"{""a"": 1, ""b"": 2}")); cassette.Add(record); var mockHttpHandler = new MockHttpRequestHandler(); var tryReplayMessageHandler = new PublicTryReplayHttpMessageHandler(cassette, mockHttpHandler); var request = new HttpRequestMessage { Method = HttpMethod.Get, RequestUri = new Uri("http://localhost:8080/test"), }; var response = await tryReplayMessageHandler.SendAsync(request); Assert.That(mockHttpHandler.Invoked, Is.False); Assert.That(response.Version, Is.EqualTo(record.Response.Version)); Assert.That(response.StatusCode, Is.EqualTo((HttpStatusCode)record.Response.StatusCode)); Assert.That(response.ReasonPhrase, Is.EqualTo(record.Response.StatusMessage)); Assert.That(response.RequestMessage, Is.Not.Null); Assert.That(response.Headers.GetValues("Server"), Is.EqualTo(new[] { record.Response.Headers["Server"] })); }
public async Task SendAsync_DoesNotExistInCassette_CallsInnerHttpHandler() { var cassette = new Cassette(); var mockHttpHandler = new MockHttpRequestHandler(); var tryReplayMessageHandler = new PublicTryReplayHttpMessageHandler(cassette, mockHttpHandler); var request = new HttpRequestMessage { Method = HttpMethod.Get, RequestUri = new Uri("http://localhost:8080/test"), }; var response = await tryReplayMessageHandler.SendAsync(request); Assert.That(mockHttpHandler.Invoked, Is.True); Assert.That(response.Version, Is.EqualTo(new Version(1, 1))); Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); Assert.That(response.ReasonPhrase, Is.EqualTo("OK")); Assert.That(response.RequestMessage, Is.Not.Null); Assert.That(response.Headers.GetValues("Server"), Is.EqualTo(new[] { "Test-Server" })); }