Files
ScadaBridge/tests/ZB.MOM.WW.ScadaBridge.SiteRuntime.Tests/Scripts/ScriptRunEventPolicyTests.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

93 lines
3.6 KiB
C#

using ZB.MOM.WW.ScadaBridge.SiteRuntime.Scripts;
namespace ZB.MOM.WW.ScadaBridge.SiteRuntime.Tests.Scripts;
/// <summary>
/// Site-events volume policy (docs/plans/2026-08-15-site-events-policy-design.md):
/// pure unit tests for
/// <see cref="ScriptRunEventPolicy.ShouldEmitPerRun"/>, isolated from any actor or DI
/// plumbing — the actor-level wiring (hot toggle, hosted-service registration) is covered by
/// <c>ScriptRunLauncherParityTests</c>.
/// </summary>
public class ScriptRunEventPolicyTests
{
private static SiteRuntimeOptions Options(
bool perRunScriptEvents = false, string[]? perRunScriptEventScripts = null)
=> new()
{
PerRunScriptEvents = perRunScriptEvents,
PerRunScriptEventScripts = (perRunScriptEventScripts ?? []).ToList()
};
/// <summary>Verifies that the default options emit no per-run events.</summary>
[Fact]
public void DefaultOptions_EmitsNothing()
{
Assert.False(ScriptRunEventPolicy.ShouldEmitPerRun(Options(), "Inst1", "Runner"));
}
/// <summary>Verifies that turning the global switch on emits for every script.</summary>
[Fact]
public void GlobalSwitchOn_EmitsForEveryScript()
{
var options = Options(perRunScriptEvents: true);
Assert.True(ScriptRunEventPolicy.ShouldEmitPerRun(options, "Inst1", "Runner"));
Assert.True(ScriptRunEventPolicy.ShouldEmitPerRun(options, "AnyOtherInstance", "AnyOtherScript"));
}
/// <summary>Verifies that an exact per-script match emits.</summary>
[Fact]
public void ExactPerScriptMatch_Emits()
{
var options = Options(perRunScriptEventScripts: ["Inst1/Runner"]);
Assert.True(ScriptRunEventPolicy.ShouldEmitPerRun(options, "Inst1", "Runner"));
}
/// <summary>Verifies that an exact per-script match does not match a different script on the same instance.</summary>
[Fact]
public void ExactPerScriptMatch_DoesNotMatchADifferentScriptOnTheSameInstance()
{
var options = Options(perRunScriptEventScripts: ["Inst1/Runner"]);
Assert.False(ScriptRunEventPolicy.ShouldEmitPerRun(options, "Inst1", "OtherScript"));
}
/// <summary>Verifies that an exact per-script match does not match the same script name on a different instance.</summary>
[Fact]
public void ExactPerScriptMatch_DoesNotMatchTheSameScriptNameOnADifferentInstance()
{
var options = Options(perRunScriptEventScripts: ["Inst1/Runner"]);
Assert.False(ScriptRunEventPolicy.ShouldEmitPerRun(options, "Inst2", "Runner"));
}
/// <summary>Verifies that an instance wildcard emits for every script on that instance only.</summary>
[Fact]
public void InstanceWildcard_EmitsForEveryScriptOnThatInstanceOnly()
{
var options = Options(perRunScriptEventScripts: ["Inst1/*"]);
Assert.True(ScriptRunEventPolicy.ShouldEmitPerRun(options, "Inst1", "Runner"));
Assert.True(ScriptRunEventPolicy.ShouldEmitPerRun(options, "Inst1", "AnotherScript"));
Assert.False(ScriptRunEventPolicy.ShouldEmitPerRun(options, "Inst2", "Runner"));
}
/// <summary>Verifies that a script that does not match the opt-in list stays silent.</summary>
[Fact]
public void NonMatchingScript_StaysSilent()
{
var options = Options(perRunScriptEventScripts: ["Inst1/Runner", "Inst2/*"]);
Assert.False(ScriptRunEventPolicy.ShouldEmitPerRun(options, "Inst3", "Runner"));
}
/// <summary>Verifies that an empty opt-in list stays silent.</summary>
[Fact]
public void EmptyOptInList_StaysSilent()
{
Assert.False(ScriptRunEventPolicy.ShouldEmitPerRun(Options(), "Inst1", "Runner"));
}
}