Files
ScadaBridge/tests/ZB.MOM.WW.ScadaBridge.HealthMonitoring.Tests/Kpi/CentralHealthAuditBacklogProviderTests.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

111 lines
4.4 KiB
C#

using ZB.MOM.WW.ScadaBridge.Commons.Messages.Health;
using ZB.MOM.WW.ScadaBridge.Commons.Types;
using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
using ZB.MOM.WW.ScadaBridge.HealthMonitoring.Kpi;
namespace ZB.MOM.WW.ScadaBridge.HealthMonitoring.Tests.Kpi;
/// <summary>
/// Coverage for <see cref="CentralHealthAuditBacklogProvider"/>.
/// The provider sums the latest per-site <c>SiteAuditBacklog.PendingCount</c> across the
/// in-memory <see cref="ICentralHealthAggregator"/> — the same aggregate the live Audit
/// backlog tile shows — so the <c>backlogTotal</c> KPI history stops recording a hardwired
/// zero. Sites with no report or a null backlog snapshot contribute nothing.
/// </summary>
public class CentralHealthAuditBacklogProviderTests
{
private static readonly DateTime At = new(2026, 6, 17, 12, 0, 0, DateTimeKind.Utc);
/// <summary>Verifies that the pending backlog total sums the pending count across all sites.</summary>
/// <returns>The result.</returns>
[Fact]
public void GetPendingBacklogTotal_Sums_PendingCount_Across_Sites()
{
var aggregator = new StubAggregator
{
States =
{
["site-a"] = StateWithBacklog("site-a", 9),
["site-b"] = StateWithBacklog("site-b", 4),
["site-c"] = new SiteHealthState { SiteId = "site-c", LatestReport = null }, // heartbeat-only
},
};
var provider = new CentralHealthAuditBacklogProvider(aggregator);
// 9 + 4; the null-report site contributes nothing.
Assert.Equal(13, provider.GetPendingBacklogTotal());
}
/// <summary>Verifies that the pending backlog total is zero when no site has reported a backlog.</summary>
/// <returns>The result.</returns>
[Fact]
public void GetPendingBacklogTotal_Returns_Zero_When_No_Backlog_Reported()
{
var aggregator = new StubAggregator
{
States =
{
["site-a"] = new SiteHealthState { SiteId = "site-a", LatestReport = MinimalReport("site-a") with { SiteAuditBacklog = null } },
["site-b"] = new SiteHealthState { SiteId = "site-b", LatestReport = null },
},
};
var provider = new CentralHealthAuditBacklogProvider(aggregator);
Assert.Equal(0, provider.GetPendingBacklogTotal());
}
private static SiteHealthState StateWithBacklog(string siteId, int pending) =>
new()
{
SiteId = siteId,
LatestReport = MinimalReport(siteId) with
{
SiteAuditBacklog = new SiteAuditBacklogSnapshot(
PendingCount: pending, OldestPendingUtc: null, OnDiskBytes: 0),
},
};
private static SiteHealthReport MinimalReport(string siteId) =>
new(
SiteId: siteId,
SequenceNumber: 1,
ReportTimestamp: At,
DataConnectionStatuses: new Dictionary<string, ConnectionHealth>(),
TagResolutionCounts: new Dictionary<string, TagResolutionStatus>(),
ScriptErrorCount: 0,
AlarmEvaluationErrorCount: 0,
StoreAndForwardBufferDepths: new Dictionary<string, int>(),
DeadLetterCount: 0,
DeployedInstanceCount: 0,
EnabledInstanceCount: 0,
DisabledInstanceCount: 0);
/// <summary>
/// Hand-rolled <see cref="ICentralHealthAggregator"/> stub — the HealthMonitoring.Tests
/// project has no mocking library. Only <see cref="GetAllSiteStates"/> is exercised.
/// </summary>
private sealed class StubAggregator : ICentralHealthAggregator
{
/// <summary>Gets the site health states served by the fake.</summary>
public Dictionary<string, SiteHealthState> States { get; } = new();
/// <inheritdoc />
public IReadOnlyDictionary<string, SiteHealthState> GetAllSiteStates() => States;
/// <inheritdoc />
public SiteHealthState? GetSiteState(string siteId) =>
States.TryGetValue(siteId, out var state) ? state : null;
/// <inheritdoc />
public void ProcessReport(SiteHealthReport report) => throw new NotSupportedException();
/// <inheritdoc />
public void MarkHeartbeat(string siteId, DateTimeOffset receivedAt) => throw new NotSupportedException();
/// <inheritdoc />
public void PruneUnknownSites(IReadOnlyCollection<string> knownSiteIds) => throw new NotSupportedException();
}
}