59 lines
2.1 KiB
C#
59 lines
2.1 KiB
C#
using FluentAssertions;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using StellaOps.Concelier.ProofService.Postgres.EfCore.CompiledModels;
|
|
using StellaOps.Concelier.ProofService.Postgres.EfCore.Models;
|
|
using Xunit;
|
|
|
|
namespace StellaOps.Concelier.ProofService.Postgres.Tests;
|
|
|
|
/// <summary>
|
|
/// Guard tests ensuring the EF Core compiled model is real (not a stub)
|
|
/// and contains all expected entity type registrations.
|
|
/// </summary>
|
|
public sealed class CompiledModelGuardTests
|
|
{
|
|
[Trait("Category", "Unit")]
|
|
[Fact]
|
|
public void CompiledModel_Instance_IsNotNull()
|
|
{
|
|
ProofServiceDbContextModel.Instance.Should().NotBeNull(
|
|
"compiled model must be generated via 'dotnet ef dbcontext optimize', not a stub");
|
|
}
|
|
|
|
[Trait("Category", "Unit")]
|
|
[Fact]
|
|
public void CompiledModel_HasExpectedEntityTypeCount()
|
|
{
|
|
var entityTypes = ProofServiceDbContextModel.Instance.GetEntityTypes().ToList();
|
|
entityTypes.Should().HaveCount(5,
|
|
"proof-service compiled model must contain exactly 5 entity types (regenerate with 'dotnet ef dbcontext optimize' if count differs)");
|
|
}
|
|
|
|
[Trait("Category", "Unit")]
|
|
[Theory]
|
|
[InlineData(typeof(BinaryFingerprintEntity))]
|
|
[InlineData(typeof(ChangelogEvidenceEntity))]
|
|
[InlineData(typeof(DistroAdvisoryEntity))]
|
|
[InlineData(typeof(PatchEvidenceEntity))]
|
|
[InlineData(typeof(PatchSignatureEntity))]
|
|
public void CompiledModel_ContainsEntityType(Type entityType)
|
|
{
|
|
var found = ProofServiceDbContextModel.Instance.FindEntityType(entityType);
|
|
found.Should().NotBeNull(
|
|
$"compiled model must contain entity type '{entityType.Name}' — regenerate if missing");
|
|
}
|
|
|
|
[Trait("Category", "Unit")]
|
|
[Fact]
|
|
public void CompiledModel_EntityTypes_HaveTableNames()
|
|
{
|
|
var entityTypes = ProofServiceDbContextModel.Instance.GetEntityTypes();
|
|
foreach (var entityType in entityTypes)
|
|
{
|
|
var tableName = entityType.GetTableName();
|
|
tableName.Should().NotBeNullOrWhiteSpace(
|
|
$"entity type '{entityType.ClrType.Name}' must have a table name configured");
|
|
}
|
|
}
|
|
}
|