- WP-1-3: Central/site failover + dual-node recovery tests (17 tests) - WP-4: Performance testing framework for target scale (7 tests) - WP-5: Security hardening (LDAPS, JWT key length, no secrets in logs) (11 tests) - WP-6: Script sandboxing adversarial tests (28 tests, all forbidden APIs) - WP-7: Recovery drill test scaffolds (5 tests) - WP-8: Observability validation (structured logs, correlation IDs, metrics) (6 tests) - WP-9: Message contract compatibility (forward/backward compat) (18 tests) - WP-10: Deployment packaging (installation guide, production checklist, topology) - WP-11: Operational runbooks (failover, troubleshooting, maintenance) 92 new tests, all passing. Zero warnings.
57 lines
1.9 KiB
C#
57 lines
1.9 KiB
C#
using Microsoft.Extensions.Logging.Abstractions;
|
|
using NSubstitute;
|
|
using ScadaLink.Commons.Entities.ExternalSystems;
|
|
using ScadaLink.Commons.Interfaces.Repositories;
|
|
|
|
namespace ScadaLink.ExternalSystemGateway.Tests;
|
|
|
|
/// <summary>
|
|
/// WP-9: Tests for Database access — connection resolution, cached writes.
|
|
/// </summary>
|
|
public class DatabaseGatewayTests
|
|
{
|
|
private readonly IExternalSystemRepository _repository = Substitute.For<IExternalSystemRepository>();
|
|
|
|
[Fact]
|
|
public async Task GetConnection_NotFound_Throws()
|
|
{
|
|
_repository.GetAllDatabaseConnectionsAsync().Returns(new List<DatabaseConnectionDefinition>());
|
|
|
|
var gateway = new DatabaseGateway(
|
|
_repository,
|
|
NullLogger<DatabaseGateway>.Instance);
|
|
|
|
await Assert.ThrowsAsync<InvalidOperationException>(
|
|
() => gateway.GetConnectionAsync("nonexistent"));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CachedWrite_NoStoreAndForward_Throws()
|
|
{
|
|
var conn = new DatabaseConnectionDefinition("testDb", "Server=localhost;Database=test") { Id = 1 };
|
|
_repository.GetAllDatabaseConnectionsAsync()
|
|
.Returns(new List<DatabaseConnectionDefinition> { conn });
|
|
|
|
var gateway = new DatabaseGateway(
|
|
_repository,
|
|
NullLogger<DatabaseGateway>.Instance,
|
|
storeAndForward: null);
|
|
|
|
await Assert.ThrowsAsync<InvalidOperationException>(
|
|
() => gateway.CachedWriteAsync("testDb", "INSERT INTO t VALUES (1)"));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CachedWrite_ConnectionNotFound_Throws()
|
|
{
|
|
_repository.GetAllDatabaseConnectionsAsync().Returns(new List<DatabaseConnectionDefinition>());
|
|
|
|
var gateway = new DatabaseGateway(
|
|
_repository,
|
|
NullLogger<DatabaseGateway>.Instance);
|
|
|
|
await Assert.ThrowsAsync<InvalidOperationException>(
|
|
() => gateway.CachedWriteAsync("nonexistent", "INSERT INTO t VALUES (1)"));
|
|
}
|
|
}
|