refactor(bootstrap): migrate practice opponents to seed file
Move /practice/info handling out of GlobalsImporter into a dedicated PracticeOpponentImporter that reads a normalized JSON seed file generated by data_dumps/extract/extract-practice-opponents.ps1.
This commit is contained in:
41
SVSim.UnitTests/Importers/PracticeOpponentImporterTests.cs
Normal file
41
SVSim.UnitTests/Importers/PracticeOpponentImporterTests.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SVSim.Bootstrap.Importers;
|
||||
using SVSim.Database;
|
||||
using SVSim.UnitTests.Infrastructure;
|
||||
|
||||
namespace SVSim.UnitTests.Importers;
|
||||
|
||||
public class PracticeOpponentImporterTests
|
||||
{
|
||||
private static string SeedDir => Path.Combine(AppContext.BaseDirectory, "Data", "seeds");
|
||||
|
||||
[Test]
|
||||
public async Task Imports_opponents_from_seed_file()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
using var scope = factory.Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
|
||||
await new PracticeOpponentImporter().ImportAsync(db, SeedDir);
|
||||
|
||||
var opponents = await db.PracticeOpponents.OrderBy(p => p.Id).ToListAsync();
|
||||
Assert.That(opponents.Count, Is.GreaterThan(0), "seed file must contain opponents");
|
||||
Assert.That(opponents.All(o => o.ClassId >= 0), 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 PracticeOpponentImporter().ImportAsync(db, SeedDir);
|
||||
int before = await db.PracticeOpponents.CountAsync();
|
||||
await new PracticeOpponentImporter().ImportAsync(db, SeedDir);
|
||||
int after = await db.PracticeOpponents.CountAsync();
|
||||
|
||||
Assert.That(after, Is.EqualTo(before));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user