513fa1aa16
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.
98 lines
4.5 KiB
C#
98 lines
4.5 KiB
C#
using Microsoft.Extensions.Options;
|
|
using ZB.MOM.WW.ScadaBridge.KpiHistory;
|
|
using ZB.MOM.WW.ScadaBridge.NotificationOutbox;
|
|
using ZB.MOM.WW.ScadaBridge.SiteCallAudit;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.Host.Tests;
|
|
|
|
/// <summary>
|
|
/// <see cref="KpiRateFoldIntervalCrossValidator"/> is the
|
|
/// boot-time guardrail for the "rate-fold interval triple" —
|
|
/// <see cref="KpiHistoryOptions.SampleInterval"/>,
|
|
/// <see cref="NotificationOutboxOptions.DeliveredKpiWindow"/>, and
|
|
/// <see cref="SiteCallAuditOptions.KpiInterval"/>. The sample sources now rescale
|
|
/// their Rate-classified samples onto <c>SampleInterval</c>, so the hourly rollup
|
|
/// fold's correctness no longer depends on this equality — but the
|
|
/// recorded/charted sample no longer equals the live dashboard tile unless it
|
|
/// holds, so this validator still fails the host at boot on any divergence,
|
|
/// naming all three configuration keys.
|
|
/// </summary>
|
|
public class KpiRateFoldIntervalCrossValidatorTests
|
|
{
|
|
private static ValidateOptionsResult Validate(
|
|
KpiHistoryOptions kpiHistoryOptions,
|
|
NotificationOutboxOptions notificationOutboxOptions,
|
|
SiteCallAuditOptions siteCallAuditOptions)
|
|
{
|
|
var validator = new KpiRateFoldIntervalCrossValidator(
|
|
Options.Create(notificationOutboxOptions),
|
|
Options.Create(siteCallAuditOptions));
|
|
return validator.Validate(Options.DefaultName, kpiHistoryOptions);
|
|
}
|
|
|
|
/// <summary>Verifies that the validator accepts all three values being equal at the documented defaults.</summary>
|
|
[Fact]
|
|
public void AllThreeEqual_AtDocumentedDefaults_IsValid()
|
|
{
|
|
var result = Validate(
|
|
new KpiHistoryOptions(), new NotificationOutboxOptions(), new SiteCallAuditOptions());
|
|
|
|
Assert.True(result.Succeeded, result.FailureMessage);
|
|
}
|
|
|
|
/// <summary>Verifies that the validator accepts all three values being equal at a common non-default value.</summary>
|
|
[Fact]
|
|
public void AllThreeEqual_AtANonDefaultCommonValue_IsValid()
|
|
{
|
|
var common = TimeSpan.FromMinutes(5);
|
|
var result = Validate(
|
|
new KpiHistoryOptions { SampleInterval = common },
|
|
new NotificationOutboxOptions { DeliveredKpiWindow = common },
|
|
new SiteCallAuditOptions { KpiInterval = common });
|
|
|
|
Assert.True(result.Succeeded, result.FailureMessage);
|
|
}
|
|
|
|
/// <summary>Verifies that the validator fails and names all three keys when the delivered KPI window diverges.</summary>
|
|
[Fact]
|
|
public void DeliveredKpiWindowDiverges_FailsAndNamesAllThreeKeys()
|
|
{
|
|
var result = Validate(
|
|
new KpiHistoryOptions { SampleInterval = TimeSpan.FromMinutes(1) },
|
|
new NotificationOutboxOptions { DeliveredKpiWindow = TimeSpan.FromMinutes(15) },
|
|
new SiteCallAuditOptions { KpiInterval = TimeSpan.FromMinutes(1) });
|
|
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("ScadaBridge:KpiHistory:SampleInterval", result.FailureMessage);
|
|
Assert.Contains("ScadaBridge:NotificationOutbox:DeliveredKpiWindow", result.FailureMessage);
|
|
Assert.Contains("ScadaBridge:SiteCallAudit:KpiInterval", result.FailureMessage);
|
|
}
|
|
|
|
/// <summary>Verifies that the validator fails and names all three keys when the KPI interval diverges.</summary>
|
|
[Fact]
|
|
public void KpiIntervalDiverges_FailsAndNamesAllThreeKeys()
|
|
{
|
|
var result = Validate(
|
|
new KpiHistoryOptions { SampleInterval = TimeSpan.FromMinutes(1) },
|
|
new NotificationOutboxOptions { DeliveredKpiWindow = TimeSpan.FromMinutes(1) },
|
|
new SiteCallAuditOptions { KpiInterval = TimeSpan.FromMinutes(20) });
|
|
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("ScadaBridge:KpiHistory:SampleInterval", result.FailureMessage);
|
|
Assert.Contains("ScadaBridge:NotificationOutbox:DeliveredKpiWindow", result.FailureMessage);
|
|
Assert.Contains("ScadaBridge:SiteCallAudit:KpiInterval", result.FailureMessage);
|
|
}
|
|
|
|
/// <summary>Verifies that the validator fails when both the delivered KPI window and the KPI interval diverge.</summary>
|
|
[Fact]
|
|
public void BothDeliveredKpiWindowAndKpiIntervalDiverge_Fails()
|
|
{
|
|
var result = Validate(
|
|
new KpiHistoryOptions { SampleInterval = TimeSpan.FromMinutes(1) },
|
|
new NotificationOutboxOptions { DeliveredKpiWindow = TimeSpan.FromMinutes(15) },
|
|
new SiteCallAuditOptions { KpiInterval = TimeSpan.FromMinutes(20) });
|
|
|
|
Assert.True(result.Failed);
|
|
}
|
|
}
|