using LCU.API.Internal.DocumentIngestorLib.Persistence; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; namespace LCU.API.Internal.DocumentIngestorLibTests; public class SqliteAppDbContextFactory : IDisposable { private readonly IList _connections = new List(); private readonly IList _contexts = new List(); public AppDbContext CreateContext() { var connection = new SqliteConnection("Filename=:memory:"); _connections.Add(connection); connection.Open(); var options = new DbContextOptionsBuilder() .UseSqlite(connection) .EnableSensitiveDataLogging() .Options; var context = new AppDbContext(options); context.Database.EnsureCreated(); _contexts.Add(context); return context; } public void Dispose() { foreach (var connection in _connections) connection.Dispose(); foreach (var context in _contexts) context.Dispose(); } }