using Mbproxy.Admin;
using Shouldly;
using Xunit;
namespace Mbproxy.Tests.Admin;
///
/// Unit tests for .
/// All tests are pure: no network, no host, no DI.
///
[Trait("Category", "Unit")]
public sealed class StatusHtmlRendererTests
{
// ── Helpers ───────────────────────────────────────────────────────────────
private static StatusResponse MakeStatus(
IReadOnlyList? plcs = null,
int uptimeSeconds = 42,
string version = "1.2.3")
{
var service = new ServiceFields(
UptimeSeconds: uptimeSeconds,
Version: version,
ConfigLastReloadUtc: null,
ConfigReloadCount: 0,
ConfigReloadRejectedCount: 0);
var listeners = new ListenersAggregate(Bound: plcs?.Count ?? 0, Configured: plcs?.Count ?? 0);
return new StatusResponse(service, listeners, plcs ?? []);
}
private static PlcStatus MakePlc(
string name = "PLC-A",
string state = "bound",
string? lastBindError = null,
int recoveryAttempts = 0,
IReadOnlyList? clients = null)
{
var noClients = (IReadOnlyList)[];
return new PlcStatus(
Name: name,
Host: "10.0.0.1",
ListenPort: 5020,
Listener: new PlcListenerStatus(state, lastBindError, recoveryAttempts),
Clients: new PlcClientsStatus(clients?.Count ?? 0, clients ?? noClients),
Pdus: new PlcPdusStatus(100, new FcCounts(50, 10, 20, 15, 5), 30, 2, 0),
Backend: new PlcBackendStatus(
ConnectsSuccess: 0, ConnectsFailed: 0,
ExceptionsByCode: new ExceptionCounts(1, 0, 0, 0, 0),
LastRoundTripMs: 3.5,
InFlight: 0, MaxInFlight: 0, TxIdWraps: 0,
DisconnectCascades: 0, QueueDepth: 0,
CoalescedHitCount: 0, CoalescedMissCount: 0,
CoalescedResponseToDeadUpstream: 0,
CacheHitCount: 0, CacheMissCount: 0,
CacheInvalidations: 0, CacheEntryCount: 0, CacheBytes: 0,
BackendHeartbeatsSent: 0, BackendHeartbeatsFailed: 0,
BackendIdleDisconnects: 0),
Bytes: new PlcBytesStatus(1024, 2048));
}
// ── 1. Valid HTML with meta-refresh for a single PLC ─────────────────────
[Fact]
public void Render_OnePlc_ProducesValidHtml_WithMetaRefresh()
{
var status = MakeStatus([MakePlc("PLC-A", "bound")]);
string html = StatusHtmlRenderer.Render(status);
html.ShouldContain("");
html.ShouldContain("");
html.ShouldContain("