test(opcua): applier forwards array params + overflow rows + doc fix (review)
Extends RecordingSink to capture isArray/arrayLength per EnsureVariable call, adds two applier-level tests asserting the wire-through for array and scalar plans, adds float/overflow InlineData rows to ExtractTagArray theory, and corrects the ExtractTagArray XML-doc wording (null => unbounded ArrayDimensions=[0]).
This commit is contained in:
@@ -551,7 +551,8 @@ public static class Phase7Composer
|
||||
/// <summary>Parses the optional array intent from a tag's <c>TagConfig</c> JSON: the <c>isArray</c>
|
||||
/// bool (absent / not a bool / non-object root / blank / malformed ⇒ <c>false</c>) and the optional
|
||||
/// <c>arrayLength</c> uint. The length is honoured ONLY when <c>isArray</c> is true AND the prop is a
|
||||
/// JSON number that fits <c>uint</c> (else <c>null</c> ⇒ unbounded, resolved later). Mirrors
|
||||
/// JSON number that fits <c>uint</c> (else <c>null</c> ⇒ unbounded 1-D array,
|
||||
/// <c>ArrayDimensions=[0]</c> at materialisation). Mirrors
|
||||
/// <see cref="ExtractTagHistorize"/> exactly in structure + null/blank/non-object/malformed-JSON
|
||||
/// tolerance. Never throws. The artifact-decode side
|
||||
/// (<c>DeploymentArtifact.ExtractTagArray</c>) MUST parse identically (byte-parity).</summary>
|
||||
|
||||
@@ -39,6 +39,10 @@ public class ExtractTagArrayTests
|
||||
[InlineData("{\"isArray\":true,\"arrayLength\":\"16\"}", true, null)]
|
||||
// Negative arrayLength does not fit uint ⇒ length null, flag still honoured.
|
||||
[InlineData("{\"isArray\":true,\"arrayLength\":-1}", true, null)]
|
||||
// Float arrayLength (16.5) is not an exact uint ⇒ TryGetUInt32 rejects it ⇒ length null.
|
||||
[InlineData("{\"isArray\":true,\"arrayLength\":16.5}", true, null)]
|
||||
// Overflow arrayLength (uint.MaxValue + 1 = 4294967296) does not fit uint ⇒ length null.
|
||||
[InlineData("{\"isArray\":true,\"arrayLength\":4294967296}", true, null)]
|
||||
public void ExtractTagArray_parses_or_returns_defaults(string? cfg, bool expectedIsArray, uint? expectedLength)
|
||||
{
|
||||
var (isArray, arrayLength) = Phase7Composer.ExtractTagArray(cfg);
|
||||
|
||||
@@ -323,6 +323,61 @@ public sealed class Phase7ApplierTests
|
||||
call.HistorianTagname.ShouldBe("40001");
|
||||
}
|
||||
|
||||
/// <summary>Array-support Task 2 — an <see cref="EquipmentTagPlan"/> with <c>IsArray: true,
|
||||
/// ArrayLength: 16</c> flowing through <see cref="Phase7Applier.MaterialiseEquipmentTags"/> must
|
||||
/// forward BOTH flags verbatim to the sink's <c>EnsureVariable</c>. Guards against arg-order swaps or
|
||||
/// accidental drops in the wire-through.</summary>
|
||||
[Fact]
|
||||
public void MaterialiseEquipmentTags_array_plan_forwards_isArray_and_arrayLength_to_sink()
|
||||
{
|
||||
var sink = new RecordingSink();
|
||||
var applier = new Phase7Applier(sink, NullLogger<Phase7Applier>.Instance);
|
||||
|
||||
var composition = new Phase7CompositionResult(
|
||||
Array.Empty<EquipmentNode>(), Array.Empty<DriverInstancePlan>(), Array.Empty<ScriptedAlarmPlan>())
|
||||
{
|
||||
EquipmentTags = new[]
|
||||
{
|
||||
new EquipmentTagPlan("tag-arr", "eq-1", "drv", FolderPath: "", Name: "Buffer", DataType: "Int16",
|
||||
FullName: "40001", Writable: false, Alarm: null, IsArray: true, ArrayLength: 16u),
|
||||
},
|
||||
};
|
||||
|
||||
applier.MaterialiseEquipmentTags(composition);
|
||||
|
||||
var call = sink.ArrayCalls.ShouldHaveSingleItem();
|
||||
call.NodeId.ShouldBe(EquipmentNodeIds.Variable("eq-1", "", "Buffer"));
|
||||
call.IsArray.ShouldBeTrue();
|
||||
call.ArrayLength.ShouldBe(16u);
|
||||
}
|
||||
|
||||
/// <summary>Array-support Task 2 — a scalar <see cref="EquipmentTagPlan"/> (<c>IsArray: false</c>,
|
||||
/// <c>ArrayLength: null</c>) must pass <c>isArray == false</c> through to the sink. Guards against a
|
||||
/// default flip that would silently materialise scalar tags as 1-D arrays.</summary>
|
||||
[Fact]
|
||||
public void MaterialiseEquipmentTags_scalar_plan_forwards_isArray_false_to_sink()
|
||||
{
|
||||
var sink = new RecordingSink();
|
||||
var applier = new Phase7Applier(sink, NullLogger<Phase7Applier>.Instance);
|
||||
|
||||
var composition = new Phase7CompositionResult(
|
||||
Array.Empty<EquipmentNode>(), Array.Empty<DriverInstancePlan>(), Array.Empty<ScriptedAlarmPlan>())
|
||||
{
|
||||
EquipmentTags = new[]
|
||||
{
|
||||
new EquipmentTagPlan("tag-scalar", "eq-1", "drv", FolderPath: "", Name: "Speed", DataType: "Float",
|
||||
FullName: "40002", Writable: false, Alarm: null, IsArray: false, ArrayLength: null),
|
||||
},
|
||||
};
|
||||
|
||||
applier.MaterialiseEquipmentTags(composition);
|
||||
|
||||
var call = sink.ArrayCalls.ShouldHaveSingleItem();
|
||||
call.NodeId.ShouldBe(EquipmentNodeIds.Variable("eq-1", "", "Speed"));
|
||||
call.IsArray.ShouldBeFalse();
|
||||
call.ArrayLength.ShouldBeNull();
|
||||
}
|
||||
|
||||
/// <summary>Verifies MaterialiseEquipmentVirtualTags creates one Variable per VirtualTag directly
|
||||
/// under its existing equipment folder, with a folder-scoped NodeId (EquipmentId/Name — NOT the
|
||||
/// VirtualTagId or Expression), parent == EquipmentId, displayName == Name, and does NOT re-create
|
||||
@@ -719,6 +774,9 @@ public sealed class Phase7ApplierTests
|
||||
/// <summary>Gets the queue of the historian-tagname arg captured per <c>EnsureVariable</c> call,
|
||||
/// keyed by NodeId (null ⇒ that call passed not-historized).</summary>
|
||||
public ConcurrentQueue<(string NodeId, string? HistorianTagname)> HistorianQueue { get; } = new();
|
||||
/// <summary>Gets the queue of the isArray/arrayLength args captured per <c>EnsureVariable</c>
|
||||
/// call, keyed by NodeId.</summary>
|
||||
public ConcurrentQueue<(string NodeId, bool IsArray, uint? ArrayLength)> ArrayQueue { get; } = new();
|
||||
/// <summary>Gets the queue of alarm-condition materialise calls.</summary>
|
||||
public ConcurrentQueue<(string AlarmNodeId, string EquipmentNodeId, string DisplayName, string AlarmType, int Severity, bool IsNative)> AlarmConditionQueue { get; } = new();
|
||||
/// <summary>Gets the number of rebuild calls made on this sink.</summary>
|
||||
@@ -732,6 +790,8 @@ public sealed class Phase7ApplierTests
|
||||
public List<(string NodeId, string? Parent, string DisplayName, string DataType, bool Writable)> VariableCalls => VariableQueue.ToList();
|
||||
/// <summary>Gets the list of recorded (NodeId, historian-tagname) pairs captured per EnsureVariable call.</summary>
|
||||
public List<(string NodeId, string? HistorianTagname)> HistorianCalls => HistorianQueue.ToList();
|
||||
/// <summary>Gets the list of recorded (NodeId, isArray, arrayLength) triples captured per EnsureVariable call.</summary>
|
||||
public List<(string NodeId, bool IsArray, uint? ArrayLength)> ArrayCalls => ArrayQueue.ToList();
|
||||
/// <summary>Gets the list of recorded alarm-condition materialise calls.</summary>
|
||||
public List<(string AlarmNodeId, string EquipmentNodeId, string DisplayName, string AlarmType, int Severity, bool IsNative)> AlarmConditionCalls => AlarmConditionQueue.ToList();
|
||||
|
||||
@@ -772,6 +832,7 @@ public sealed class Phase7ApplierTests
|
||||
{
|
||||
VariableQueue.Enqueue((variableNodeId, parentFolderNodeId, displayName, dataType, writable));
|
||||
HistorianQueue.Enqueue((variableNodeId, historianTagname));
|
||||
ArrayQueue.Enqueue((variableNodeId, isArray, arrayLength));
|
||||
}
|
||||
/// <summary>Records a rebuild address space call.</summary>
|
||||
public void RebuildAddressSpace() => Interlocked.Increment(ref RebuildCalls);
|
||||
|
||||
Reference in New Issue
Block a user