Closed karpikpl closed 1 year ago
Published NuGet package v2.1.2.
The fix worked. I was able to use Flurl and have a valid unit test:
public async Task HealthCheckEndpoint_Should_BeExposed_And_Return503_When_CheckFails()
{
// Arrange
// fake & record all http calls in the test subject
using (var httpTest = new HttpTest()) {
httpTest.RespondWith("server error", 500);
using var test = CreateApiTester<SampleApp.Startup>();
test.Http().TestServer.PreserveExecutionContext = true;
// Act
var result = await test.Http()
.RunAsync(HttpMethod.Get, "/health");
// Assert
System.Text.Json.JsonElement response = result.GetValue<dynamic>();
var status = response.GetProperty("healthReport").GetProperty("status").GetString();
status.Should().Be("Unhealthy", because: "the health check was mocked to fail");
httpTest.ShouldHaveMadeACall();
httpTest.ShouldHaveCalled("https://www.mock-url.com/*")
.WithVerb(HttpMethod.Head);
}
}
Flurl can be used with
TestServer
- see this stack overflow answer - https://stackoverflow.com/questions/50155702/can-i-use-flurlclient-with-asp-net-core-testserver but UnitTestEx does not exposeTestServer
via an API, would it be possible to allow it?