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

42 lines
2.2 KiB
C#

using Grpc.Core;
using ZB.MOM.WW.ScadaBridge.Communication.Grpc;
namespace ZB.MOM.WW.ScadaBridge.Communication.Tests.Grpc;
public class AuditWireBudgetTests
{
/// <summary>Verifies that a row over the soft budget travels alone in its batch without being truncated.</summary>
[Fact]
public void OversizeSoftBudgetRow_TravelsAloneWithoutTruncation()
{
var batch = new AuditEventBatch();
var bytes = AuditWireBudget.InitialBytes;
var row = new AuditEventDto { EventId = "large", ErrorDetail = new string('x', GrpcMessageLimits.AuditBatchBytes + 1) };
Assert.True(AuditWireBudget.TryAppend(batch.Events, row, ref bytes, row.EventId));
Assert.False(AuditWireBudget.TryAppend(batch.Events, new AuditEventDto { EventId = "next" }, ref bytes, "next"));
Assert.Same(row, Assert.Single(batch.Events));
Assert.Equal(row.ErrorDetail, batch.Events[0].ErrorDetail);
Assert.True(bytes < GrpcMessageLimits.MaxMessageBytes);
}
/// <summary>Verifies that a hard-oversize row does not block the rows before it and fails explicitly when it is first in a batch.</summary>
[Fact]
public void HardOversizeRow_DoesNotBlockGoodPrefix_AndFailsExplicitlyWhenFirst()
{
var good = new AuditEventDto { EventId = "good", ErrorMessage = "small" };
var huge = new AuditEventDto { EventId = "retained-id", ErrorDetail = new string('x', GrpcMessageLimits.MaxMessageBytes) };
var batch = new AuditEventBatch();
var bytes = AuditWireBudget.InitialBytes;
Assert.True(AuditWireBudget.TryAppend(batch.Events, good, ref bytes, good.EventId));
Assert.False(AuditWireBudget.TryAppend(batch.Events, huge, ref bytes, huge.EventId));
Assert.Equal("good", Assert.Single(batch.Events).EventId);
var next = new AuditEventBatch();
bytes = AuditWireBudget.InitialBytes;
var ex = Assert.Throws<RpcException>(() => AuditWireBudget.TryAppend(next.Events, huge, ref bytes, huge.EventId));
Assert.Equal(StatusCode.ResourceExhausted, ex.StatusCode);
Assert.Contains("retained-id", ex.Status.Detail);
Assert.Contains("retained locally", ex.Status.Detail);
Assert.Empty(next.Events);
}
}