Frontend gaps fill work. Testing fixes work. Auditing in progress.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using System.Reflection;
|
||||
using Xunit;
|
||||
using Xunit.Sdk;
|
||||
|
||||
namespace StellaOps.Infrastructure.Postgres.Testing;
|
||||
|
||||
@@ -24,9 +23,8 @@ namespace StellaOps.Infrastructure.Postgres.Testing;
|
||||
/// </code>
|
||||
/// </remarks>
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
|
||||
public sealed class MigrationTestAttribute : BeforeAfterTestAttribute
|
||||
public sealed class MigrationTestAttribute : Attribute
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether to truncate tables before the test runs.
|
||||
/// Default is true.
|
||||
@@ -43,42 +41,6 @@ public sealed class MigrationTestAttribute : BeforeAfterTestAttribute
|
||||
/// Gets or sets specific table names to truncate. If null or empty, all tables are truncated.
|
||||
/// </summary>
|
||||
public string[]? Tables { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Called before the test method runs.
|
||||
/// </summary>
|
||||
public override void Before(MethodInfo methodUnderTest)
|
||||
{
|
||||
if (!TruncateBefore)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Try to find the fixture from the test class
|
||||
var testClass = methodUnderTest.DeclaringType;
|
||||
if (testClass is null) return;
|
||||
|
||||
// Look for a field or property of type PostgresIntegrationFixture
|
||||
var fixtureField = testClass
|
||||
.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
|
||||
.FirstOrDefault(f => typeof(PostgresIntegrationFixture).IsAssignableFrom(f.FieldType));
|
||||
|
||||
var fixtureProperty = testClass
|
||||
.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
|
||||
.FirstOrDefault(p => typeof(PostgresIntegrationFixture).IsAssignableFrom(p.PropertyType));
|
||||
|
||||
// Note: We can't access the instance here in xUnit's BeforeAfterTestAttribute
|
||||
// This is a limitation - the actual truncation needs to be done via a different mechanism
|
||||
// See MigrationTestFixture for a better approach
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called after the test method runs.
|
||||
/// </summary>
|
||||
public override void After(MethodInfo methodUnderTest)
|
||||
{
|
||||
// Cleanup is optional and typically not needed
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -117,7 +79,7 @@ public abstract class MigrationTestBase<TFixture> : IAsyncLifetime
|
||||
/// Called before each test. Override to customize initialization.
|
||||
/// By default, truncates all tables for test isolation.
|
||||
/// </summary>
|
||||
public virtual async Task InitializeAsync()
|
||||
public virtual async ValueTask InitializeAsync()
|
||||
{
|
||||
await _fixture.TruncateAllTablesAsync().ConfigureAwait(false);
|
||||
}
|
||||
@@ -125,9 +87,9 @@ public abstract class MigrationTestBase<TFixture> : IAsyncLifetime
|
||||
/// <summary>
|
||||
/// Called after each test. Override to customize cleanup.
|
||||
/// </summary>
|
||||
public virtual Task DisposeAsync()
|
||||
public virtual ValueTask DisposeAsync()
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
return ValueTask.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -151,3 +113,7 @@ public static class MigrationTestCollection
|
||||
/// </summary>
|
||||
public const string Name = "MigrationTests";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ public abstract class PostgresIntegrationFixture : IAsyncLifetime
|
||||
/// <summary>
|
||||
/// Initializes the PostgreSQL container and runs migrations.
|
||||
/// </summary>
|
||||
public virtual async Task InitializeAsync()
|
||||
public virtual async ValueTask InitializeAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -114,7 +114,7 @@ public abstract class PostgresIntegrationFixture : IAsyncLifetime
|
||||
/// <summary>
|
||||
/// Cleans up the PostgreSQL container and fixture.
|
||||
/// </summary>
|
||||
public virtual async Task DisposeAsync()
|
||||
public virtual async ValueTask DisposeAsync()
|
||||
{
|
||||
if (_fixture != null)
|
||||
{
|
||||
@@ -155,3 +155,5 @@ public sealed class PostgresIntegrationFixtureWithoutMigrations : PostgresIntegr
|
||||
protected override Assembly? GetMigrationAssembly() => null;
|
||||
protected override string GetModuleName() => "Test";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<OutputType>Exe</OutputType>
|
||||
<UseAppHost>true</UseAppHost>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>preview</LangVersion>
|
||||
@@ -15,7 +17,8 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Testcontainers.PostgreSql" />
|
||||
<PackageReference Include="xunit" PrivateAssets="all" />
|
||||
<PackageReference Include="xunit.v3.assert" PrivateAssets="all" />
|
||||
<PackageReference Include="xunit.v3.core" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -23,3 +26,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user