36 lines
1015 B
C#
36 lines
1015 B
C#
using Microsoft.EntityFrameworkCore;
|
|
using PageManager.Api.Data;
|
|
using Testcontainers.PostgreSql;
|
|
|
|
namespace PageManager.Api.Tests.Integration.Fixtures;
|
|
|
|
public class PostgresFixture : IAsyncLifetime
|
|
{
|
|
private readonly PostgreSqlContainer _container = new PostgreSqlBuilder()
|
|
.WithImage("postgres:17-alpine")
|
|
.Build();
|
|
|
|
public string ConnectionString => _container.GetConnectionString();
|
|
|
|
public async Task InitializeAsync()
|
|
{
|
|
await _container.StartAsync();
|
|
|
|
var options = new DbContextOptionsBuilder<AppDbContext>()
|
|
.UseNpgsql(ConnectionString)
|
|
.UseSnakeCaseNamingConvention()
|
|
.Options;
|
|
|
|
await using var db = new AppDbContext(options);
|
|
await db.Database.MigrateAsync();
|
|
}
|
|
|
|
public async Task DisposeAsync()
|
|
{
|
|
await _container.DisposeAsync();
|
|
}
|
|
}
|
|
|
|
[CollectionDefinition("Postgres")]
|
|
public class PostgresCollection : ICollectionFixture<PostgresFixture> { }
|