我正在将现有的 ASP.Net 5 Web 应用程序迁移到 ASP.Net 6,并遇到了通过集成测试的最后障碍。
\n我自定义 WebApplicationFactory 并抛出异常:Changing the host configuration using WebApplicationBuilder.WebHost is not supported. Use WebApplication.CreateBuilder(WebApplicationOptions) instead.
public class CustomWebApplicationFactory<TStartup> : WebApplicationFactory<TStartup> where TStartup : class\n {\n protected override void ConfigureWebHost(IWebHostBuilder builder)\n {\n Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "IntegrationTests");\n builder.ConfigureServices(services => {\n // Create a new service provider.\n var serviceProvider = new ServiceCollection()\n .AddEntityFrameworkInMemoryDatabase().AddLogging()\n .BuildServiceProvider();\n\n // Add a database context (AppDbContext) using an in-memory database for testing.\n services.AddDbContextPool<AppDbContext>(options =>\n {\n options.UseInMemoryDatabase("InMemoryAppDb");\n options.UseInternalServiceProvider(serviceProvider);\n options.EnableSensitiveDataLogging();\n options.EnableDetailedErrors();\n options.LogTo(Console.WriteLine);\n });\n\n services.AddDbContextPool<AppIdentityDbContext>(options …Run Code Online (Sandbox Code Playgroud)