Implement backup and restore functionality; add IBackupService and BackupService; refactor services to use DbContextFactory

This commit is contained in:
2026-04-03 10:53:53 +02:00
parent 0923c037eb
commit 387c18e834
15 changed files with 411 additions and 71 deletions

View File

@@ -17,15 +17,17 @@ public class BalanceCalculationTests : IDisposable
public BalanceCalculationTests()
{
var options = new DbContextOptionsBuilder<FinanceDbContext>()
.UseSqlite("Data Source=:memory:")
.UseSqlite("Data Source=duempelkas-balance-tests;Mode=Memory;Cache=Shared")
.Options;
_db = new FinanceDbContext(options);
_db.Database.OpenConnection();
_db.Database.EnsureCreated();
_balanceQueryService = new BalanceQueryService(_db);
_entryService = new EntryService(_db);
var dbFactory = new TestDbContextFactory(options);
_balanceQueryService = new BalanceQueryService(dbFactory);
_entryService = new EntryService(dbFactory);
}
[Fact]
@@ -106,4 +108,19 @@ public class BalanceCalculationTests : IDisposable
_db.Database.CloseConnection();
_db.Dispose();
}
private sealed class TestDbContextFactory : IDbContextFactory<FinanceDbContext>
{
private readonly DbContextOptions<FinanceDbContext> _options;
public TestDbContextFactory(DbContextOptions<FinanceDbContext> options)
{
_options = options;
}
public FinanceDbContext CreateDbContext() => new(_options);
public Task<FinanceDbContext> CreateDbContextAsync(CancellationToken cancellationToken = default)
=> Task.FromResult(new FinanceDbContext(_options));
}
}