feat(packs): PackDrawTableImporter with fixture tests
Idempotent upsert keyed on pack_id; slot rates and card weights are wiped per pack and reinserted. String slot/tier in the seed translate to enum at import time. Tests: - Imports_config_slot_rates_and_card_weights - Is_idempotent_on_rerun Fixtures live under SVSim.Bootstrap/Data/test-fixtures/seeds/ and overlay the production seeds via the existing csproj rule (test-fixture file beats production file at same Link path). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
48
SVSim.UnitTests/Importers/PackDrawTableImporterTests.cs
Normal file
48
SVSim.UnitTests/Importers/PackDrawTableImporterTests.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SVSim.Bootstrap.Importers;
|
||||
using SVSim.Database;
|
||||
using SVSim.Database.Enums;
|
||||
using SVSim.UnitTests.Infrastructure;
|
||||
|
||||
namespace SVSim.UnitTests.Importers;
|
||||
|
||||
public class PackDrawTableImporterTests
|
||||
{
|
||||
private static string SeedDir => Path.Combine(AppContext.BaseDirectory, "Data", "seeds");
|
||||
|
||||
[Test]
|
||||
public async Task Imports_config_slot_rates_and_card_weights()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
using var scope = factory.Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
|
||||
await new PackDrawTableImporter().ImportAsync(db, SeedDir);
|
||||
|
||||
Assert.That(await db.PackDrawConfigs.CountAsync(), Is.EqualTo(2));
|
||||
Assert.That(await db.PackDrawSlotRates.CountAsync(), Is.EqualTo(8));
|
||||
Assert.That(await db.PackDrawCardWeights.CountAsync(), Is.EqualTo(5));
|
||||
|
||||
var bonus = await db.PackDrawCardWeights
|
||||
.Where(w => w.PackId == 98001 && w.Slot == DrawSlot.Bonus)
|
||||
.ToListAsync();
|
||||
Assert.That(bonus.Count, Is.EqualTo(2));
|
||||
Assert.That(bonus.All(w => w.RatePct == null && w.IsLeader && w.Tier == DrawTier.Special), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Is_idempotent_on_rerun()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
using var scope = factory.Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
|
||||
await new PackDrawTableImporter().ImportAsync(db, SeedDir);
|
||||
int before = await db.PackDrawCardWeights.CountAsync();
|
||||
await new PackDrawTableImporter().ImportAsync(db, SeedDir);
|
||||
int after = await db.PackDrawCardWeights.CountAsync();
|
||||
|
||||
Assert.That(after, Is.EqualTo(before));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user