using JSMR.Infrastructure.Data; using Microsoft.EntityFrameworkCore; using Org.BouncyCastle.Asn1.Pkcs; namespace JSMR.Tests.Fixtures; public class CircleSearchProviderFixture : MariaDbFixture { protected override async Task OnInitializedAsync(AppDbContext context) { await SeedAsync(context); } private static async Task SeedAsync(AppDbContext context) { // Make seeding idempotent (quick existence check) if (await context.Circles.AnyAsync()) return; context.Circles.AddRange( new() { CircleId = 1, Name = "Good Dreams", MakerId = "RG00001" }, new() { CircleId = 2, Name = "Sweet Dreams", Favorite = true, MakerId = "RG00002" }, new() { CircleId = 3, Name = "Nightmare Fuel", Blacklisted = true, MakerId = "RG00003" }, new() { CircleId = 4, Name = "Garbage Studio", Spam = true, MakerId = "RG00004" } ); await context.SaveChangesAsync(); } } public sealed class CircleSearchProviderFixture2(MariaDbContainerFixture container) : IAsyncLifetime { public AppDbContext? DbContext { get; private set; } public async ValueTask InitializeAsync() { //DbContext = await MariaTestDb.CreateIsolatedAsync( // container.RootConnectionString, // seed: SeedAsync); var newDb = $"t_{DateTime.UtcNow:yyyyMMddHHmmss}_{Guid.NewGuid():N}"; DbContext = await MariaDbClone.CloneFromTemplateAsync( container.RootConnectionString, container.TemplateDbName, newDbName: newDb, seed: SeedAsync); } private static async Task SeedAsync(AppDbContext context) { // Make seeding idempotent (quick existence check) if (await context.Circles.AnyAsync()) return; context.Circles.AddRange( new() { CircleId = 1, Name = "Good Dreams", MakerId = "RG00001" }, new() { CircleId = 2, Name = "Sweet Dreams", Favorite = true, MakerId = "RG00002" }, new() { CircleId = 3, Name = "Nightmare Fuel", Blacklisted = true, MakerId = "RG00003" }, new() { CircleId = 4, Name = "Garbage Studio", Spam = true, MakerId = "RG00004" } ); await context.SaveChangesAsync(); } public async ValueTask DisposeAsync() { if (DbContext is not null) { await DbContext.DisposeAsync(); } } }