using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; using Novelly.Api.Data; namespace Novelly.Api.Tests; public class TestDatabase : IDisposable { private readonly SqliteConnection _connection; public TestDatabase() { _connection = new SqliteConnection("Data Source=:memory:"); _connection.Open(); Context = CreateContext(); Context.Database.EnsureCreated(); } public NovelDbContext Context { get; } public NovelDbContext CreateContext() => new(new DbContextOptionsBuilder().UseSqlite(_connection).Options); public void Dispose() { Context.Dispose(); _connection.Dispose(); GC.SuppressFinalize(this); } }