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:
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user