using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Diagnostics; using ProposalSystem.Infrastructure.Data; namespace ProposalSystem.Tests.Helpers; /// /// Creates isolated in-memory DbContext instances for unit tests. /// Each call produces a uniquely-named database so tests don't leak state. /// Transaction warnings are suppressed since InMemory provider does not support them. /// public static class DbContextFactory { public static ProposalDbContext Create() { var options = new DbContextOptionsBuilder() .UseInMemoryDatabase(databaseName: $"TestDb_{Guid.NewGuid()}") .ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning)) .Options; var context = new ProposalDbContext(options); context.Database.EnsureCreated(); return context; } }