Шибалкин Александр
457579c88d
All checks were successful
Unit tests / test (push) Successful in 1m0s
33 lines
1.0 KiB
C#
33 lines
1.0 KiB
C#
|
|
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<PersistencePostgresContext>()
|
|
.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<PersistencePostgresContext>()
|
|
.UseNpgsql(dbContainer.GetConnectionString()).Options);
|
|
|
|
await forumDbContext.Database.MigrateAsync();
|
|
}
|
|
|
|
public async Task DisposeAsync() => await dbContainer.DisposeAsync();
|
|
}
|
|
|