我有一个简单的健康检查测试,如下所示:
public class HealthCheckEndpointTests : IClassFixture<ItemsApplicationFactory>
{
private readonly ItemsApplicationFactory _factory;
public HealthCheckEndpointTests(ItemsApplicationFactory factory)
{
_factory = factory;
}
public async Task HealthCheck_Test()
{
// Arrange
HttpClient httpClient = _factory.CreateClient();
// Act
string response = await httpClient.GetStringAsync("/health/live");
// Assert
Assert.Equal("Healthy", response);
}
}
Run Code Online (Sandbox Code Playgroud)
我的 ItemsApplicationFactory 如下所示:
public class ItemsApplicationFactory : WebApplicationFactory<Program>
{
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.ConfigureKestrel(options => options.AllowSynchronousIO = true);
builder.ConfigureServices(services =>
{
// remove db context options if exists
var dbContextDescriptor = services.SingleOrDefault(d => d.ServiceType == …Run Code Online (Sandbox Code Playgroud)