test(server): cover GatewayConfigPathRules, DashboardRedactor, EventSubscriberReplayAttachment

This commit is contained in:
Joseph Doherty
2026-10-22 08:25:11 -04:00
parent dd3ea056b0
commit 908cf7ccca
3 changed files with 236 additions and 0 deletions
@@ -0,0 +1,63 @@
using System.Threading.Channels;
using ZB.MOM.WW.MxGateway.Contracts.Proto;
using ZB.MOM.WW.MxGateway.Server.Sessions;
namespace ZB.MOM.WW.MxGateway.Tests.Sessions;
/// <summary>Tests for the <see cref="EventSubscriberReplayAttachment"/> value shape.</summary>
public sealed class EventSubscriberReplayAttachmentTests
{
/// <summary>Verifies the constructor exposes every component unchanged.</summary>
[Fact]
public void Constructor_ExposesComponents()
{
StubLease lease = new();
MxEvent[] replay = [new MxEvent { WorkerSequence = 5 }, new MxEvent { WorkerSequence = 6 }];
EventSubscriberReplayAttachment attachment = new(lease, replay, true, 5, 6);
Assert.Same(lease, attachment.Lease);
Assert.Same(replay, attachment.ReplayedEvents);
Assert.True(attachment.Gap);
Assert.Equal(5UL, attachment.OldestAvailableSequence);
Assert.Equal(6UL, attachment.LiveResumeSequence);
}
/// <summary>Verifies value equality holds for identical components and breaks when a watermark differs.</summary>
[Fact]
public void Equality_ComparesComponents()
{
StubLease lease = new();
IReadOnlyList<MxEvent> replay = [];
EventSubscriberReplayAttachment a = new(lease, replay, false, 0, 10);
EventSubscriberReplayAttachment same = new(lease, replay, false, 0, 10);
EventSubscriberReplayAttachment other = a with { LiveResumeSequence = 11 };
Assert.Equal(a, same);
Assert.NotEqual(a, other);
}
/// <summary>Verifies disposing the lease through the attachment releases the subscriber.</summary>
[Fact]
public void Lease_DisposeIsObservableThroughAttachment()
{
StubLease lease = new();
EventSubscriberReplayAttachment attachment = new(lease, [], false, 0, 0);
attachment.Lease.Dispose();
Assert.True(lease.Disposed);
}
private sealed class StubLease : IEventSubscriberLease
{
private readonly Channel<MxEvent> channel = Channel.CreateUnbounded<MxEvent>();
public bool Disposed { get; private set; }
public ChannelReader<MxEvent> Reader => channel.Reader;
public void Dispose() => Disposed = true;
}
}