using System; using Microsoft.EntityFrameworkCore; namespace PolyTrader.Tests.TestSupport { /// /// Test-Implementierung von auf Basis des /// EF-Core-InMemory-Providers. Jede Factory-Instanz nutzt eine eigene (per GUID benannte) /// In-Memory-DB, sodass Tests voneinander isoliert sind; alle vom selben Factory erzeugten /// Kontexte teilen sich die gleiche Datenbank (wie im echten Betrieb der DbContextFactory). /// public sealed class InMemoryContextFactory : IDbContextFactory where TContext : DbContext { private readonly Func, TContext> _ctor; private readonly DbContextOptions _options; public InMemoryContextFactory(Func, TContext> ctor) { _ctor = ctor; _options = new DbContextOptionsBuilder() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .EnableSensitiveDataLogging() .Options; } public TContext CreateDbContext() => _ctor(_options); } }