This commit is contained in:
StellaOps Bot
2025-11-29 02:19:50 +02:00
parent 2548abc56f
commit b34f13dc03
86 changed files with 9625 additions and 640 deletions

View File

@@ -0,0 +1,68 @@
using FluentAssertions;
using Npgsql;
using Xunit;
namespace StellaOps.Authority.Storage.Postgres.Tests;
/// <summary>
/// Tests that verify Authority module migrations run successfully.
/// </summary>
[Collection(AuthorityPostgresCollection.Name)]
public sealed class AuthorityMigrationTests
{
private readonly AuthorityPostgresFixture _fixture;
public AuthorityMigrationTests(AuthorityPostgresFixture fixture)
{
_fixture = fixture;
}
[Fact]
public async Task MigrationsApplied_SchemaHasTables()
{
// Arrange
await using var connection = new NpgsqlConnection(_fixture.ConnectionString);
await connection.OpenAsync();
// Act - Query for tables in schema
await using var cmd = new NpgsqlCommand(
"""
SELECT table_name FROM information_schema.tables
WHERE table_schema = @schema
AND table_type = 'BASE TABLE'
ORDER BY table_name;
""",
connection);
cmd.Parameters.AddWithValue("schema", _fixture.SchemaName);
var tables = new List<string>();
await using var reader = await cmd.ExecuteReaderAsync();
while (await reader.ReadAsync())
{
tables.Add(reader.GetString(0));
}
// Assert - Should have core Authority tables
tables.Should().Contain("schema_migrations");
// Add more specific table assertions based on Authority migrations
}
[Fact]
public async Task MigrationsApplied_SchemaVersionRecorded()
{
// Arrange
await using var connection = new NpgsqlConnection(_fixture.ConnectionString);
await connection.OpenAsync();
// Act - Check schema_migrations table
await using var cmd = new NpgsqlCommand(
$"SELECT COUNT(*) FROM {_fixture.SchemaName}.schema_migrations;",
connection);
var count = await cmd.ExecuteScalarAsync();
// Assert - At least one migration should be recorded
count.Should().NotBeNull();
((long)count!).Should().BeGreaterThan(0);
}
}

View File

@@ -0,0 +1,28 @@
using System.Reflection;
using StellaOps.Authority.Storage.Postgres;
using StellaOps.Infrastructure.Postgres.Testing;
using Xunit;
namespace StellaOps.Authority.Storage.Postgres.Tests;
/// <summary>
/// PostgreSQL integration test fixture for the Authority module.
/// Runs migrations from embedded resources and provides test isolation.
/// </summary>
public sealed class AuthorityPostgresFixture : PostgresIntegrationFixture, ICollectionFixture<AuthorityPostgresFixture>
{
protected override Assembly? GetMigrationAssembly()
=> typeof(AuthorityDataSource).Assembly;
protected override string GetModuleName() => "Authority";
}
/// <summary>
/// Collection definition for Authority PostgreSQL integration tests.
/// Tests in this collection share a single PostgreSQL container instance.
/// </summary>
[CollectionDefinition(Name)]
public sealed class AuthorityPostgresCollection : ICollectionFixture<AuthorityPostgresFixture>
{
public const string Name = "AuthorityPostgres";
}

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" ?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\__Libraries\StellaOps.Authority.Storage.Postgres\StellaOps.Authority.Storage.Postgres.csproj" />
<ProjectReference Include="..\..\..\__Libraries\StellaOps.Infrastructure.Postgres.Testing\StellaOps.Infrastructure.Postgres.Testing.csproj" />
</ItemGroup>
</Project>