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().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(); }