public static async Task SendAsync_Throws_If_Registration_Missing_Post() { // Arrange var options = new HttpClientInterceptorOptions() { ThrowOnMissingRegistration = true, }; var mock = new Mock <HttpMessageHandler>(); using (var handler = options.CreateHttpMessageHandler()) { using (var target = new HttpClient(handler)) { using (var content = new StringContent(string.Empty)) { // Act var exception = await Assert.ThrowsAsync <InvalidOperationException>(() => target.PostAsync("https://google.com/", content)); // Assert exception.Message.ShouldBe("No HTTP response is configured for POST https://google.com/."); } } } }
public static async Task SendAsync_Throws_If_Registration_Missing_Post() { // Arrange var options = new HttpClientInterceptorOptions() .ThrowsOnMissingRegistration(); var mock = new Mock <HttpMessageHandler>(); using var handler = options.CreateHttpMessageHandler(); using var target = new HttpClient(handler); using var content = new StringContent(string.Empty); // Act var exception = await Assert.ThrowsAsync <HttpRequestNotInterceptedException>( () => target.PostAsync("https://google.com/", content)); // Assert exception.Message.ShouldBe("No HTTP response is configured for POST https://google.com/."); exception.Request.ShouldNotBeNull(); exception.Request.RequestUri.ShouldBe(new Uri("https://google.com/")); }