28 lines
957 B
C#
28 lines
957 B
C#
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Mvc.Testing;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using PageManager.Api.Data;
|
|
|
|
namespace PageManager.Api.Tests.Integration.Fixtures;
|
|
|
|
public class TestWebAppFactory(PostgresFixture postgres) : WebApplicationFactory<Program>
|
|
{
|
|
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
|
{
|
|
builder.UseEnvironment("Testing");
|
|
|
|
builder.ConfigureServices(services =>
|
|
{
|
|
var descriptor = services.SingleOrDefault(
|
|
d => d.ServiceType == typeof(DbContextOptions<AppDbContext>));
|
|
if (descriptor is not null)
|
|
services.Remove(descriptor);
|
|
|
|
services.AddDbContext<AppDbContext>(options =>
|
|
options.UseNpgsql(postgres.ConnectionString)
|
|
.UseSnakeCaseNamingConvention());
|
|
});
|
|
}
|
|
}
|