I'm trying to add some integration tests to my existing .net 6.0 project, but keep running into issues
Right now if I run the test, it hits the line await host.RunAsync(CancellationToken.None); in Program.cs and then just hangs forever and seemingly does nothing
Have I misunderstoof something? If not how can I troubleshoot this?
Program.cs
public /*static*/ class Program
{
public static async Task Main(string[] args)
{
var host = BuildWebHost(args);
await host.InitialiseAsync(CancellationToken.None);
await host.SeedAsync(CancellationToken.None);
await host.RunAsync(CancellationToken.None); // hangs here
}
}
Tests.cs
[Fact]
public void Test1Async()
{
using (var application = new WebApplicationFactory<Program>()
.WithWebHostBuilder(builder =>
{
builder.ConfigureServices(services =>
{
// set up servises
});
}))
{
var c = application.CreateClient(); // hangs here
}
}
It does eventually time out and give me this error
Message: System.InvalidOperationException : Timed out waiting for the entry point to build the IHost after 00:05:00. This timeout can be modified using the 'DOTNET_HOST_FACTORY_RESOLVER_DEFAULT_TIMEOUT_IN_SECONDS' environment variable.
Stack Trace: HostingListener.CreateHost() <>c__DisplayClass10_0.b__0(String[] args) DeferredHostBuilder.Build() WebApplicationFactory
1.CreateHost(IHostBuilder builder) DelegatedWebApplicationFactory.CreateHost(IHostBuilder builder) WebApplicationFactory1.ConfigureHostBuilder(IHostBuilder hostBuilder) WebApplicationFactory1.EnsureServer() WebApplicationFactory1.CreateDefaultClient(DelegatingHandler[] handlers) WebApplicationFactory1.CreateDefaultClient(Uri baseAddress, DelegatingHandler[] handlers) WebApplicationFactory1.CreateClient(WebApplicationFactoryClientOptions options) WebApplicationFactory`1.CreateClient() UnitTest1.Test1Async() line 35