using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using ServicesDAO.Data; namespace DynamicCrud.Tests.Fixtures; public class DbContextFixture : IDisposable { private readonly DbContextOptions _options; public DbContextFixture() { // Misma fuente de credenciales que el servidor: appsettings.secrets.json (no versionado), // copiado a la salida desde server/. Las variables de entorno tienen prioridad para CI. var config = new ConfigurationBuilder() .SetBasePath(AppContext.BaseDirectory) .AddJsonFile("appsettings.test.json", optional: true) .AddJsonFile("appsettings.secrets.json", optional: true) .AddEnvironmentVariables() .Build(); var connectionString = config.GetConnectionString("Local") ?? throw new InvalidOperationException( "ConnectionStrings:Local no está configurado. Cree server/appsettings.secrets.json " + "a partir de server/appsettings.secrets.example.json, o defina la variable de entorno " + "ConnectionStrings__Local. Ver la sección 'Credenciales de base de datos' del README."); _options = new DbContextOptionsBuilder() .UseMySQL(connectionString) .UseSnakeCaseNamingConvention() .Options; } public CloudServicesDbContext CreateContext() => new(_options); public void Dispose() { } }