Resolve Tests-025..026

Tests-025 (Conventions): Extracted the previously-duplicated
NullDashboardEventBroadcaster into TestSupport/NullDashboardEventBroadcaster.cs
(singleton Instance, private ctor). The two nested copies in
EventStreamServiceTests and GatewayEndToEndFakeWorkerSmokeTests were
removed; both files now use the shared type via
'using ZB.MOM.WW.MxGateway.Tests.TestSupport;'. The Server-041 regression
test's ThrowingDashboardEventBroadcaster is intentionally left nested —
single-file usage doesn't warrant promotion to TestSupport. The third
copy in IntegrationTests/WorkerLiveMxAccessSmokeTests was handled by
IntegrationTests-024 in its own commit.

Tests-026 (Testing coverage): Added a new RecordingDashboardEventBroadcaster
test double in TestSupport — a thread-safe (ConcurrentQueue<DashboardEventCapture>)
recorder. New fixture
StreamEventsAsync_PublishesEachEventToDashboardBroadcaster in
EventStreamServiceTests pushes two events through the fake session and
asserts the broadcaster received both with the correct sessionId and
WorkerSequence. TDD red→green confirmed: the deliberately-wrong
"Expected 3, Actual 2" red phase proved the recording fake was actually
invoked by the production code path.

Verification: 486/486 server tests passing (485 previous + 1 new).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Joseph Doherty
2026-05-24 03:20:40 -04:00
parent bd1d1f1c0e
commit d48099f0d0
4 changed files with 61 additions and 10 deletions
@@ -414,9 +414,4 @@ public sealed class GatewayEndToEndFakeWorkerSmokeTests
}
}
private sealed class NullDashboardEventBroadcaster : ZB.MOM.WW.MxGateway.Server.Dashboard.Hubs.IDashboardEventBroadcaster
{
public static readonly NullDashboardEventBroadcaster Instance = new();
public void Publish(string sessionId, ZB.MOM.WW.MxGateway.Contracts.Proto.MxEvent mxEvent) { }
}
}
@@ -0,0 +1,26 @@
using ZB.MOM.WW.MxGateway.Contracts.Proto;
using ZB.MOM.WW.MxGateway.Server.Dashboard.Hubs;
namespace ZB.MOM.WW.MxGateway.Tests.TestSupport;
/// <summary>
/// <see cref="IDashboardEventBroadcaster"/> that drops every event on the floor.
/// Used by tests that need to wire up <c>EventStreamService</c> but do not care
/// about the dashboard fan-out side-channel. The singleton <see cref="Instance"/>
/// mirrors the Tests-007 / Tests-021 shared-fake pattern under
/// <c>src/ZB.MOM.WW.MxGateway.Tests/TestSupport/</c>.
/// </summary>
public sealed class NullDashboardEventBroadcaster : IDashboardEventBroadcaster
{
/// <summary>Shared instance for tests that do not need to inspect broadcaster state.</summary>
public static readonly NullDashboardEventBroadcaster Instance = new();
private NullDashboardEventBroadcaster()
{
}
/// <inheritdoc />
public void Publish(string sessionId, MxEvent mxEvent)
{
}
}
@@ -0,0 +1,30 @@
using System.Collections.Concurrent;
using ZB.MOM.WW.MxGateway.Contracts.Proto;
using ZB.MOM.WW.MxGateway.Server.Dashboard.Hubs;
namespace ZB.MOM.WW.MxGateway.Tests.TestSupport;
/// <summary>
/// <see cref="IDashboardEventBroadcaster"/> test double that captures every
/// <c>Publish(sessionId, mxEvent)</c> call into a thread-safe list, so tests
/// can prove the gRPC producer loop actually mirrors events to the dashboard
/// fan-out seam. Tests-026.
/// </summary>
public sealed class RecordingDashboardEventBroadcaster : IDashboardEventBroadcaster
{
private readonly ConcurrentQueue<DashboardEventCapture> _captures = new();
/// <summary>Gets a snapshot of every <c>Publish</c> call in arrival order.</summary>
public IReadOnlyList<DashboardEventCapture> Captures => _captures.ToArray();
/// <inheritdoc />
public void Publish(string sessionId, MxEvent mxEvent)
{
_captures.Enqueue(new DashboardEventCapture(sessionId, mxEvent));
}
}
/// <summary>Captured <c>(sessionId, mxEvent)</c> pair from a Publish invocation.</summary>
/// <param name="SessionId">The session id passed to Publish.</param>
/// <param name="MxEvent">The MxEvent passed to Publish.</param>
public sealed record DashboardEventCapture(string SessionId, MxEvent MxEvent);