Init repo
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user