2026-03-03 07:36:09 -06:00
|
|
|
namespace FiscalOS.Infra.Tests.Integration;
|
|
|
|
|
|
|
|
|
|
public abstract class IntegrationTest : IAsyncLifetime
|
|
|
|
|
{
|
|
|
|
|
private bool _isDisposed;
|
|
|
|
|
private readonly FileSystem _fileSystem = new();
|
|
|
|
|
protected AppDbContext AppDbContext { get; }
|
|
|
|
|
|
|
|
|
|
protected IntegrationTest()
|
|
|
|
|
{
|
|
|
|
|
var options = Options.Create(new AppDbContextOptions()
|
|
|
|
|
{
|
|
|
|
|
DatabaseFilePath = $"{Guid.NewGuid()}.db",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AppDbContext = new(options, _fileSystem);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-05 13:58:00 -06:00
|
|
|
protected async Task<User> CreateTestUserAsync()
|
|
|
|
|
{
|
2026-03-06 07:14:57 -06:00
|
|
|
var user = UserBuilder.Create()
|
|
|
|
|
.WithInstitution(static ib =>
|
|
|
|
|
{
|
|
|
|
|
ib.WithMetadata();
|
2026-03-08 07:18:27 -05:00
|
|
|
ib.WithAccount(static ab =>
|
2026-03-06 07:14:57 -06:00
|
|
|
{
|
|
|
|
|
ab.WithMetadata();
|
2026-03-08 07:18:27 -05:00
|
|
|
ab.WithTransaction(static tb =>
|
|
|
|
|
{
|
|
|
|
|
tb.WithMetadata();
|
|
|
|
|
});
|
2026-03-06 07:14:57 -06:00
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.Build();
|
2026-03-05 13:58:00 -06:00
|
|
|
|
|
|
|
|
await AppDbContext.AddAsync(user, TestContext.Current.CancellationToken);
|
|
|
|
|
await AppDbContext.SaveChangesAsync(TestContext.Current.CancellationToken);
|
|
|
|
|
|
|
|
|
|
return user;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-03 07:36:09 -06:00
|
|
|
public async ValueTask InitializeAsync()
|
|
|
|
|
{
|
|
|
|
|
await AppDbContext.Database.MigrateAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async ValueTask DisposeAsync()
|
|
|
|
|
{
|
|
|
|
|
await DisposeAsync(true);
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual async Task DisposeAsync(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
if (_isDisposed)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (disposing)
|
|
|
|
|
{
|
|
|
|
|
await AppDbContext.DisposeAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_isDisposed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|