using SQLite;
using Wino.Core.Domain.Entities.Calendar;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Entities.Shared;
using Wino.Services;
namespace Wino.Core.Tests.Helpers;
///
/// In-memory database service for testing purposes.
/// Creates a temporary SQLite database in memory that is destroyed after tests complete.
///
public class InMemoryDatabaseService : IDatabaseService
{
public SQLiteAsyncConnection Connection { get; private set; }
public InMemoryDatabaseService()
{
// Use :memory: for a truly in-memory database or a temporary file
Connection = new SQLiteAsyncConnection(":memory:");
}
public async Task InitializeAsync()
{
await CreateTablesAsync();
}
private async Task CreateTablesAsync()
{
await Task.WhenAll(
Connection.CreateTableAsync(),
Connection.CreateTableAsync(),
Connection.CreateTableAsync(),
Connection.CreateTableAsync(),
Connection.CreateTableAsync(),
Connection.CreateTableAsync(),
Connection.CreateTableAsync(),
Connection.CreateTableAsync(),
Connection.CreateTableAsync(),
Connection.CreateTableAsync(),
Connection.CreateTableAsync(),
Connection.CreateTableAsync(),
Connection.CreateTableAsync(),
Connection.CreateTableAsync(),
Connection.CreateTableAsync()
);
}
public async ValueTask DisposeAsync()
{
if (Connection != null)
{
await Connection.CloseAsync();
Connection = null!;
}
}
}