Full OPC UA server on .NET Framework 4.8 (x86) exposing AVEVA System Platform Galaxy tags via MXAccess. Mirrors Galaxy object hierarchy as OPC UA address space, translating contained-name browse paths to tag-name runtime references. Components implemented: - Configuration: AppConfiguration with 4 sections, validator - Domain: ConnectionState, Quality, Vtq, MxDataTypeMapper, error codes - MxAccess: StaComThread, MxAccessClient (partial classes), MxProxyAdapter using strongly-typed ArchestrA.MxAccess COM interop - Galaxy Repository: SQL queries (hierarchy, attributes, change detection), ChangeDetectionService with auto-rebuild on deploy - OPC UA Server: LmxNodeManager (CustomNodeManager2), LmxOpcUaServer, OpcUaServerHost with programmatic config, SecurityPolicy None - Status Dashboard: HTTP server with HTML/JSON/health endpoints - Integration: Full 14-step startup, graceful shutdown, component wiring 175 tests (174 unit + 1 integration), all passing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
110 lines
5.9 KiB
C#
110 lines
5.9 KiB
C#
using System.Collections.Generic;
|
|
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.LmxOpcUa.Host.Domain;
|
|
using ZB.MOM.WW.LmxOpcUa.Host.OpcUa;
|
|
|
|
namespace ZB.MOM.WW.LmxOpcUa.Tests.OpcUa
|
|
{
|
|
public class LmxNodeManagerBuildTests
|
|
{
|
|
private static (List<GalaxyObjectInfo> hierarchy, List<GalaxyAttributeInfo> attributes) CreateTestData()
|
|
{
|
|
var hierarchy = new List<GalaxyObjectInfo>
|
|
{
|
|
new GalaxyObjectInfo { GobjectId = 1, TagName = "DEV", ContainedName = "DEV", BrowseName = "DEV", ParentGobjectId = 0, IsArea = true },
|
|
new GalaxyObjectInfo { GobjectId = 2, TagName = "TestArea", ContainedName = "TestArea", BrowseName = "TestArea", ParentGobjectId = 1, IsArea = true },
|
|
new GalaxyObjectInfo { GobjectId = 3, TagName = "TestMachine_001", ContainedName = "TestMachine_001", BrowseName = "TestMachine_001", ParentGobjectId = 2, IsArea = false },
|
|
new GalaxyObjectInfo { GobjectId = 4, TagName = "DelmiaReceiver_001", ContainedName = "DelmiaReceiver", BrowseName = "DelmiaReceiver", ParentGobjectId = 3, IsArea = false },
|
|
};
|
|
|
|
var attributes = new List<GalaxyAttributeInfo>
|
|
{
|
|
new GalaxyAttributeInfo { GobjectId = 3, TagName = "TestMachine_001", AttributeName = "MachineID", FullTagReference = "TestMachine_001.MachineID", MxDataType = 5, IsArray = false },
|
|
new GalaxyAttributeInfo { GobjectId = 4, TagName = "DelmiaReceiver_001", AttributeName = "DownloadPath", FullTagReference = "DelmiaReceiver_001.DownloadPath", MxDataType = 5, IsArray = false },
|
|
new GalaxyAttributeInfo { GobjectId = 4, TagName = "DelmiaReceiver_001", AttributeName = "JobStepNumber", FullTagReference = "DelmiaReceiver_001.JobStepNumber", MxDataType = 2, IsArray = false },
|
|
new GalaxyAttributeInfo { GobjectId = 3, TagName = "TestMachine_001", AttributeName = "BatchItems", FullTagReference = "TestMachine_001.BatchItems[]", MxDataType = 5, IsArray = true, ArrayDimension = 50 },
|
|
};
|
|
|
|
return (hierarchy, attributes);
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildAddressSpace_CreatesCorrectNodeCounts()
|
|
{
|
|
var (hierarchy, attributes) = CreateTestData();
|
|
var model = AddressSpaceBuilder.Build(hierarchy, attributes);
|
|
|
|
model.ObjectCount.ShouldBe(2); // TestMachine_001, DelmiaReceiver
|
|
model.VariableCount.ShouldBe(4); // MachineID, DownloadPath, JobStepNumber, BatchItems
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildAddressSpace_TagReferencesPopulated()
|
|
{
|
|
var (hierarchy, attributes) = CreateTestData();
|
|
var model = AddressSpaceBuilder.Build(hierarchy, attributes);
|
|
|
|
model.NodeIdToTagReference.ContainsKey("TestMachine_001.MachineID").ShouldBe(true);
|
|
model.NodeIdToTagReference.ContainsKey("DelmiaReceiver_001.DownloadPath").ShouldBe(true);
|
|
model.NodeIdToTagReference.ContainsKey("DelmiaReceiver_001.JobStepNumber").ShouldBe(true);
|
|
model.NodeIdToTagReference.ContainsKey("TestMachine_001.BatchItems[]").ShouldBe(true);
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildAddressSpace_ArrayVariable_HasCorrectInfo()
|
|
{
|
|
var (hierarchy, attributes) = CreateTestData();
|
|
var model = AddressSpaceBuilder.Build(hierarchy, attributes);
|
|
|
|
model.NodeIdToTagReference.ContainsKey("TestMachine_001.BatchItems[]").ShouldBe(true);
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildAddressSpace_Areas_AreNotCountedAsObjects()
|
|
{
|
|
var hierarchy = new List<GalaxyObjectInfo>
|
|
{
|
|
new GalaxyObjectInfo { GobjectId = 1, TagName = "Area1", BrowseName = "Area1", ParentGobjectId = 0, IsArea = true },
|
|
new GalaxyObjectInfo { GobjectId = 2, TagName = "Obj1", BrowseName = "Obj1", ParentGobjectId = 1, IsArea = false }
|
|
};
|
|
|
|
var model = AddressSpaceBuilder.Build(hierarchy, new List<GalaxyAttributeInfo>());
|
|
model.ObjectCount.ShouldBe(1); // Only Obj1, not Area1
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildAddressSpace_RootNodes_AreTopLevel()
|
|
{
|
|
var hierarchy = new List<GalaxyObjectInfo>
|
|
{
|
|
new GalaxyObjectInfo { GobjectId = 1, TagName = "Root1", BrowseName = "Root1", ParentGobjectId = 0, IsArea = true },
|
|
new GalaxyObjectInfo { GobjectId = 2, TagName = "Child1", BrowseName = "Child1", ParentGobjectId = 1, IsArea = false }
|
|
};
|
|
|
|
var model = AddressSpaceBuilder.Build(hierarchy, new List<GalaxyAttributeInfo>());
|
|
model.RootNodes.Count.ShouldBe(1); // Only Root1 is a root
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildAddressSpace_DataTypeMappings()
|
|
{
|
|
var hierarchy = new List<GalaxyObjectInfo>
|
|
{
|
|
new GalaxyObjectInfo { GobjectId = 1, TagName = "Obj", BrowseName = "Obj", ParentGobjectId = 0, IsArea = false }
|
|
};
|
|
var attributes = new List<GalaxyAttributeInfo>
|
|
{
|
|
new GalaxyAttributeInfo { GobjectId = 1, TagName = "Obj", AttributeName = "BoolAttr", FullTagReference = "Obj.BoolAttr", MxDataType = 1, IsArray = false },
|
|
new GalaxyAttributeInfo { GobjectId = 1, TagName = "Obj", AttributeName = "IntAttr", FullTagReference = "Obj.IntAttr", MxDataType = 2, IsArray = false },
|
|
new GalaxyAttributeInfo { GobjectId = 1, TagName = "Obj", AttributeName = "FloatAttr", FullTagReference = "Obj.FloatAttr", MxDataType = 3, IsArray = false },
|
|
new GalaxyAttributeInfo { GobjectId = 1, TagName = "Obj", AttributeName = "StrAttr", FullTagReference = "Obj.StrAttr", MxDataType = 5, IsArray = false },
|
|
};
|
|
|
|
var model = AddressSpaceBuilder.Build(hierarchy, attributes);
|
|
model.VariableCount.ShouldBe(4);
|
|
model.NodeIdToTagReference.Count.ShouldBe(4);
|
|
}
|
|
}
|
|
}
|