tests: add test for unit of work

This commit is contained in:
Stevan Freeborn
2024-08-23 08:32:34 -05:00
parent 886eb2f855
commit 3739164960
14 changed files with 428 additions and 36 deletions
@@ -0,0 +1,33 @@
namespace SanctionsSearch.Worker.Tests.Integration;
public class DatabaseTest : IAsyncLifetime
{
private readonly AppDbContext _appDbContext;
protected readonly Mock<TimeProvider> _timeProviderMock = new();
protected readonly DbContext _context;
protected readonly ILoggerFactory _loggerFactory = LoggerFactory.Create(builder => builder.ClearProviders());
public DatabaseTest()
{
var options = new DbOptions { DatabaseName = $"{Guid.NewGuid()}.db" };
var context = new AppDbContext(options, _timeProviderMock.Object);
_appDbContext = context;
_context = context;
}
public virtual async Task InitializeAsync()
{
await _context.Database.MigrateAsync();
}
public virtual async Task DisposeAsync()
{
await _appDbContext.DisposeAsync();
SqliteConnection.ClearAllPools();
File.Delete(_appDbContext.DatabasePath);
}
}