test(inventory): lock Unknown-source fallthrough behaviour

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 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-09 15:33:04 -04:00
parent 5334263793
commit 8de78ba7ed

View File

@@ -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<SVSim.Database.Services.Inventory.IInventoryService>();
// 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<SVSim.Database.SVSimDbContext>();
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"));
}
}