refactor(opcua): FB-7 review nits — model-event SourceNode=Server, dataType guard, shape tests
Code-review follow-ups on the FB-7 surgical shape-write commit: - GeneralModelChangeEvent now sets SourceNode=Server + SourceName (Part 3 §8.7.4) so clients filtering events by SourceNode match it (report still uses source:null). - UpdateTagAttributes adds an explicit dataType null/empty guard (widened surface). - Tighten the ArrayLengthDiffers doc comment. - Add array→scalar transition test + null-arrayLength zero-default test (coverage symmetry). 275/275 OpcUaServer.Tests green.
This commit is contained in:
+48
@@ -112,6 +112,54 @@ public sealed class NodeManagerSurgicalShapeUpdateTests : IDisposable
|
||||
await host.DisposeAsync();
|
||||
}
|
||||
|
||||
/// <summary>The symmetric array → scalar flip: ValueRank drops back to Scalar, ArrayDimensions clears to
|
||||
/// null, and the (now wrong-shaped) array value is reset.</summary>
|
||||
[Fact]
|
||||
public async Task Array_to_scalar_flip_clears_dimensions_and_resets_value()
|
||||
{
|
||||
var (host, server) = await BootAsync();
|
||||
var nm = server.NodeManager!;
|
||||
|
||||
nm.EnsureVariable("eq-1/buf", parentFolderNodeId: null, displayName: "Buf", dataType: "Int16",
|
||||
writable: false, historianTagname: null, isArray: true, arrayLength: 4u);
|
||||
nm.WriteValue("eq-1/buf", new short[] { 1, 2, 3, 4 }, OpcUaQuality.Good, DateTime.UtcNow);
|
||||
var node = nm.TryGetVariable("eq-1/buf")!;
|
||||
node.ValueRank.ShouldBe(ValueRanks.OneDimension); // arrange guard
|
||||
|
||||
var applied = nm.UpdateTagAttributes("eq-1/buf", writable: false, historianTagname: null,
|
||||
dataType: "Int16", isArray: false, arrayLength: null);
|
||||
|
||||
applied.ShouldBeTrue();
|
||||
node.ValueRank.ShouldBe(ValueRanks.Scalar);
|
||||
node.ArrayDimensions.ShouldBeNull();
|
||||
node.Value.ShouldBeNull();
|
||||
node.StatusCode.ShouldBe((StatusCode)StatusCodes.BadWaitingForInitialData);
|
||||
|
||||
await host.DisposeAsync();
|
||||
}
|
||||
|
||||
/// <summary>A scalar → array flip with a null arrayLength defaults ArrayDimensions to [0] — mirroring
|
||||
/// <see cref="OtOpcUaNodeManager.EnsureVariable"/>'s fresh-node default for an unspecified length.</summary>
|
||||
[Fact]
|
||||
public async Task Array_flip_with_null_length_defaults_dimension_to_zero()
|
||||
{
|
||||
var (host, server) = await BootAsync();
|
||||
var nm = server.NodeManager!;
|
||||
|
||||
nm.EnsureVariable("eq-1/buf", parentFolderNodeId: null, displayName: "Buf", dataType: "Int16", writable: false);
|
||||
var node = nm.TryGetVariable("eq-1/buf")!;
|
||||
|
||||
var applied = nm.UpdateTagAttributes("eq-1/buf", writable: false, historianTagname: null,
|
||||
dataType: "Int16", isArray: true, arrayLength: null);
|
||||
|
||||
applied.ShouldBeTrue();
|
||||
node.ValueRank.ShouldBe(ValueRanks.OneDimension);
|
||||
node.ArrayDimensions.ShouldNotBeNull();
|
||||
node.ArrayDimensions[0].ShouldBe(0u); // null length ⇒ [0], same as EnsureVariable
|
||||
|
||||
await host.DisposeAsync();
|
||||
}
|
||||
|
||||
// ───────────────────────────── Backward compatibility (shape unchanged) ─────────────────────────────
|
||||
|
||||
/// <summary>A Writable-only change (DataType + array-ness identical to the live node) must NOT reset the
|
||||
|
||||
Reference in New Issue
Block a user