Files
TeleWave/backend/tests/TeleWave.Application.Tests/Support/TestDb.cs
T

18 lines
808 B
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Microsoft.EntityFrameworkCore;
using TeleWave.Infrastructure.Persistence;
namespace TeleWave.Application.Tests.Support;
/// <summary>
/// Общий InMemory-стенд поверх реального <see cref="AppDbContext"/> (с настоящими EF-конфигурациями).
/// Каждый экземпляр — своя изолированная БД; <see cref="New"/> отдаёт новый контекст на ту же БД,
/// чтобы можно было перечитать сохранённое свежим контекстом.
/// </summary>
internal sealed class TestDb
{
private readonly string _name = $"tw-{Guid.NewGuid():N}";
public AppDbContext New() =>
new(new DbContextOptionsBuilder<AppDbContext>().UseInMemoryDatabase(_name).Options);
}