При обновлении проекта интеграционного тестирования класс WebApplicationFactory вызывает ошибки . Я перенес свой файл запуска в файл Program.cs.
Это мой код для класса WebApplicationFactory
Код: Выделить всё
public class ServiceWorkerFactory
: WebApplicationFactory where TProgram : class
{
protected override IHostBuilder CreateHostBuilder()
{
return Host.CreateDefaultBuilder().ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup();
}
)
.ConfigureAppConfiguration(
(
hostingContext,
config
) =>
{
config.AddInMemoryCollection(new[]
{
new KeyValuePair(
"ConnectionStrings:test",
DatabaseTestSetup.test
),
});
});
}
protected override void ConfigureWebHost
(
IWebHostBuilder builder
)
{
base.ConfigureWebHost(builder);
builder.ConfigureServices((context, services) =>
{
var sp = services.BuildServiceProvider();
//Need to pass the tenant id dynamically probably from appconfig
//Get the integration test application settings
var integrationTestAppSettings = context.Configuration.GetSection("IntegrationTest").Get();
if (integrationTestAppSettings != null)
{
services.AddSingleton(integrationTestAppSettings);
}
else
{
throw new System.Exception("Integration testing appsetting configuration not found !!");
}
var tc = new TaskContext() { TenantId = integrationTestAppSettings.TenantId };
builder.ConfigureTestServices(services =>
{
services.AddHangfire(options => options.UseMemoryStorage());
// Mock external dependency
services.SwapService(Substitute.For());
});
}
}
Пожалуйста, сообщите, если я сделал что-то не так.
Подробнее здесь: https://stackoverflow.com/questions/788 ... to-net-8-0