Refactor EntryService to allow shared DisplayId for transfers; update related tests and migration files

This commit is contained in:
2026-04-03 12:00:53 +02:00
parent 387c18e834
commit 69181e66b0
8 changed files with 365 additions and 14 deletions

View File

@@ -13,11 +13,12 @@ public class TransferServiceTests : IDisposable
private readonly FinanceDbContext _db;
private readonly EntryService _entryService;
private readonly BalanceQueryService _balanceQueryService;
private readonly string _connectionString = $"Data Source=duempelkas-transfer-tests-{Guid.NewGuid():N};Mode=Memory;Cache=Shared";
public TransferServiceTests()
{
var options = new DbContextOptionsBuilder<FinanceDbContext>()
.UseSqlite("Data Source=duempelkas-transfer-tests;Mode=Memory;Cache=Shared")
.UseSqlite(_connectionString)
.Options;
_db = new FinanceDbContext(options);
@@ -52,7 +53,8 @@ public class TransferServiceTests : IDisposable
var targetEntry = entries.Single(e => e.AccountId == accountB.Id);
targetEntry.Type.Should().Be(EntryType.Income);
targetEntry.Amount.Should().Be(100.00m);
targetEntry.DisplayId.Should().Be("2026-002");
targetEntry.DisplayId.Should().Be("2026-001");
targetEntry.DisplayId.Should().Be(sourceEntry.DisplayId);
var links = await _db.TransferLinks.ToListAsync();
links.Should().HaveCount(1);
@@ -105,6 +107,29 @@ public class TransferServiceTests : IDisposable
await act.Should().ThrowAsync<InvalidOperationException>();
}
[Fact]
public async Task UpdateTransfer_ChangeLinkedAccount_KeepsSharedDisplayId()
{
var source = new Account { Name = "Barkasse" };
var initialTarget = new Account { Name = "Girokonto" };
var newTarget = new Account { Name = "Sparkonto" };
_db.Accounts.AddRange(source, initialTarget, newTarget);
await _db.SaveChangesAsync();
await _entryService.CreateTransferAsync(source.Id, initialTarget.Id, new DateTime(2026, 3, 15), "Umbuchung", 500.00m);
var sourceEntry = await _db.Entries.SingleAsync(e => e.AccountId == source.Id);
await _entryService.UpdateTransferAsync(sourceEntry.Id, newTarget.Id, new DateTime(2026, 3, 16), "Umbuchung angepasst", 550.00m);
_db.ChangeTracker.Clear();
var updatedSourceEntry = await _db.Entries.SingleAsync(e => e.AccountId == source.Id);
var updatedTargetEntry = await _db.Entries.SingleAsync(e => e.AccountId == newTarget.Id);
updatedSourceEntry.DisplayId.Should().Be("2026-001");
updatedTargetEntry.DisplayId.Should().Be(updatedSourceEntry.DisplayId);
}
public void Dispose()
{
_db.Database.CloseConnection();