This commit is contained in:
master
2026-01-07 10:25:34 +02:00
726 changed files with 147397 additions and 1364 deletions

View File

@@ -80,12 +80,12 @@ public class PostgresOnlyStartupTests : IAsyncLifetime
// Arrange
var ct = TestContext.Current.CancellationToken;
using var connection = new Npgsql.NpgsqlConnection(_connectionString);
await connection.OpenAsync(ct);
await connection.OpenAsync(TestContext.Current.CancellationToken);
// Act - Create a test schema
using var createCmd = connection.CreateCommand();
createCmd.CommandText = "CREATE SCHEMA IF NOT EXISTS test_platform";
await createCmd.ExecuteNonQueryAsync(ct);
await createCmd.ExecuteNonQueryAsync(TestContext.Current.CancellationToken);
// Assert - Verify schema exists
using var verifyCmd = connection.CreateCommand();
@@ -93,7 +93,7 @@ public class PostgresOnlyStartupTests : IAsyncLifetime
SELECT schema_name
FROM information_schema.schemata
WHERE schema_name = 'test_platform'";
var result = await verifyCmd.ExecuteScalarAsync(ct);
var result = await verifyCmd.ExecuteScalarAsync(TestContext.Current.CancellationToken);
result.Should().Be("test_platform");
}
@@ -103,7 +103,7 @@ public class PostgresOnlyStartupTests : IAsyncLifetime
// Arrange
var ct = TestContext.Current.CancellationToken;
using var connection = new Npgsql.NpgsqlConnection(_connectionString);
await connection.OpenAsync(ct);
await connection.OpenAsync(TestContext.Current.CancellationToken);
// Create test table
using var createCmd = connection.CreateCommand();
@@ -113,33 +113,33 @@ public class PostgresOnlyStartupTests : IAsyncLifetime
name VARCHAR(100) NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW()
)";
await createCmd.ExecuteNonQueryAsync(ct);
await createCmd.ExecuteNonQueryAsync(TestContext.Current.CancellationToken);
// Act - Insert
using var insertCmd = connection.CreateCommand();
insertCmd.CommandText = "INSERT INTO test_crud (name) VALUES ('test-record') RETURNING id";
var insertedId = await insertCmd.ExecuteScalarAsync(ct);
var insertedId = await insertCmd.ExecuteScalarAsync(TestContext.Current.CancellationToken);
insertedId.Should().NotBeNull();
// Act - Select
using var selectCmd = connection.CreateCommand();
selectCmd.CommandText = "SELECT name FROM test_crud WHERE id = @id";
selectCmd.Parameters.AddWithValue("id", insertedId!);
var name = await selectCmd.ExecuteScalarAsync(ct);
var name = await selectCmd.ExecuteScalarAsync(TestContext.Current.CancellationToken);
name.Should().Be("test-record");
// Act - Update
using var updateCmd = connection.CreateCommand();
updateCmd.CommandText = "UPDATE test_crud SET name = 'updated-record' WHERE id = @id";
updateCmd.Parameters.AddWithValue("id", insertedId!);
var rowsAffected = await updateCmd.ExecuteNonQueryAsync(ct);
var rowsAffected = await updateCmd.ExecuteNonQueryAsync(TestContext.Current.CancellationToken);
rowsAffected.Should().Be(1);
// Act - Delete
using var deleteCmd = connection.CreateCommand();
deleteCmd.CommandText = "DELETE FROM test_crud WHERE id = @id";
deleteCmd.Parameters.AddWithValue("id", insertedId!);
rowsAffected = await deleteCmd.ExecuteNonQueryAsync(ct);
rowsAffected = await deleteCmd.ExecuteNonQueryAsync(TestContext.Current.CancellationToken);
rowsAffected.Should().Be(1);
}
@@ -153,7 +153,7 @@ public class PostgresOnlyStartupTests : IAsyncLifetime
// Arrange
var ct = TestContext.Current.CancellationToken;
using var connection = new Npgsql.NpgsqlConnection(_connectionString);
await connection.OpenAsync(ct);
await connection.OpenAsync(TestContext.Current.CancellationToken);
// Act - Run a migration-like DDL script
var migrationScript = @"
@@ -180,12 +180,12 @@ public class PostgresOnlyStartupTests : IAsyncLifetime
using var migrateCmd = connection.CreateCommand();
migrateCmd.CommandText = migrationScript;
await migrateCmd.ExecuteNonQueryAsync(ct);
await migrateCmd.ExecuteNonQueryAsync(TestContext.Current.CancellationToken);
// Assert - Verify migration recorded
using var verifyCmd = connection.CreateCommand();
verifyCmd.CommandText = "SELECT COUNT(*) FROM schema_migrations WHERE version = 'V2_create_scan_results'";
var count = await verifyCmd.ExecuteScalarAsync(ct);
var count = await verifyCmd.ExecuteScalarAsync(TestContext.Current.CancellationToken);
Convert.ToInt32(count).Should().Be(1);
}
@@ -195,17 +195,17 @@ public class PostgresOnlyStartupTests : IAsyncLifetime
// Arrange
var ct = TestContext.Current.CancellationToken;
using var connection = new Npgsql.NpgsqlConnection(_connectionString);
await connection.OpenAsync(ct);
await connection.OpenAsync(TestContext.Current.CancellationToken);
// Act - Create common extensions used by StellaOps
using var extCmd = connection.CreateCommand();
extCmd.CommandText = "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\"";
await extCmd.ExecuteNonQueryAsync(ct);
await extCmd.ExecuteNonQueryAsync(TestContext.Current.CancellationToken);
// Assert - Verify extension exists
using var verifyCmd = connection.CreateCommand();
verifyCmd.CommandText = "SELECT COUNT(*) FROM pg_extension WHERE extname = 'uuid-ossp'";
var count = await verifyCmd.ExecuteScalarAsync(ct);
var count = await verifyCmd.ExecuteScalarAsync(TestContext.Current.CancellationToken);
Convert.ToInt32(count).Should().Be(1);
}