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.
42 lines
1.5 KiB
C#
42 lines
1.5 KiB
C#
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));
|
|
}
|
|
}
|