using Microsoft.EntityFrameworkCore;
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase;
namespace ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Tests;
public class SeedDataTests : IDisposable
{
private readonly ScadaBridgeDbContext _context;
/// Initializes an in-memory SQLite database with the schema and seed data applied.
public SeedDataTests()
{
var options = new DbContextOptionsBuilder()
.UseSqlite("DataSource=:memory:")
.Options;
_context = new ScadaBridgeDbContext(options);
_context.Database.OpenConnection();
_context.Database.EnsureCreated();
}
/// Releases the resources held by the test fixture.
public void Dispose()
{
_context.Database.CloseConnection();
_context.Dispose();
}
/// Verifies that the seeded administrator LDAP group mapping exists.
/// A task that represents the asynchronous operation.
[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"; group NAME unchanged.
Assert.Equal("Administrator", adminMapping.Role);
Assert.Equal(1, adminMapping.Id);
}
}