Seeding reorg

This commit is contained in:
gamer147
2026-05-24 21:13:15 -04:00
parent 34bcc579a5
commit c14408ba06
73 changed files with 4611 additions and 369716 deletions

View File

@@ -58,6 +58,12 @@ internal sealed class SVSimTestFactory : WebApplicationFactory<Program>
db.Database.EnsureCreated();
db.EnsureSeedDataAsync().GetAwaiter().GetResult();
// Reference data is no longer HasData-seeded; load the CSVs via the same importer
// production uses so tests exercise the same code path. CardCosmeticRewards skipped —
// FK to Cards would reject every row against the minimal 3-card test seed below.
var dataDir = Path.Combine(AppContext.BaseDirectory, "Data");
new ReferenceDataImporter().ImportAllAsync(db, dataDir).GetAwaiter().GetResult();
// Seed a minimal card set so card-pool tests can resolve a non-empty pool without
// requiring the full CardImporter tool or a cards.json file. The set is marked
// IsInRotation so both standard-pack (by setId) and special-pack (rotation scan)

View File

@@ -30,34 +30,6 @@ internal class SqliteFriendlyModelCustomizer : ModelCustomizer
shortUdidProperty.ValueGenerated = ValueGenerated.Never;
AssignClientSideKeyGenerators(modelBuilder.Model);
StripCardCosmeticRewardSeed(modelBuilder.Model);
}
/// <summary>
/// CardCosmeticReward rows have an FK to Cards.Id, and the production model HasData-seeds
/// 1068 rows from card_cosmetic_rewards.csv (chunk A.2). In production those rows have
/// matching cards inserted by the CardImporter before runtime. The unit-test factory uses
/// SQLite + EnsureCreated + a minimal 3-card seed — most of the cosmetic-reward rows have
/// no matching Cards row, and EnsureCreated's FK-deferred batch insert throws SqliteException
/// "FOREIGN KEY constraint failed" at host construction time. Strip the seed in tests; the
/// test fixture inserts CardCosmeticReward rows ad-hoc when a specific scenario needs them.
///
/// HasData seed is stored in the internal EntityType._data field (no public API). Clear it
/// via reflection. The clear runs after base.Customize so the HasData call inside Seed()
/// has populated the list before we wipe it.
/// </summary>
private static void StripCardCosmeticRewardSeed(IMutableModel model)
{
var entityType = model.FindEntityType(typeof(CardCosmeticReward));
if (entityType is null) return;
// EntityType._data is a List<IDictionary<string, object>>? — null when empty.
var dataField = entityType.GetType().GetField(
"_data",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (dataField is null) return;
var list = dataField.GetValue(entityType) as System.Collections.IList;
list?.Clear();
}
/// <summary>