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.
124 lines
5.5 KiB
C#
124 lines
5.5 KiB
C#
using ZB.MOM.WW.ScadaBridge.Commons.Types.Alarms;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
|
|
using ZB.MOM.WW.ScadaBridge.DataConnectionLayer;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.DataConnectionLayer.Tests;
|
|
|
|
/// <summary>
|
|
/// The alarm conditionFilter is a comma-separated, case-insensitive
|
|
/// list of condition type names. Blank = allow all. These tests pin the
|
|
/// parse-once / IsAllowed predicate that the DataConnectionActor uses as the
|
|
/// authoritative client-side gate.
|
|
/// </summary>
|
|
public class AlarmConditionFilterTests
|
|
{
|
|
private static NativeAlarmTransition Tx(string typeName,
|
|
AlarmTransitionKind kind = AlarmTransitionKind.Raise) =>
|
|
new("ref", "obj", typeName, kind,
|
|
new AlarmConditionState(true, false, null, AlarmShelveState.Unshelved, false, 500),
|
|
"cat", "desc", "msg", "", "", null, DateTimeOffset.UtcNow, "1", "0");
|
|
|
|
/// <summary>Verifies that a null or blank filter is empty and allows every condition type.</summary>
|
|
/// <param name="filter">The condition filter text under test.</param>
|
|
[Theory]
|
|
[InlineData(null)]
|
|
[InlineData("")]
|
|
[InlineData(" ")]
|
|
[InlineData(",")]
|
|
[InlineData(" , , ")]
|
|
public void NullOrBlankFilter_IsEmpty_AllowsEverything(string? filter)
|
|
{
|
|
var f = AlarmConditionFilter.Parse(filter);
|
|
Assert.True(f.IsEmpty);
|
|
Assert.True(f.IsAllowed(Tx("AnalogLimit.Hi")));
|
|
Assert.True(f.IsAllowed(Tx("anything-at-all")));
|
|
}
|
|
|
|
/// <summary>Verifies that parsing splits a comma-separated list into individual names.</summary>
|
|
[Fact]
|
|
public void Parse_SplitsCommaSeparatedList()
|
|
{
|
|
var f = AlarmConditionFilter.Parse("AnalogLimit.Hi,DiscreteAlarm,AnalogLimit.Lo");
|
|
Assert.False(f.IsEmpty);
|
|
Assert.True(f.IsAllowed(Tx("AnalogLimit.Hi")));
|
|
Assert.True(f.IsAllowed(Tx("DiscreteAlarm")));
|
|
Assert.True(f.IsAllowed(Tx("AnalogLimit.Lo")));
|
|
Assert.False(f.IsAllowed(Tx("AnalogLimit.HiHi")));
|
|
}
|
|
|
|
/// <summary>Verifies that the allowed check ignores letter casing.</summary>
|
|
[Fact]
|
|
public void IsAllowed_IsCaseInsensitive()
|
|
{
|
|
var f = AlarmConditionFilter.Parse("AnalogLimit.Hi");
|
|
Assert.True(f.IsAllowed(Tx("analoglimit.hi")));
|
|
Assert.True(f.IsAllowed(Tx("ANALOGLIMIT.HI")));
|
|
Assert.False(f.IsAllowed(Tx("DiscreteAlarm")));
|
|
}
|
|
|
|
/// <summary>Verifies that parsing trims whitespace around each name.</summary>
|
|
[Fact]
|
|
public void Parse_TrimsWhitespaceAroundEachName()
|
|
{
|
|
var f = AlarmConditionFilter.Parse(" AnalogLimit.Hi ,\tDiscreteAlarm ");
|
|
Assert.True(f.IsAllowed(Tx("AnalogLimit.Hi")));
|
|
Assert.True(f.IsAllowed(Tx("DiscreteAlarm")));
|
|
}
|
|
|
|
/// <summary>Verifies that parsing drops empty entries and keeps the non-empty ones.</summary>
|
|
[Fact]
|
|
public void Parse_DropsEmptyEntries_KeepsNonEmpty()
|
|
{
|
|
var f = AlarmConditionFilter.Parse("AnalogLimit.Hi,, ,DiscreteAlarm");
|
|
Assert.False(f.IsEmpty);
|
|
Assert.True(f.IsAllowed(Tx("AnalogLimit.Hi")));
|
|
Assert.True(f.IsAllowed(Tx("DiscreteAlarm")));
|
|
Assert.False(f.IsAllowed(Tx("")));
|
|
}
|
|
|
|
/// <summary>Verifies that the snapshot-complete framing sentinel is never filtered out.</summary>
|
|
[Fact]
|
|
public void IsAllowed_NeverDropsSnapshotCompleteFramingSentinel()
|
|
{
|
|
// SnapshotComplete is a pure framing sentinel (empty AlarmTypeName) that
|
|
// drives the NativeAlarmActor's atomic snapshot swap. A type filter must
|
|
// never swallow it or the snapshot replay never completes.
|
|
var f = AlarmConditionFilter.Parse("AnalogLimit.Hi");
|
|
Assert.True(f.IsAllowed(Tx("", AlarmTransitionKind.SnapshotComplete)));
|
|
}
|
|
|
|
/// <summary>Verifies that replayed snapshot conditions are filtered by condition type.</summary>
|
|
[Fact]
|
|
public void IsAllowed_FiltersReplayedSnapshotConditionsByType()
|
|
{
|
|
// Snapshot-kind transitions carry real conditions and ARE filtered.
|
|
var f = AlarmConditionFilter.Parse("AnalogLimit.Hi");
|
|
Assert.True(f.IsAllowed(Tx("AnalogLimit.Hi", AlarmTransitionKind.Snapshot)));
|
|
Assert.False(f.IsAllowed(Tx("DiscreteAlarm", AlarmTransitionKind.Snapshot)));
|
|
}
|
|
|
|
/// <summary>Verifies that the names property exposes the normalized set for server-side optimization.</summary>
|
|
[Fact]
|
|
public void Names_ExposesNormalizedSet_ForServerSideOptimization()
|
|
{
|
|
var f = AlarmConditionFilter.Parse(" AnalogLimit.Hi , DiscreteAlarm ");
|
|
Assert.Equal(new[] { "AnalogLimit.Hi", "DiscreteAlarm" }, f.Names.OrderBy(n => n).ToArray());
|
|
Assert.Empty(AlarmConditionFilter.Parse(null).Names);
|
|
}
|
|
|
|
/// <summary>Verifies that an OPC UA event whose type name resolves to a friendly name matches a filter on that friendly name.</summary>
|
|
[Fact]
|
|
public void IsAllowed_OpcUaResolvedFriendlyName_MatchesFriendlyNameFilter()
|
|
{
|
|
// Regression: OPC UA delivers events whose AlarmTypeName, after
|
|
// RealOpcUaClient.ResolveAlarmTypeName, is a standard friendly type name
|
|
// (e.g. "ExclusiveLevelAlarmType"). A friendly-name filter on that source
|
|
// built a correct server WhereClause; the client gate must agree and deliver,
|
|
// not drop every event (which the prior NodeId-string AlarmTypeName caused).
|
|
var f = AlarmConditionFilter.Parse("ExclusiveLevelAlarmType,DiscreteAlarmType");
|
|
Assert.True(f.IsAllowed(Tx("ExclusiveLevelAlarmType")));
|
|
Assert.True(f.IsAllowed(Tx("DiscreteAlarmType")));
|
|
Assert.False(f.IsAllowed(Tx("OffNormalAlarmType")));
|
|
}
|
|
}
|