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(); 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(); 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)); } }