Files
lmxopcua/tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests/DriverStatusSnapshotStoreTests.cs
Joseph Doherty bd6c0b4d3d docs: complete XML doc comments via fixdocs (2757 to 131 findings)
Add missing <returns>/<param>/<summary>/<typeparam> tags and clean up
misused inheritdoc across 481 files so the documented API surface is
complete. Documentation-only (zero code lines changed). The 131 remaining
findings are inheritdoc-style warnings deliberately left to preserve
hand-written implementation rationale (plan-decision notes, race-condition
explanations).
2026-06-03 12:34:34 -04:00

63 lines
2.3 KiB
C#

using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.AdminUI.Hubs;
using ZB.MOM.WW.OtOpcUa.Commons.Messages.Drivers;
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests;
/// <summary>
/// Covers the in-process push contract the Blazor Server <c>DriverStatusPanel</c> relies on:
/// <see cref="IDriverStatusSnapshotStore.SnapshotChanged"/> fires on every
/// <see cref="IDriverStatusSnapshotStore.Upsert"/>, and <c>TryGet</c> returns the latest.
/// The panel subscribes to this store directly instead of opening a self-targeted SignalR
/// connection (which a server-side component can't reach behind a reverse proxy).
/// </summary>
public sealed class DriverStatusSnapshotStoreTests
{
private static DriverHealthChanged Snap(string instance, string state = "Healthy") =>
new("MAIN", instance, state, null, null, 0, new DateTime(2026, 5, 29, 0, 0, 0, DateTimeKind.Utc));
/// <summary>Verifies that Upsert raises SnapshotChanged with the stored snapshot.</summary>
[Fact]
public void Upsert_raises_SnapshotChanged_with_the_stored_snapshot()
{
var store = new InMemoryDriverStatusSnapshotStore();
var received = new List<DriverHealthChanged>();
store.SnapshotChanged += received.Add;
var snap = Snap("drv-1", "Faulted");
store.Upsert(snap);
received.Count.ShouldBe(1);
received[0].ShouldBeSameAs(snap);
}
/// <summary>Verifies that Upsert then TryGet returns the latest snapshot.</summary>
[Fact]
public void Upsert_then_TryGet_returns_the_latest_snapshot()
{
var store = new InMemoryDriverStatusSnapshotStore();
store.Upsert(Snap("drv-1", "Healthy"));
store.Upsert(Snap("drv-1", "Degraded"));
store.TryGet("drv-1", out var latest).ShouldBeTrue();
latest.State.ShouldBe("Degraded");
}
/// <summary>Verifies that an unsubscribed handler stops receiving events after removal.</summary>
[Fact]
public void Unsubscribed_handler_stops_receiving_after_removal()
{
var store = new InMemoryDriverStatusSnapshotStore();
var count = 0;
void Handler(DriverHealthChanged _) => count++;
store.SnapshotChanged += Handler;
store.Upsert(Snap("drv-1"));
store.SnapshotChanged -= Handler;
store.Upsert(Snap("drv-1"));
count.ShouldBe(1);
}
}