Files
scadalink-design/tests/ScadaLink.Host.Tests/WindowsServiceTests.cs
Joseph Doherty d38356efdb Phase 1 WP-11–22: Host infrastructure, Blazor Server UI, and integration tests
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.
2026-03-16 19:50:59 -04:00

57 lines
1.8 KiB
C#

using System.Reflection;
namespace ScadaLink.Host.Tests;
/// <summary>
/// WP-17: Tests for Windows Service support.
/// Verifies UseWindowsService() is called in Program.cs.
/// </summary>
public class WindowsServiceTests
{
[Fact]
public void ProgramCs_CallsUseWindowsService()
{
var hostProjectDir = FindHostProjectDirectory();
Assert.NotNull(hostProjectDir);
var programFile = Path.Combine(hostProjectDir, "Program.cs");
Assert.True(File.Exists(programFile), "Program.cs not found");
var content = File.ReadAllText(programFile);
// Verify UseWindowsService() is called for both Central and Site paths
var occurrences = content.Split("UseWindowsService()").Length - 1;
Assert.True(occurrences >= 2,
$"Expected UseWindowsService() to be called at least twice (Central and Site paths), found {occurrences} occurrence(s)");
}
[Fact]
public void HostProject_ReferencesWindowsServicesPackage()
{
var hostProjectDir = FindHostProjectDirectory();
Assert.NotNull(hostProjectDir);
var csprojFile = Path.Combine(hostProjectDir, "ScadaLink.Host.csproj");
Assert.True(File.Exists(csprojFile), "ScadaLink.Host.csproj not found");
var content = File.ReadAllText(csprojFile);
Assert.Contains("Microsoft.Extensions.Hosting.WindowsServices", content);
}
private static string? FindHostProjectDirectory()
{
var assemblyDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!;
var dir = new DirectoryInfo(assemblyDir);
while (dir != null)
{
var hostPath = Path.Combine(dir.FullName, "src", "ScadaLink.Host");
if (Directory.Exists(hostPath))
return hostPath;
dir = dir.Parent;
}
return null;
}
}