Files
mxaccessgw/src/ZB.MOM.WW.MxGateway.Tests/TestSupport/RecordingDashboardEventBroadcaster.cs
T
Joseph Doherty d48099f0d0 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>
2026-05-24 03:20:40 -04:00

31 lines
1.3 KiB
C#

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);