using Microsoft.EntityFrameworkCore;
using ScadaLink.ConfigurationDatabase;

namespace ScadaLink.ConfigurationDatabase.Tests;

public class SeedDataTests : IDisposable
{
    private readonly ScadaLinkDbContext _context;

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

        _context = new ScadaLinkDbContext(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);
        Assert.Equal("Admin", adminMapping.Role);
        Assert.Equal(1, adminMapping.Id);
    }
}
