public async Task DelegatingHandlerMultiTestWithDuplicate() { var handler = HttpMock.Mock() .For("/test1") .Accepts("request1") .Returns("response1") .For("/test2") .Accepts("request2") .Returns("response2") .For("/test2") .Accepts("request2") .Returns("response2") .BuildDelegatingHandler(() => new FakeDelegatingHandler()); var responses = await handler.Invoke(); int counter = 1; foreach (var response in responses) { response.StatusCode.Should().Be(HttpStatusCode.OK); var data = await response.GetContentAsStringAsync(); data.Should().Be($"response{counter}request{counter}"); counter++; } }
public async Task HttpClientAnyTest() { var client = HttpMock.Mock() .For() .AcceptsAny() .Returns("response") .BuildClient(); var response = await client.PostAsync(string.Empty, It.IsAny <HttpContent>()); response.StatusCode.Should().Be(HttpStatusCode.OK); var data = await response.GetContentAsStringAsync(); data.Should().Be("response"); }
public async Task DelegatingHandlerSingleTest() { var handler = HttpMock.Mock() .For() .Accepts("request") .Returns("response") .BuildDelegatingHandler(() => new FakeDelegatingHandler()); var response = await handler.InvokeSingle(); response.StatusCode.Should().Be(HttpStatusCode.OK); var data = await response.GetContentAsStringAsync(); data.Should().Be("responserequest"); }
public async Task HttpClientFactoryTestWithEmptyName() { var factory = HttpMock.Mock() .For() .Accepts("request") .Returns("response") .BuildFactory(); using (var client = factory.CreateClient()) { var response = await client.PostAsync(string.Empty, It.IsAny <HttpContent>()); response.StatusCode.Should().Be(HttpStatusCode.OK); var data = await response.GetContentAsStringAsync(); data.Should().Be("response"); } }
public async Task HttpClientTypedModelTest() { var client = HttpMock.Mock() .For() .Accepts(new FakeInput { Id = "1" }) .Returns(new FakeOutput { Id = "1" }) .BuildClient(); var response = await client.PostAsync(string.Empty, It.IsAny <HttpContent>()); response.StatusCode.Should().Be(HttpStatusCode.OK); var data = await response.GetContentAsStringAsync(); var model = JsonConvert.DeserializeObject <FakeOutput>(data); model.Id.Should().Be("1"); }