using DD.Persistence.Database; using DD.Persistence.Database.Model; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Caching.Memory; using Testcontainers.PostgreSql; using Xunit; namespace DD.Persistence.Repository.Test; public class RepositoryTestFixture : IAsyncLifetime { public readonly PostgreSqlContainer dbContainer = new PostgreSqlBuilder() .WithImage("timescale/timescaledb:latest-pg16") .WithHostname("localhost") .WithDatabase("persistence") .WithUsername("postgres") .WithPassword("postgres") //.WithPortBinding("5462") .Build(); public PersistencePostgresContext GetDbContext() => new(new DbContextOptionsBuilder() .UseNpgsql(dbContainer.GetConnectionString()).Options); public IMemoryCache GetMemoryCache() => new MemoryCache(new MemoryCacheOptions()); public virtual async Task InitializeAsync() { await dbContainer.StartAsync(); var forumDbContext = new PersistencePostgresContext(new DbContextOptionsBuilder() .UseNpgsql(dbContainer.GetConnectionString()).Options); await forumDbContext.Database.MigrateAsync(); } public async Task DisposeAsync() => await dbContainer.DisposeAsync(); }