generated from Avanade/avanade-template
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using Flurl with UnitTestEx #52
Labels
enhancement
New feature or request
Comments
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);
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Flurl can be used with
TestServer
- see this stack overflow answer - https://stackoverflow.com/questions/50155702/can-i-use-flurlclient-with-asp-net-core-testserverbut UnitTestEx does not expose
TestServer
via an API, would it be possible to allow it?The text was updated successfully, but these errors were encountered: