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.
174 lines
7.0 KiB
C#
174 lines
7.0 KiB
C#
using ZB.MOM.WW.ScadaBridge.CentralUI.Components.Shared;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Shared;
|
|
|
|
/// <summary>
|
|
/// Round-trip coverage for the WhileTrue/OnTrue <c>mode</c> field on the
|
|
/// Conditional and Expression script triggers.
|
|
/// </summary>
|
|
public class ScriptTriggerConfigCodecTests
|
|
{
|
|
// ── Parse: mode field ──────────────────────────────────────────────────
|
|
|
|
/// <summary>Verifies that parsing a conditional trigger without a mode defaults to on-true.</summary>
|
|
[Fact]
|
|
public void Parse_Conditional_WithoutMode_DefaultsToOnTrue()
|
|
{
|
|
const string json = @"{""attributeName"":""Temp"",""operator"":"">"",""threshold"":80}";
|
|
|
|
var model = ScriptTriggerConfigCodec.Parse(json, ScriptTriggerKind.Conditional);
|
|
|
|
Assert.Equal(ScriptTriggerMode.OnTrue, model.Mode);
|
|
}
|
|
|
|
/// <summary>Verifies that parsing a conditional trigger reads the while-true mode.</summary>
|
|
[Fact]
|
|
public void Parse_Conditional_WhileTrue_IsRead()
|
|
{
|
|
const string json =
|
|
@"{""attributeName"":""Temp"",""operator"":"">"",""threshold"":80,""mode"":""WhileTrue""}";
|
|
|
|
var model = ScriptTriggerConfigCodec.Parse(json, ScriptTriggerKind.Conditional);
|
|
|
|
Assert.Equal(ScriptTriggerMode.WhileTrue, model.Mode);
|
|
}
|
|
|
|
/// <summary>Verifies that parsing an expression trigger without a mode defaults to on-true.</summary>
|
|
[Fact]
|
|
public void Parse_Expression_WithoutMode_DefaultsToOnTrue()
|
|
{
|
|
const string json = @"{""expression"":""Attributes[\""T\""] > 1""}";
|
|
|
|
var model = ScriptTriggerConfigCodec.Parse(json, ScriptTriggerKind.Expression);
|
|
|
|
Assert.Equal(ScriptTriggerMode.OnTrue, model.Mode);
|
|
}
|
|
|
|
/// <summary>Verifies that parsing an expression trigger reads the while-true mode.</summary>
|
|
[Fact]
|
|
public void Parse_Expression_WhileTrue_IsRead()
|
|
{
|
|
const string json =
|
|
@"{""expression"":""Attributes[\""T\""] > 1"",""mode"":""WhileTrue""}";
|
|
|
|
var model = ScriptTriggerConfigCodec.Parse(json, ScriptTriggerKind.Expression);
|
|
|
|
Assert.Equal(ScriptTriggerMode.WhileTrue, model.Mode);
|
|
}
|
|
|
|
/// <summary>Verifies that parsing an unrecognized mode defaults to on-true.</summary>
|
|
[Fact]
|
|
public void Parse_UnrecognizedMode_DefaultsToOnTrue()
|
|
{
|
|
const string json =
|
|
@"{""attributeName"":""Temp"",""operator"":"">"",""threshold"":80,""mode"":""Sometimes""}";
|
|
|
|
var model = ScriptTriggerConfigCodec.Parse(json, ScriptTriggerKind.Conditional);
|
|
|
|
Assert.Equal(ScriptTriggerMode.OnTrue, model.Mode);
|
|
}
|
|
|
|
// ── Serialize: mode field ──────────────────────────────────────────────
|
|
|
|
/// <summary>Verifies that serializing a while-true conditional trigger writes the mode.</summary>
|
|
[Fact]
|
|
public void Serialize_Conditional_WhileTrue_WritesMode()
|
|
{
|
|
var model = new ScriptTriggerModel
|
|
{
|
|
AttributeName = "Temp",
|
|
Operator = ">",
|
|
Threshold = 80,
|
|
Mode = ScriptTriggerMode.WhileTrue
|
|
};
|
|
|
|
var json = ScriptTriggerConfigCodec.Serialize(model, ScriptTriggerKind.Conditional);
|
|
|
|
Assert.Contains("\"mode\":\"WhileTrue\"", json);
|
|
}
|
|
|
|
/// <summary>Verifies that serializing a while-true expression trigger writes the mode.</summary>
|
|
[Fact]
|
|
public void Serialize_Expression_WhileTrue_WritesMode()
|
|
{
|
|
var model = new ScriptTriggerModel
|
|
{
|
|
Expression = "Attributes[\"T\"] > 1",
|
|
Mode = ScriptTriggerMode.WhileTrue
|
|
};
|
|
|
|
var json = ScriptTriggerConfigCodec.Serialize(model, ScriptTriggerKind.Expression);
|
|
|
|
Assert.Contains("\"mode\":\"WhileTrue\"", json);
|
|
}
|
|
|
|
// ── Round-trip ─────────────────────────────────────────────────────────
|
|
|
|
/// <summary>Verifies that a conditional trigger's mode survives a serialize and parse round trip.</summary>
|
|
/// <param name="whileTrue">Whether the trigger uses the while-true mode.</param>
|
|
[Theory]
|
|
[InlineData(false)]
|
|
[InlineData(true)]
|
|
public void RoundTrip_Conditional_PreservesMode(bool whileTrue)
|
|
{
|
|
var mode = whileTrue ? ScriptTriggerMode.WhileTrue : ScriptTriggerMode.OnTrue;
|
|
var original = new ScriptTriggerModel
|
|
{
|
|
AttributeName = "Temp",
|
|
Operator = ">=",
|
|
Threshold = 12.5,
|
|
Mode = mode
|
|
};
|
|
|
|
var json = ScriptTriggerConfigCodec.Serialize(original, ScriptTriggerKind.Conditional);
|
|
var reparsed = ScriptTriggerConfigCodec.Parse(json, ScriptTriggerKind.Conditional);
|
|
|
|
Assert.Equal(mode, reparsed.Mode);
|
|
}
|
|
|
|
// ── SupportsMinTimeBetweenRuns ─────────────────────────────────────────
|
|
|
|
/// <summary>Verifies that automatic trigger types that throttle support a minimum time between runs.</summary>
|
|
/// <param name="triggerType">The trigger type under test.</param>
|
|
[Theory]
|
|
[InlineData("ValueChange")]
|
|
[InlineData("Conditional")]
|
|
[InlineData("Expression")]
|
|
public void SupportsMinTimeBetweenRuns_TrueForAutoTriggersThatThrottle(string triggerType)
|
|
{
|
|
Assert.True(ScriptTriggerConfigCodec.SupportsMinTimeBetweenRuns(triggerType));
|
|
}
|
|
|
|
/// <summary>Verifies that interval, call, none and unknown trigger types do not support a minimum time between runs.</summary>
|
|
/// <param name="triggerType">The trigger type under test, or null.</param>
|
|
[Theory]
|
|
[InlineData("Interval")] // has its own period control
|
|
[InlineData("Call")] // invoked explicitly — no throttle applies
|
|
[InlineData(null)] // None — never runs automatically
|
|
[InlineData("Bogus")] // Unknown trigger type
|
|
public void SupportsMinTimeBetweenRuns_FalseForIntervalCallNoneAndUnknown(string? triggerType)
|
|
{
|
|
Assert.False(ScriptTriggerConfigCodec.SupportsMinTimeBetweenRuns(triggerType));
|
|
}
|
|
|
|
/// <summary>Verifies that an expression trigger's mode survives a serialize and parse round trip.</summary>
|
|
/// <param name="whileTrue">Whether the trigger uses the while-true mode.</param>
|
|
[Theory]
|
|
[InlineData(false)]
|
|
[InlineData(true)]
|
|
public void RoundTrip_Expression_PreservesMode(bool whileTrue)
|
|
{
|
|
var mode = whileTrue ? ScriptTriggerMode.WhileTrue : ScriptTriggerMode.OnTrue;
|
|
var original = new ScriptTriggerModel
|
|
{
|
|
Expression = "Attributes[\"T\"] > 1",
|
|
Mode = mode
|
|
};
|
|
|
|
var json = ScriptTriggerConfigCodec.Serialize(original, ScriptTriggerKind.Expression);
|
|
var reparsed = ScriptTriggerConfigCodec.Parse(json, ScriptTriggerKind.Expression);
|
|
|
|
Assert.Equal(mode, reparsed.Mode);
|
|
}
|
|
}
|