Files
ScadaBridge/tests/ZB.MOM.WW.ScadaBridge.Communication.Tests/Protos/PullAuditEventsProtoTests.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

87 lines
3.1 KiB
C#

using Google.Protobuf;
using Google.Protobuf.WellKnownTypes;
using ZB.MOM.WW.ScadaBridge.Communication.Grpc;
namespace ZB.MOM.WW.ScadaBridge.Communication.Tests.Protos;
/// <summary>
/// Wire-format round-trip tests for the Audit Log reconciliation
/// pull proto messages (<see cref="PullAuditEventsRequest"/>,
/// <see cref="PullAuditEventsResponse"/>). Locks the additive contract the
/// central→site reconciliation puller depends on.
/// </summary>
public class PullAuditEventsProtoTests
{
private static AuditEventDto NewAuditDto(Guid? id = null) => new()
{
EventId = (id ?? Guid.NewGuid()).ToString(),
OccurredAtUtc = Timestamp.FromDateTimeOffset(
new DateTimeOffset(2026, 5, 20, 10, 15, 30, 123, TimeSpan.Zero)),
Channel = "ApiOutbound",
Kind = "ApiCall",
Status = "Delivered",
SourceSiteId = "site-1",
};
/// <summary>Verifies that a <c>PullAuditEventsRequest</c> survives a serialize and parse round trip unchanged.</summary>
[Fact]
public void PullAuditEventsRequest_RoundTrip()
{
var sinceUtc = Timestamp.FromDateTimeOffset(
new DateTimeOffset(2026, 5, 20, 9, 0, 0, TimeSpan.Zero));
var original = new PullAuditEventsRequest
{
SinceUtc = sinceUtc,
BatchSize = 250,
};
var bytes = original.ToByteArray();
var deserialized = PullAuditEventsRequest.Parser.ParseFrom(bytes);
Assert.Equal(sinceUtc, deserialized.SinceUtc);
Assert.Equal(250, deserialized.BatchSize);
}
/// <summary>Verifies that a <c>PullAuditEventsResponse</c> with events and the more-available flag survives a round trip.</summary>
[Fact]
public void PullAuditEventsResponse_RoundTrip_WithEvents_And_MoreAvailable()
{
var dtos = Enumerable.Range(0, 4).Select(_ => NewAuditDto()).ToList();
var original = new PullAuditEventsResponse
{
MoreAvailable = true,
};
original.Events.AddRange(dtos);
var bytes = original.ToByteArray();
var deserialized = PullAuditEventsResponse.Parser.ParseFrom(bytes);
Assert.True(deserialized.MoreAvailable);
Assert.Equal(4, deserialized.Events.Count);
for (int i = 0; i < dtos.Count; i++)
{
Assert.Equal(dtos[i].EventId, deserialized.Events[i].EventId);
Assert.Equal(dtos[i].Status, deserialized.Events[i].Status);
Assert.Equal(dtos[i].SourceSiteId, deserialized.Events[i].SourceSiteId);
Assert.Equal(dtos[i].OccurredAtUtc, deserialized.Events[i].OccurredAtUtc);
}
}
/// <summary>Verifies that an empty <c>PullAuditEventsResponse</c> parses back with no events.</summary>
[Fact]
public void PullAuditEventsResponse_Empty_Yields_EmptyEvents()
{
var original = new PullAuditEventsResponse();
Assert.Empty(original.Events);
Assert.False(original.MoreAvailable);
var bytes = original.ToByteArray();
var deserialized = PullAuditEventsResponse.Parser.ParseFrom(bytes);
Assert.Empty(deserialized.Events);
Assert.False(deserialized.MoreAvailable);
}
}