feat(packs): PackDrawTable aggregate + IPackDrawTableRepository

Aggregate (Config + SlotRates + CardWeights) and a single-pack getter
loaded as one unit per /pack/open. PackOpenService consumes the
aggregate; tests use the production seed (fixture overlay) to validate
shape.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-05-30 21:53:33 -04:00
parent f7407fe382
commit 3c36124fa7
5 changed files with 95 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using SVSim.Bootstrap.Importers;
using SVSim.Database;
using SVSim.Database.Repositories.PackDrawTables;
using SVSim.UnitTests.Infrastructure;
namespace SVSim.UnitTests.Repositories;
public class PackDrawTableRepositoryTests
{
private static string SeedDir => Path.Combine(AppContext.BaseDirectory, "Data", "seeds");
[Test]
public async Task GetAsync_returns_null_when_pack_unseeded()
{
using var factory = new SVSimTestFactory();
using var scope = factory.Services.CreateScope();
var repo = scope.ServiceProvider.GetRequiredService<IPackDrawTableRepository>();
var table = await repo.GetAsync(123456);
Assert.That(table, Is.Null);
}
[Test]
public async Task GetAsync_returns_config_slot_rates_and_card_weights_for_seeded_pack()
{
using var factory = new SVSimTestFactory();
using var scope = factory.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
var repo = scope.ServiceProvider.GetRequiredService<IPackDrawTableRepository>();
await new PackDrawTableImporter().ImportAsync(db, SeedDir);
var table = await repo.GetAsync(10000);
Assert.That(table, Is.Not.Null);
Assert.That(table!.Config.AnimationRatePct, Is.EqualTo(8.0));
Assert.That(table.SlotRates.Count, Is.EqualTo(7));
Assert.That(table.CardWeights.Count, Is.EqualTo(3));
Assert.That(table.CardWeights.All(w => w.PackId == 10000), Is.True);
}
}