feat(inventory): BeginAsync loads viewer with canonical graph

Includes Cards/Sleeves/Emblems/LeaderSkins/Degrees/MyPageBackgrounds/Items
under AsSplitQuery, plus caller-supplied extras via InventoryLoadConfig.
Opens a DB transaction and returns an InventoryTransaction shell. All
mutation methods throw NotImplementedException until subsequent tasks
land them.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-05-31 15:46:20 -04:00
parent b181257aaa
commit 02e86cf16c
4 changed files with 187 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
using Microsoft.Extensions.DependencyInjection;
using SVSim.Database.Services.Inventory;
using SVSim.UnitTests.Infrastructure;
namespace SVSim.UnitTests.Services.Inventory;
public class InventoryServiceBeginTests
{
[Test]
public async Task BeginAsync_loads_viewer_with_canonical_graph()
{
using var factory = new SVSimTestFactory();
long viewerId = await factory.SeedViewerAsync();
using var scope = factory.Services.CreateScope();
var inv = scope.ServiceProvider.GetRequiredService<IInventoryService>();
await using var tx = await inv.BeginAsync(viewerId);
Assert.That(tx.Viewer, Is.Not.Null);
Assert.That(tx.Viewer.Id, Is.EqualTo(viewerId));
Assert.That(tx.Viewer.Cards, Is.Not.Null, "Cards collection must be loaded");
Assert.That(tx.Viewer.Sleeves, Is.Not.Null, "Sleeves collection must be loaded");
Assert.That(tx.Viewer.Items, Is.Not.Null, "Items collection must be loaded");
}
[Test]
public async Task BeginAsync_throws_when_viewer_missing()
{
using var factory = new SVSimTestFactory();
using var scope = factory.Services.CreateScope();
var inv = scope.ServiceProvider.GetRequiredService<IInventoryService>();
Assert.ThrowsAsync<InventoryViewerNotFoundException>(
async () => { await inv.BeginAsync(viewerId: 9999); });
}
[Test]
public async Task BeginAsync_applies_extra_includes_via_configure()
{
using var factory = new SVSimTestFactory();
long viewerId = await factory.SeedViewerAsync();
using var scope = factory.Services.CreateScope();
var inv = scope.ServiceProvider.GetRequiredService<IInventoryService>();
await using var tx = await inv.BeginAsync(viewerId, configure:
cfg => cfg.WithInclude(v => v.MissionData));
Assert.That(tx.Viewer.MissionData, Is.Not.Null);
}
}