tests: add test for unit of work
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user