using ZB.MOM.WW.ScadaBridge.SiteRuntime.Scripts;
namespace ZB.MOM.WW.ScadaBridge.SiteRuntime.Tests.Scripts;
///
/// SRT-7 (WP6 6.2): an Expression trigger is routed by the literal attribute keys it reads,
/// and falls back to all-changes whenever those keys cannot be pinned down.
///
public class TriggerExpressionKeysTests
{
/// Literal root and child reads are extracted as canonical keys.
[Theory]
[InlineData("(double)Attributes[\"Temp\"] > 50", new[] { "Temp" })]
[InlineData("(double)Attributes[\"A\"] > (double)Attributes[\"B\"] && Attributes[\"A\"] != null", new[] { "A", "B" })]
[InlineData("(double)Children[\"Pump1\"].Attributes[\"Speed\"] > 10", new[] { "Pump1.Speed" })]
[InlineData("Attributes[\"Mode\"] as string == \"Auto\" || (bool)Children[\"V\"].Attributes[\"Open\"]", new[] { "Mode", "V.Open" })]
public void LiteralReads_AreExtracted(string expression, string[] expected)
{
Assert.True(TriggerExpressionKeys.TryExtract(expression, out var keys));
Assert.Equal(expected, keys);
}
/// Anything that is not a recognised literal read falls back to all-changes.
[Theory]
[InlineData("true")] // no attribute read (may depend on the clock)
[InlineData("DateTime.UtcNow.Second == 0")]
[InlineData("Attributes[\"A\" + \"B\"] != null")] // non-literal key
[InlineData("Attributes[name] != null")]
[InlineData("Parent != null")]
[InlineData("Children[\"P\"].Attributes[k] != null")] // non-literal child key
[InlineData("Children[c].Attributes[\"S\"] != null")] // non-literal child name
[InlineData("((Func