From 3172b7bdeed688ebaf50bd6ac6b28951f0c9318c Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Tue, 16 Jun 2026 21:22:43 -0400 Subject: [PATCH] test(opcua): cover null-arrayLength dimension + tighten scalar assertion (review) --- .../NodeManagerArrayTests.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests/NodeManagerArrayTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests/NodeManagerArrayTests.cs index fb03a669..2dfce4d1 100644 --- a/tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests/NodeManagerArrayTests.cs +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests/NodeManagerArrayTests.cs @@ -43,6 +43,26 @@ public sealed class NodeManagerArrayTests : IDisposable await host.DisposeAsync(); } + /// When arrayLength is null the created node must still be a 1-D array (ValueRank=OneDimension) + /// with ArrayDimensions [0] — the "unfixed-length" contract. + [Fact] + public async Task EnsureVariable_with_null_arrayLength_sets_dimension_zero() + { + var (host, server) = await BootAsync(); + var nm = server.NodeManager!; + + nm.EnsureVariable("eq-1/arr-unfixed", parentFolderNodeId: null, displayName: "arr-unfixed", dataType: "Int32", + writable: false, historianTagname: null, isArray: true, arrayLength: null); + + var variable = nm.TryGetVariable("eq-1/arr-unfixed"); + variable.ShouldNotBeNull(); + variable!.ValueRank.ShouldBe(ValueRanks.OneDimension); + variable.ArrayDimensions.ShouldNotBeNull(); + variable.ArrayDimensions.ShouldBe(new uint[] { 0u }); + + await host.DisposeAsync(); + } + /// A default (scalar) EnsureVariable call keeps ValueRank=Scalar and leaves /// ArrayDimensions null/empty. [Fact] @@ -57,7 +77,7 @@ public sealed class NodeManagerArrayTests : IDisposable var variable = nm.TryGetVariable("eq-1/scalar"); variable.ShouldNotBeNull(); variable!.ValueRank.ShouldBe(ValueRanks.Scalar); - (variable.ArrayDimensions is null || variable.ArrayDimensions.Count == 0).ShouldBeTrue(); + variable.ArrayDimensions.ShouldBeNull(); await host.DisposeAsync(); }