refactor(tests): SqlTestFixture usa TestConnectionStrings; ctor interno para Api.Tests

Agrega ctor parameterless que apunta a SIGCM2_Test_App (requerido por
xUnit ICollectionFixture<T>). El ctor con string se marca internal y
expone via InternalsVisibleTo a SIGCM2.Api.Tests. TestWebAppFactory
apunta a SIGCM2_Test_Api. Se agrega propiedad Connection pública para
que los tests que necesitan queries ad-hoc la usen.
This commit is contained in:
2026-04-18 21:44:19 -03:00
parent d4a2b3bc3e
commit e987228f14
2 changed files with 17 additions and 4 deletions

View File

@@ -16,7 +16,14 @@ public sealed class SqlTestFixture : IAsyncLifetime
private SqlConnection _connection = null!; private SqlConnection _connection = null!;
private Respawner _respawner = 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; _connectionString = connectionString;
} }
@@ -80,6 +87,13 @@ public sealed class SqlTestFixture : IAsyncLifetime
await ResetAndSeedAsync(); 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() public async Task ResetAndSeedAsync()
{ {
await _respawner.ResetAsync(_connection); await _respawner.ResetAsync(_connection);

View File

@@ -13,12 +13,11 @@ namespace SIGCM2.TestSupport;
/// <summary> /// <summary>
/// WebApplicationFactory for integration tests against SIGCM2.Api. /// 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> /// </summary>
public sealed class TestWebAppFactory : WebApplicationFactory<Program>, IAsyncLifetime public sealed class TestWebAppFactory : WebApplicationFactory<Program>, IAsyncLifetime
{ {
private const string TestConnectionString = private const string TestConnectionString = TestConnectionStrings.ApiTestDb;
"Server=TECNICA3;Database=SIGCM2_Test;User Id=desarrollo;Password=desarrollo2026;TrustServerCertificate=True;";
// Resolved once — absolute paths independent of working directory // Resolved once — absolute paths independent of working directory
private static readonly string RepoRoot = ResolveRepoRoot(); private static readonly string RepoRoot = ResolveRepoRoot();