35 lines
858 B
C#
35 lines
858 B
C#
using Microsoft.Data.Sqlite;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using MissionControl.Data;
|
|
|
|
namespace MissionControl.Server.Tests;
|
|
|
|
/// <summary>
|
|
/// An in-memory SQLite database that speaks real EF Core, for fast endpoint tests
|
|
/// without a SQL Server instance.
|
|
/// </summary>
|
|
public sealed class TestDatabase : IDisposable
|
|
{
|
|
private readonly SqliteConnection _connection = new("DataSource=:memory:");
|
|
|
|
public TestDatabase()
|
|
{
|
|
_connection.Open();
|
|
|
|
var options = new DbContextOptionsBuilder<MissionControlContext>()
|
|
.UseSqlite(_connection)
|
|
.Options;
|
|
|
|
Context = new MissionControlContext(options);
|
|
Context.Database.EnsureCreated();
|
|
}
|
|
|
|
public MissionControlContext Context { get; }
|
|
|
|
public void Dispose()
|
|
{
|
|
Context.Dispose();
|
|
_connection.Dispose();
|
|
}
|
|
}
|