From 8de78ba7edb513ee9f81feeb85ca4dd65b2e1141 Mon Sep 17 00:00:00 2001 From: gamer147 Date: Tue, 9 Jun 2026 15:33:04 -0400 Subject: [PATCH] test(inventory): lock Unknown-source fallthrough behaviour MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds Commit_writes_history_row_with_Unknown_source_when_caller_omits_Source to InventoryHistoryTests — asserts that BeginAsync without a configure callback writes AcquireType=0 / Message="Unknown", per spec §10. Co-Authored-By: Claude Sonnet 4.6 --- .../Inventory/InventoryHistoryTests.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/SVSim.UnitTests/Services/Inventory/InventoryHistoryTests.cs b/SVSim.UnitTests/Services/Inventory/InventoryHistoryTests.cs index 4a86e70..3dbd39a 100644 --- a/SVSim.UnitTests/Services/Inventory/InventoryHistoryTests.cs +++ b/SVSim.UnitTests/Services/Inventory/InventoryHistoryTests.cs @@ -305,4 +305,28 @@ public class InventoryHistoryTests Assert.That(primaryCount, Is.EqualTo(300), "primary viewer pruned to cap"); Assert.That(otherCount, Is.EqualTo(50), "other viewer untouched by primary's prune"); } + + [Test] + public async Task Commit_writes_history_row_with_Unknown_source_when_caller_omits_Source() + { + using var factory = new SVSim.UnitTests.Infrastructure.SVSimTestFactory(); + long viewerId = await factory.SeedViewerAsync(); + using var scope = factory.Services.CreateScope(); + var inv = scope.ServiceProvider.GetRequiredService(); + + // No configure callback — Source defaults to Unknown. + await using (var tx = await inv.BeginAsync(viewerId)) + { + await tx.GrantAsync(SVSim.Database.Enums.UserGoodsType.Rupy, 0, 10); + await tx.CommitAsync(); + } + + using var verifyScope = factory.Services.CreateScope(); + var ctx = verifyScope.ServiceProvider.GetRequiredService(); + var rows = await ctx.ViewerAcquireHistory.AsNoTracking() + .Where(h => h.ViewerId == viewerId).ToListAsync(); + Assert.That(rows, Has.Count.EqualTo(1)); + Assert.That(rows[0].AcquireType, Is.EqualTo((int)GrantSource.Unknown)); + Assert.That(rows[0].Message, Is.EqualTo("Unknown")); + } }