mirror of
https://github.com/Sea-Haven-Industries/proposal-system.git
synced 2026-09-30 22:53:13 +00:00
23 lines
680 B
C#
23 lines
680 B
C#
|
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
using ProposalSystem.Infrastructure.Data;
|
||
|
|
|
||
|
|
namespace ProposalSystem.Tests.Helpers;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Creates isolated in-memory DbContext instances for unit tests.
|
||
|
|
/// Each call produces a uniquely-named database so tests don't leak state.
|
||
|
|
/// </summary>
|
||
|
|
public static class DbContextFactory
|
||
|
|
{
|
||
|
|
public static ProposalDbContext Create()
|
||
|
|
{
|
||
|
|
var options = new DbContextOptionsBuilder<ProposalDbContext>()
|
||
|
|
.UseInMemoryDatabase(databaseName: $"TestDb_{Guid.NewGuid()}")
|
||
|
|
.Options;
|
||
|
|
|
||
|
|
var context = new ProposalDbContext(options);
|
||
|
|
context.Database.EnsureCreated();
|
||
|
|
return context;
|
||
|
|
}
|
||
|
|
}
|