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; /// /// P5-5 (arch-review Low): is the /// boot-time guardrail for the "rate-fold interval triple" — /// , /// , and /// . The sample sources now rescale /// their Rate-classified samples onto SampleInterval, 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. /// 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); } [Fact] public void AllThreeEqual_AtDocumentedDefaults_IsValid() { var result = Validate( new KpiHistoryOptions(), new NotificationOutboxOptions(), new SiteCallAuditOptions()); Assert.True(result.Succeeded, result.FailureMessage); } [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); } [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); } [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); } [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); } }