public async Task ManualInjection_MockAndVerify() { // Given var requestTrackerOne = m_TeePeeBuilderOne.ForRequest("https://some.api/path/resource", HttpMethod.Put) .ContainingQueryParam("filter", "other") .WithBody(new { Caller = "ThisCaller" }) .Responds() .WithStatus(HttpStatusCode.Created) .TrackRequest(); var requestTrackerTwo = m_TeePeeBuilderTwo.ForRequest("https://other.api/path/otherresource", HttpMethod.Put) .ContainingQueryParam("filter", "other") .WithBody(new { Caller = "ThisCaller" }) .Responds() .WithStatus(HttpStatusCode.Created) .TrackRequest(); var controller = new HttpClientFactoryMultipleTypedUsageController(new ExampleTypedHttpClient(m_TeePeeBuilderOne.Build().Manual("https://some.api").CreateClient()), new AnotherExampleTypedHttpClient(m_TeePeeBuilderTwo.Build().Manual("https://other.api").CreateClient())); // When var result = await controller.FireAndForget(); // Then Assert.NotNull(result); Assert.IsType <OkResult>(result); requestTrackerOne.WasCalled(1); requestTrackerTwo.WasCalled(1); }
public async Task ManualInjection_RecommendedPassiveMocking() { // Given m_TeePeeBuilderOne.ForRequest("https://some.api/path/resource", HttpMethod.Get) .ContainingQueryParam("filter", "those") .Responds() .WithStatus(HttpStatusCode.OK) .WithBody(new { Things = new[] { new { Value = 10 } } }); m_TeePeeBuilderTwo.ForRequest("https://other.api/path/otherresource", HttpMethod.Get) .ContainingQueryParam("filter", "those") .Responds() .WithStatus(HttpStatusCode.OK) .WithBody(new { Things = new[] { new { Value = 30 } } }); var controller = new HttpClientFactoryMultipleTypedUsageController(new ExampleTypedHttpClient(m_TeePeeBuilderOne.Build().Manual("https://some.api").CreateClient()), new AnotherExampleTypedHttpClient(m_TeePeeBuilderTwo.Build().Manual("https://other.api").CreateClient())); // When var result = await controller.FireAndAct(); // Then Assert.NotNull(result); var okResult = Assert.IsType <OkObjectResult>(result); var resultValue = Assert.IsType <int>(okResult.Value); Assert.Equal(40, resultValue); }