Files
ScadaBridge/tests/ZB.MOM.WW.ScadaBridge.SiteEventLogging.Tests/EventLogHandlerActorTests.cs
T
Joseph Doherty 513fa1aa16 docs(tests): fix CommentChecker findings across tests/ — 13,392 → 0 (repo-wide scan clean)
Comment/XML-doc changes only:
- add summaries to ~10k test methods, fixtures, fakes and helpers
  (+ <param> on theories, <returns> on async Task methods,
  <inheritdoc/> on interface implementations the checker can resolve)
- strip ~2.6k project-tracking references (WP*, P*-*, row-NN, Task N,
  #NN, Component-0NN) from comments, keeping the explanatory text;
  reword false positives in comments only
- real docs on fakes implementing BCL/library interfaces
  (IDisposable, ILogger, IOptionsMonitor, IAsyncLifetime)
- reword the last 5 src/ false positives (CWE-1236, failures-1,
  year-0001, M365)

Only non-comment edits: four one-line nested classes split across lines
so members can carry docs. Build 0 errors / 0 warnings.
2026-10-07 15:05:49 -04:00

88 lines
3.3 KiB
C#

using Akka.Actor;
using Akka.TestKit.Xunit2;
using ZB.MOM.WW.ScadaBridge.Commons.Messages.RemoteQuery;
namespace ZB.MOM.WW.ScadaBridge.SiteEventLogging.Tests;
/// <summary>
/// Regression tests for the actor message contract of
/// <see cref="EventLogHandlerActor"/> was previously untested.
/// </summary>
public class EventLogHandlerActorTests : TestKit
{
/// <summary>Test double returning a canned response and recording the request.</summary>
private sealed class FakeQueryService : IEventLogQueryService
{
private readonly Func<EventLogQueryRequest, EventLogQueryResponse> _handler;
/// <summary>Gets the most recent query request received.</summary>
public EventLogQueryRequest? LastRequest { get; private set; }
/// <summary>Initializes the fake with a handler that produces query responses.</summary>
/// <param name="handler">The function that answers each query request.</param>
public FakeQueryService(Func<EventLogQueryRequest, EventLogQueryResponse> handler)
=> _handler = handler;
/// <inheritdoc />
public EventLogQueryResponse ExecuteQuery(EventLogQueryRequest request)
{
LastRequest = request;
return _handler(request);
}
}
private static EventLogQueryRequest MakeRequest(string correlationId) => new(
CorrelationId: correlationId,
SiteId: "site-1",
From: null,
To: null,
EventType: null,
Severity: null,
InstanceId: null,
KeywordFilter: null,
ContinuationToken: null,
PageSize: 500,
Timestamp: DateTimeOffset.UtcNow);
private static EventLogQueryResponse MakeResponse(EventLogQueryRequest req, bool success = true) => new(
CorrelationId: req.CorrelationId,
SiteId: req.SiteId,
Entries: [],
ContinuationToken: null,
HasMore: false,
Success: success,
ErrorMessage: success ? null : "boom",
Timestamp: DateTimeOffset.UtcNow);
/// <summary>Verifies that the actor replies to the sender with the query response.</summary>
[Fact]
public void Actor_RepliesToSender_WithQueryResponse()
{
var fake = new FakeQueryService(req => MakeResponse(req));
var actor = Sys.ActorOf(Props.Create(() => new EventLogHandlerActor(fake)));
var request = MakeRequest("corr-1");
actor.Tell(request, TestActor);
var response = ExpectMsg<EventLogQueryResponse>();
Assert.Equal("corr-1", response.CorrelationId);
Assert.Equal("site-1", response.SiteId);
Assert.True(response.Success);
Assert.Same(request, fake.LastRequest);
}
/// <summary>Verifies that the actor passes a query-service error response on to the sender.</summary>
[Fact]
public void Actor_PropagatesQueryServiceErrorResponse_ToSender()
{
var fake = new FakeQueryService(req => MakeResponse(req, success: false));
var actor = Sys.ActorOf(Props.Create(() => new EventLogHandlerActor(fake)));
actor.Tell(MakeRequest("corr-2"), TestActor);
var response = ExpectMsg<EventLogQueryResponse>();
Assert.False(response.Success);
Assert.Equal("corr-2", response.CorrelationId);
Assert.Equal("boom", response.ErrorMessage);
}
}