Merge pull request 'fix: issue #29 — integration tests flakiness (DB split + SqlTestFixture consolidado)' (#34) from fix/issue-29-flakiness into main

This commit was merged in pull request #34.
This commit is contained in:
2026-04-19 10:41:27 +00:00
41 changed files with 228 additions and 514 deletions

View File

@@ -16,7 +16,14 @@ public sealed class SqlTestFixture : IAsyncLifetime
private SqlConnection _connection = null!;
private Respawner _respawner = null!;
public SqlTestFixture(string connectionString)
/// <summary>Parameterless ctor for xUnit ICollectionFixture — uses SIGCM2_Test_App.</summary>
public SqlTestFixture() : this(TestConnectionStrings.AppTestDb) { }
/// <summary>
/// Explicit connection string ctor — used by TestWebAppFactory (same assembly).
/// Internal to satisfy xUnit's "single public constructor" rule for ICollectionFixture.
/// </summary>
internal SqlTestFixture(string connectionString)
{
_connectionString = connectionString;
}
@@ -80,6 +87,13 @@ public sealed class SqlTestFixture : IAsyncLifetime
await ResetAndSeedAsync();
}
/// <summary>
/// Exposes the open SqlConnection for tests that need to run ad-hoc queries
/// (e.g. seed extra rows, assert history tables). Connection is opened during
/// InitializeAsync and closed in DisposeAsync.
/// </summary>
public SqlConnection Connection => _connection;
public async Task ResetAndSeedAsync()
{
await _respawner.ResetAsync(_connection);

View File

@@ -0,0 +1,20 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("SIGCM2.Api.Tests")]
namespace SIGCM2.TestSupport;
/// <summary>
/// Centralized connection string constants for integration test databases.
/// Single source of truth — change server/credentials here only.
/// </summary>
public static class TestConnectionStrings
{
/// <summary>Used by SIGCM2.Application.Tests via SqlTestFixture (parameterless ctor).</summary>
public const string AppTestDb =
"Server=TECNICA3;Database=SIGCM2_Test_App;User Id=desarrollo;Password=desarrollo2026;TrustServerCertificate=True;";
/// <summary>Used by SIGCM2.Api.Tests via TestWebAppFactory.</summary>
public const string ApiTestDb =
"Server=TECNICA3;Database=SIGCM2_Test_Api;User Id=desarrollo;Password=desarrollo2026;TrustServerCertificate=True;";
}

View File

@@ -13,12 +13,11 @@ namespace SIGCM2.TestSupport;
/// <summary>
/// WebApplicationFactory for integration tests against SIGCM2.Api.
/// Uses SIGCM2_Test database (separate from production SIGCM2).
/// Uses SIGCM2_Test_Api database (isolated from Application.Tests which uses SIGCM2_Test_App).
/// </summary>
public sealed class TestWebAppFactory : WebApplicationFactory<Program>, IAsyncLifetime
{
private const string TestConnectionString =
"Server=TECNICA3;Database=SIGCM2_Test;User Id=desarrollo;Password=desarrollo2026;TrustServerCertificate=True;";
private const string TestConnectionString = TestConnectionStrings.ApiTestDb;
// Resolved once — absolute paths independent of working directory
private static readonly string RepoRoot = ResolveRepoRoot();