Eug*_*ukh 5 c# asp.net-mvc integration-testing asp.net-core
我尝试运行集成测试并收到此错误
System.InvalidOperationException:入口点在未构建 IHost 的情况下退出。在 Microsoft.Extensions.Hosting.HostFactoryResolver.HostingListener.CreateHost() 在 Microsoft.Extensions.Hosting.HostFactoryResolver.<>c__DisplayClass10_0.b__0(String[] args) 在 Microsoft.AspNetCore.Mvc.Testing.DeferredHostBuilder.Build() 在 Microsoft .AspNetCore.Mvc.Testing.WebApplicationFactory
1.CreateHost(IHostBuilder builder) at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory1.ConfigureHostBuilder(IHostBuilder hostBuilder) 在 Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory1.EnsureServer() at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory1.CreateDefaultClient(DelegatingHandler[] 处理程序) 在 Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory1.CreateDefaultClient(Uri baseAddress, DelegatingHandler[] handlers) at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory1.CreateClient(WebApplicationFactoryClientOptions options) )位于 C:\Users\nemes\Documents\GitHub\ptco.app\System\Ptco.System.IntegrationTests\Infrastruct\IntegrationTestsWebFactory.cs 中的 Ptco.System.IntegrationTests.Infrastruct.IntegrationTestsWebFactory.CreteManagedClient():第 249 行
第 249 行是
private HttpClient CreteManagedClient() =>
CreateClient(new WebApplicationFactoryClientOptions
{
BaseAddress = new Uri(_configuration.GetValue<string>("IntegrationServerBaseUri"))
});
Run Code Online (Sandbox Code Playgroud)
就是这样称呼的
public IntegrationTestsWebFactory()
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
{
_configurationPath = Path.Join(AppDomain.CurrentDomain.BaseDirectory, "appsettings.json");
_configuration = BuildConfiguration();
ManagedHttpClient = CreteManagedClient();
}
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个错误?
这发生在我身上,因为我将 serilog 与CreateBootstrapLogger().
这是详细讨论https://github.com/serilog/serilog-aspnetcore/issues/289
对我来说,它与CreateLogger. 检查是否确实需要 CreateBootstrapLogger 此处https://nblumhardt.com/2020/10/bootstrap-logger/#why-cant-we-just-do-both