Files
SVSimServer/SVSim.UnitTests/Importers/LoadIndexImporterTests.cs
gamer147 87d0001569 refactor(bootstrap): add 7 load-index importers (excluding card lists)
Stage 9B of the bootstrap-seed-refactor: add per-domain importer classes
that consume the load-index seed split produced in Stage 9A.

New importers (each in its own file under SVSim.Bootstrap/Importers/):
- RotationConfigImporter: writes Rotation/Challenge/MyRotationSchedule
  GameConfig sections (atomic UpsertSection<T> pattern, copied private-static
  from GlobalsImporter so this importer stands alone post-9C).
- MyRotationImporter: settings + abilities (extractor pre-joins on rotation_id).
- AvatarAbilityImporter: per-leader_skin_id ability rows.
- ArenaSeasonImporter: singleton (Id=1) Take Two arena season.
- BattlePassImporter: per-level reward blobs.
- DailyLoginBonusImporter: per-bonus-id campaign blobs.
- PreReleaseInfoImporter: singleton (Id=1) pre-release window.

Seed DTOs under SVSim.Bootstrap/Models/Seed/ mirror the seed JSON via
[JsonPropertyName] snake_case. Raw-JSON columns (reward_data, format_info,
etc.) use JsonElement on the seed and JsonSerializer.Serialize in the
importer.

Tests: 7 new happy-path tests in LoadIndexImporterTests.cs (idempotency
covered by BattlePass spot-check). Full suite: 382/382 passing (375 + 7).

NOT modifying in this stage: GlobalsImporter.cs (Stage 9C strips the old
methods), Program.cs (Stage 9C wires up all 9 importers), SVSimTestFactory
(Stage 9C). Double-writing on bootstrap is expected and OK during 9B.
2026-05-26 15:29:57 -04:00

119 lines
4.8 KiB
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using SVSim.Bootstrap.Importers;
using SVSim.Database;
using SVSim.UnitTests.Infrastructure;
namespace SVSim.UnitTests.Importers;
/// <summary>
/// Happy-path coverage for the 7 load-index importer classes introduced in Stage 9B
/// (RotationConfig, MyRotation, AvatarAbility, ArenaSeason, BattlePass, DailyLoginBonus,
/// PreReleaseInfo). Each test instantiates the importer in isolation and verifies it inserts
/// rows from the corresponding seed file under <c>Data/seeds/</c>. Idempotency is spot-checked
/// in one test (BattlePass) to avoid duplicating the canonical 4-test set per importer.
/// </summary>
public class LoadIndexImporterTests
{
private static string SeedDir => Path.Combine(AppContext.BaseDirectory, "Data", "seeds");
[Test]
public async Task RotationConfigImporter_writes_game_config_sections()
{
using var factory = new SVSimTestFactory();
using var scope = factory.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
await new RotationConfigImporter().ImportAsync(db, SeedDir);
var rows = await db.GameConfigs.ToListAsync();
Assert.That(rows.Any(r => r.SectionName == "Rotation"), Is.True,
"Rotation section must be written from rotation-config.json");
}
[Test]
public async Task MyRotationImporter_writes_settings_and_abilities()
{
using var factory = new SVSimTestFactory();
using var scope = factory.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
await new MyRotationImporter().ImportAsync(db, SeedDir);
Assert.That(await db.MyRotationSettings.CountAsync(), Is.GreaterThan(0),
"my-rotation-settings.json must produce setting rows");
Assert.That(await db.MyRotationAbilities.CountAsync(), Is.GreaterThan(0),
"my-rotation-abilities.json must produce ability rows");
}
[Test]
public async Task AvatarAbilityImporter_writes_abilities()
{
using var factory = new SVSimTestFactory();
using var scope = factory.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
await new AvatarAbilityImporter().ImportAsync(db, SeedDir);
Assert.That(await db.AvatarAbilities.CountAsync(), Is.GreaterThan(0),
"avatar-abilities.json must produce ability rows");
}
[Test]
public async Task ArenaSeasonImporter_writes_singleton()
{
using var factory = new SVSimTestFactory();
using var scope = factory.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
await new ArenaSeasonImporter().ImportAsync(db, SeedDir);
var row = await db.ArenaSeasons.FirstOrDefaultAsync(e => e.Id == 1);
Assert.That(row, Is.Not.Null, "ArenaSeason singleton id=1 must be written");
Assert.That(row!.FormatInfo, Is.Not.EqualTo("{}"), "format_info blob must be populated from seed");
}
[Test]
public async Task BattlePassImporter_writes_levels_and_is_idempotent()
{
using var factory = new SVSimTestFactory();
using var scope = factory.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
await new BattlePassImporter().ImportAsync(db, SeedDir);
int after1 = await db.BattlePassLevels.CountAsync();
await new BattlePassImporter().ImportAsync(db, SeedDir);
int after2 = await db.BattlePassLevels.CountAsync();
Assert.That(after1, Is.GreaterThan(0), "battle-pass-levels.json must produce rows");
Assert.That(after2, Is.EqualTo(after1), "rerun must be idempotent (no new rows)");
}
[Test]
public async Task DailyLoginBonusImporter_writes_bonus_rows()
{
using var factory = new SVSimTestFactory();
using var scope = factory.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
await new DailyLoginBonusImporter().ImportAsync(db, SeedDir);
Assert.That(await db.DailyLoginBonuses.CountAsync(), Is.GreaterThan(0),
"daily-login-bonus.json must produce rows");
}
[Test]
public async Task PreReleaseInfoImporter_writes_singleton()
{
using var factory = new SVSimTestFactory();
using var scope = factory.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
await new PreReleaseInfoImporter().ImportAsync(db, SeedDir);
var row = await db.PreReleaseInfos.FirstOrDefaultAsync(e => e.Id == 1);
Assert.That(row, Is.Not.Null, "PreReleaseInfo singleton id=1 must be written");
Assert.That(row!.PreReleaseId, Is.Not.Empty, "pre_release_id field must be populated");
}
}