Publish default values for null static arrays

This commit is contained in:
Joseph Doherty
2026-03-25 14:12:37 -04:00
parent ed42b33512
commit bb0a89b2a1
2 changed files with 118 additions and 4 deletions

View File

@@ -90,6 +90,37 @@ namespace ZB.MOM.WW.LmxOpcUa.Tests.Integration
}
}
/// <summary>
/// Confirms that a null runtime value for a statically sized array is exposed as a typed fixed-length array.
/// </summary>
[Fact]
public async Task Read_NullStaticArray_ReturnsDefaultTypedArray()
{
var fixture = OpcUaServerFixture.WithFakeMxAccessClient();
fixture.MxAccessClient!.TagValues["MESReceiver_001.MoveInPartNumbers[]"] = Vtq.Good(null);
await fixture.InitializeAsync();
try
{
using var client = new OpcUaTestClient();
await client.ConnectAsync(fixture.EndpointUrl);
var nodeId = client.MakeNodeId("MESReceiver_001.MoveInPartNumbers");
var value = client.Read(nodeId).Value as string[];
value.ShouldNotBeNull();
value.Length.ShouldBe(50);
value.ShouldAllBe(v => v == string.Empty);
var dimensions = client.ReadAttribute(nodeId, Attributes.ArrayDimensions).Value as uint[];
dimensions.ShouldBe(new uint[] { 50 });
}
finally
{
await fixture.DisposeAsync();
}
}
/// <summary>
/// Confirms that an indexed write also updates the published OPC UA value seen by subscribed clients.
/// </summary>
@@ -136,5 +167,37 @@ namespace ZB.MOM.WW.LmxOpcUa.Tests.Integration
await fixture.DisposeAsync();
}
}
/// <summary>
/// Confirms that indexed writes succeed even when the current runtime array value is null.
/// </summary>
[Fact]
public async Task Write_SingleArrayElement_WhenCurrentArrayIsNull_UsesDefaultArray()
{
var fixture = OpcUaServerFixture.WithFakeMxAccessClient();
fixture.MxAccessClient!.TagValues["MESReceiver_001.MoveInPartNumbers[]"] = Vtq.Good(null);
await fixture.InitializeAsync();
try
{
using var client = new OpcUaTestClient();
await client.ConnectAsync(fixture.EndpointUrl);
var nodeId = client.MakeNodeId("MESReceiver_001.MoveInPartNumbers");
var status = client.Write(nodeId, new[] { "UPDATED-PART" }, indexRange: "1");
StatusCode.IsGood(status).ShouldBe(true);
var after = client.Read(nodeId).Value as string[];
after.ShouldNotBeNull();
after.Length.ShouldBe(50);
after[0].ShouldBe(string.Empty);
after[1].ShouldBe("UPDATED-PART");
after[2].ShouldBe(string.Empty);
}
finally
{
await fixture.DisposeAsync();
}
}
}
}