using Microsoft.EntityFrameworkCore;
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase;

namespace ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Tests;

public class SeedDataTests : IDisposable
{
    private readonly ScadaBridgeDbContext _context;

    public SeedDataTests()
    {
        var options = new DbContextOptionsBuilder<ScadaBridgeDbContext>()
            .UseSqlite("DataSource=:memory:")
            .Options;

        _context = new ScadaBridgeDbContext(options);
        _context.Database.OpenConnection();
        _context.Database.EnsureCreated();
    }

    public void Dispose()
    {
        _context.Database.CloseConnection();
        _context.Dispose();
    }

    [Fact]
    public async Task SeedData_AdminMappingExists()
    {
        var adminMapping = await _context.LdapGroupMappings
            .SingleOrDefaultAsync(m => m.LdapGroupName == "SCADA-Admins");

        Assert.NotNull(adminMapping);
        // Role VALUE canonicalized to "Administrator" (Task 1.7); group NAME unchanged.
        Assert.Equal("Administrator", adminMapping.Role);
        Assert.Equal(1, adminMapping.Id);
    }
}
