35 lines
967 B
C#
35 lines
967 B
C#
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<SqliteConnection> _connections = new List<SqliteConnection>();
|
|
private readonly IList<AppDbContext> _contexts = new List<AppDbContext>();
|
|
|
|
public AppDbContext CreateContext()
|
|
{
|
|
var connection = new SqliteConnection("Filename=:memory:");
|
|
_connections.Add(connection);
|
|
connection.Open();
|
|
|
|
var options = new DbContextOptionsBuilder<AppDbContext>()
|
|
.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();
|
|
}
|
|
} |