using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using VCommon.VEntityFrameworkCore.Tests.Configs;
using VCommon.VEntityFrameworkCore.Tests.Entities;
using Xunit.Abstractions;

namespace VCommon.VEntityFrameworkCore.Tests.Efc
{
    public class TestDbContext : VEfDbContextBase
    {
        private readonly ITestOutputHelper _outputHelper;
        public virtual DbSet<TestEntity> TestEntities { get; set; }

        public TestDbContext()
        {
        }

        public TestDbContext(ITestOutputHelper outputHelper)
        {
            _outputHelper = outputHelper;
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());
            optionsBuilder.UseMySQL(configuration.GetConnectionString("Default"));

            if (_outputHelper != null) optionsBuilder.LogTo(_outputHelper.WriteLine);

            optionsBuilder.EnableSensitiveDataLogging();

            base.OnConfiguring(optionsBuilder);
        }
    }
}
