Host infrastructure (WP-11–17): - StartupValidator with 19 validation rules - /health/ready endpoint with DB + Akka health checks - Akka.NET bootstrap via AkkaHostedService (HOCON config, cluster, remoting, SBR) - Serilog with SiteId/NodeHostname/NodeRole enrichment - DeadLetterMonitorActor with count tracking - CoordinatedShutdown wiring (no Environment.Exit) - Windows Service support (UseWindowsService) Central UI (WP-18–21): - Blazor Server shell with Bootstrap 5, role-aware NavMenu - Login/logout flow (LDAP auth → JWT → HTTP-only cookie) - CookieAuthenticationStateProvider with idle timeout - LDAP group mapping CRUD page (Admin role) - Route guards with Authorize attributes per role - SignalR reconnection overlay for failover Integration tests (WP-22): - Startup validation, auth flow, audit transactions, readiness gating 186 tests pass (1 skipped: LDAP integration), zero warnings.
67 lines
2.5 KiB
C#
67 lines
2.5 KiB
C#
using Microsoft.AspNetCore.Mvc.Testing;
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace ScadaLink.Host.Tests;
|
|
|
|
/// <summary>
|
|
/// WP-12: Tests for /health/ready endpoint.
|
|
/// </summary>
|
|
public class HealthCheckTests : IDisposable
|
|
{
|
|
private readonly List<IDisposable> _disposables = new();
|
|
|
|
public void Dispose()
|
|
{
|
|
foreach (var d in _disposables)
|
|
{
|
|
try { d.Dispose(); } catch { /* best effort */ }
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public async Task HealthReady_Endpoint_ReturnsResponse()
|
|
{
|
|
var previousEnv = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT");
|
|
try
|
|
{
|
|
Environment.SetEnvironmentVariable("DOTNET_ENVIRONMENT", "Central");
|
|
|
|
var factory = new WebApplicationFactory<Program>()
|
|
.WithWebHostBuilder(builder =>
|
|
{
|
|
builder.ConfigureAppConfiguration((context, config) =>
|
|
{
|
|
config.AddInMemoryCollection(new Dictionary<string, string?>
|
|
{
|
|
["ScadaLink:Node:NodeHostname"] = "localhost",
|
|
["ScadaLink:Node:RemotingPort"] = "0",
|
|
["ScadaLink:Cluster:SeedNodes:0"] = "akka.tcp://scadalink@localhost:2551",
|
|
["ScadaLink:Cluster:SeedNodes:1"] = "akka.tcp://scadalink@localhost:2552",
|
|
["ScadaLink:Database:SkipMigrations"] = "true",
|
|
});
|
|
});
|
|
builder.UseSetting("ScadaLink:Node:Role", "Central");
|
|
builder.UseSetting("ScadaLink:Database:SkipMigrations", "true");
|
|
});
|
|
_disposables.Add(factory);
|
|
|
|
var client = factory.CreateClient();
|
|
_disposables.Add(client);
|
|
|
|
var response = await client.GetAsync("/health/ready");
|
|
|
|
// The endpoint exists and returns a status code.
|
|
// With test infrastructure (no real DB), the database check may fail,
|
|
// so we accept either 200 (Healthy) or 503 (Unhealthy).
|
|
Assert.True(
|
|
response.StatusCode == System.Net.HttpStatusCode.OK ||
|
|
response.StatusCode == System.Net.HttpStatusCode.ServiceUnavailable,
|
|
$"Expected 200 or 503, got {(int)response.StatusCode}");
|
|
}
|
|
finally
|
|
{
|
|
Environment.SetEnvironmentVariable("DOTNET_ENVIRONMENT", previousEnv);
|
|
}
|
|
}
|
|
}
|