public async Task ManualInjection_MockAndVerify() { // Given var requestTrackerOne = m_TeePeeBuilderOne.ForRequest("https://first.api/pathone/resourceone", HttpMethod.Put) .ContainingQueryParam("filter", "other") .WithBody(new { Caller = "ThisCaller" }) .Responds() .WithStatus(HttpStatusCode.Created) .TrackRequest(); var requestTrackerTwo = m_TeePeeBuilderTwo.ForRequest("https://second.api/pathtwo/resourcetwo", HttpMethod.Put) .ContainingQueryParam("filter", "other") .WithBody(new { Caller = "ThisCaller" }) .Responds() .WithStatus(HttpStatusCode.Created) .TrackRequest(); var controller = new HttpClientFactoryMultipleNamedUsageController(new[] { m_TeePeeBuilderOne.Build().Manual("https://first.api"), m_TeePeeBuilderTwo.Build().Manual("https://second.api") } .ToHttpClientFactory()); // 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://first.api/pathone/resourceone", HttpMethod.Get) .ContainingQueryParam("filter", "those") .Responds() .WithStatus(HttpStatusCode.OK) .WithBody(new { Things = new[] { new { Value = 10 } } }); m_TeePeeBuilderTwo.ForRequest("https://second.api/pathtwo/resourcetwo", HttpMethod.Get) .ContainingQueryParam("filter", "those") .Responds() .WithStatus(HttpStatusCode.OK) .WithBody(new { Things = new[] { new { Value = 30 } } }); var controller = new HttpClientFactoryMultipleNamedUsageController(new[] { m_TeePeeBuilderOne.Build().Manual("https://first.api"), m_TeePeeBuilderTwo.Build().Manual("https://second.api") } .ToHttpClientFactory()); // 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); }