Renames all 11 projects (5 src + 6 tests), the .slnx solution file, all source-file namespaces, all axaml namespace references, and all v1 documentation references in CLAUDE.md and docs/*.md (excluding docs/v2/ which is already in OtOpcUa form). Also updates the TopShelf service registration name from "LmxOpcUa" to "OtOpcUa" per Phase 0 Task 0.6.
Preserves runtime identifiers per Phase 0 Out-of-Scope rules to avoid breaking v1/v2 client trust during coexistence: OPC UA `ApplicationUri` defaults (`urn:{GalaxyName}:LmxOpcUa`), server `EndpointPath` (`/LmxOpcUa`), `ServerName` default (feeds cert subject CN), `MxAccessConfiguration.ClientName` default (defensive — stays "LmxOpcUa" for MxAccess audit-trail consistency), client OPC UA identifiers (`ApplicationName = "LmxOpcUaClient"`, `ApplicationUri = "urn:localhost:LmxOpcUaClient"`, cert directory `%LocalAppData%\LmxOpcUaClient\pki\`), and the `LmxOpcUaServer` class name (class rename out of Phase 0 scope per Task 0.5 sed pattern; happens in Phase 1 alongside `LmxNodeManager → GenericDriverNodeManager` Core extraction). 23 LmxOpcUa references retained, all enumerated and justified in `docs/v2/implementation/exit-gate-phase-0.md`.
Build clean: 0 errors, 30 warnings (lower than baseline 167). Tests at strict improvement over baseline: 821 passing / 1 failing vs baseline 820 / 2 (one flaky pre-existing failure passed this run; the other still fails — both pre-existing and unrelated to the rename). `Client.UI.Tests`, `Historian.Aveva.Tests`, `Client.Shared.Tests`, `IntegrationTests` all match baseline exactly. Exit gate compliance results recorded in `docs/v2/implementation/exit-gate-phase-0.md` with all 7 checks PASS or DEFERRED-to-PR-review (#7 service install verification needs Windows service permissions on the reviewer's box).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
203 lines
7.8 KiB
C#
203 lines
7.8 KiB
C#
using System.Collections.Concurrent;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Opc.Ua;
|
|
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Host.Domain;
|
|
using ZB.MOM.WW.OtOpcUa.Tests.Helpers;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Tests.Integration
|
|
{
|
|
/// <summary>
|
|
/// Verifies OPC UA indexed array writes against the bridge's whole-array runtime update behavior.
|
|
/// </summary>
|
|
public class ArrayWriteTests
|
|
{
|
|
/// <summary>
|
|
/// Confirms that writing a single array element updates the correct slot while preserving the rest of the array.
|
|
/// </summary>
|
|
[Fact]
|
|
public async Task Write_SingleArrayElement_UpdatesWholeArrayValue()
|
|
{
|
|
var fixture = OpcUaServerFixture.WithFakeMxAccessClient();
|
|
fixture.MxAccessClient!.TagValues["MESReceiver_001.MoveInPartNumbers[]"] = Vtq.Good(
|
|
Enumerable.Range(0, 50).Select(i => $"PART-{i:00}").ToArray());
|
|
|
|
await fixture.InitializeAsync();
|
|
try
|
|
{
|
|
using var client = new OpcUaTestClient();
|
|
await client.ConnectAsync(fixture.EndpointUrl);
|
|
|
|
// Browse path: TestMachine_001 -> MESReceiver -> MoveInPartNumbers
|
|
var nodeId = client.MakeNodeId("MESReceiver_001.MoveInPartNumbers");
|
|
|
|
var before = client.Read(nodeId).Value as string[];
|
|
before.ShouldNotBeNull();
|
|
before.Length.ShouldBe(50);
|
|
before[1].ShouldBe("PART-01");
|
|
|
|
var status = client.Write(nodeId, new[] { "UPDATED-PART" }, "1");
|
|
StatusCode.IsGood(status).ShouldBe(true);
|
|
|
|
var after = client.Read(nodeId).Value as string[];
|
|
after.ShouldNotBeNull();
|
|
after.Length.ShouldBe(50);
|
|
after[0].ShouldBe("PART-00");
|
|
after[1].ShouldBe("UPDATED-PART");
|
|
after[2].ShouldBe("PART-02");
|
|
}
|
|
finally
|
|
{
|
|
await fixture.DisposeAsync();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Confirms that array nodes use bracketless OPC UA node identifiers while still exposing one-dimensional array
|
|
/// metadata.
|
|
/// </summary>
|
|
[Fact]
|
|
public async Task ArrayNode_UsesBracketlessNodeId_AndPublishesArrayDimensions()
|
|
{
|
|
var fixture = OpcUaServerFixture.WithFakeMxAccessClient();
|
|
fixture.MxAccessClient!.TagValues["MESReceiver_001.MoveInPartNumbers[]"] = Vtq.Good(
|
|
Enumerable.Range(0, 50).Select(i => $"PART-{i:00}").ToArray());
|
|
|
|
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);
|
|
|
|
var valueRank = client.ReadAttribute(nodeId, Attributes.ValueRank).Value;
|
|
valueRank.ShouldBe(ValueRanks.OneDimension);
|
|
|
|
var dimensions = client.ReadAttribute(nodeId, Attributes.ArrayDimensions).Value as uint[];
|
|
dimensions.ShouldNotBeNull();
|
|
dimensions.ShouldBe(new uint[] { 50 });
|
|
}
|
|
finally
|
|
{
|
|
await fixture.DisposeAsync();
|
|
}
|
|
}
|
|
|
|
/// <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>
|
|
[Fact]
|
|
public async Task Write_SingleArrayElement_PublishesUpdatedArrayToSubscribers()
|
|
{
|
|
var fixture = OpcUaServerFixture.WithFakeMxAccessClient();
|
|
fixture.MxAccessClient!.TagValues["MESReceiver_001.MoveInPartNumbers[]"] = Vtq.Good(
|
|
Enumerable.Range(0, 50).Select(i => $"PART-{i:00}").ToArray());
|
|
|
|
await fixture.InitializeAsync();
|
|
try
|
|
{
|
|
using var client = new OpcUaTestClient();
|
|
await client.ConnectAsync(fixture.EndpointUrl);
|
|
|
|
var nodeId = client.MakeNodeId("MESReceiver_001.MoveInPartNumbers");
|
|
var notifications = new ConcurrentBag<MonitoredItemNotification>();
|
|
var (sub, item) = await client.SubscribeAsync(nodeId, 100);
|
|
item.Notification += (_, e) =>
|
|
{
|
|
if (e.NotificationValue is MonitoredItemNotification notification)
|
|
notifications.Add(notification);
|
|
};
|
|
|
|
await Task.Delay(500);
|
|
|
|
var status = client.Write(nodeId, new[] { "UPDATED-PART" }, "1");
|
|
StatusCode.IsGood(status).ShouldBe(true);
|
|
|
|
await Task.Delay(1000);
|
|
|
|
notifications.Any(n =>
|
|
n.Value.Value is string[] values &&
|
|
values.Length == 50 &&
|
|
values[0] == "PART-00" &&
|
|
values[1] == "UPDATED-PART" &&
|
|
values[2] == "PART-02").ShouldBe(true);
|
|
|
|
await sub.DeleteAsync(true);
|
|
}
|
|
finally
|
|
{
|
|
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" }, "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();
|
|
}
|
|
}
|
|
}
|
|
} |