Implement LmxOpcUa server — all 6 phases complete
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>
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.LmxOpcUa.Host.Domain;
|
||||
|
||||
namespace ZB.MOM.WW.LmxOpcUa.Tests.Domain
|
||||
{
|
||||
public class MxDataTypeMapperTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(1, 1u)] // Boolean
|
||||
[InlineData(2, 6u)] // Integer → Int32
|
||||
[InlineData(3, 10u)] // Float
|
||||
[InlineData(4, 11u)] // Double
|
||||
[InlineData(5, 12u)] // String
|
||||
[InlineData(6, 13u)] // DateTime
|
||||
[InlineData(7, 11u)] // ElapsedTime → Double
|
||||
[InlineData(8, 12u)] // Reference → String
|
||||
[InlineData(13, 6u)] // Enumeration → Int32
|
||||
[InlineData(14, 12u)] // Custom → String
|
||||
[InlineData(15, 21u)] // InternationalizedString → LocalizedText
|
||||
[InlineData(16, 12u)] // Custom → String
|
||||
public void MapToOpcUaDataType_AllKnownTypes(int mxDataType, uint expectedNodeId)
|
||||
{
|
||||
MxDataTypeMapper.MapToOpcUaDataType(mxDataType).ShouldBe(expectedNodeId);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(99)]
|
||||
[InlineData(-1)]
|
||||
public void MapToOpcUaDataType_UnknownDefaultsToString(int mxDataType)
|
||||
{
|
||||
MxDataTypeMapper.MapToOpcUaDataType(mxDataType).ShouldBe(12u); // String
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1, typeof(bool))]
|
||||
[InlineData(2, typeof(int))]
|
||||
[InlineData(3, typeof(float))]
|
||||
[InlineData(4, typeof(double))]
|
||||
[InlineData(5, typeof(string))]
|
||||
[InlineData(6, typeof(DateTime))]
|
||||
[InlineData(7, typeof(double))]
|
||||
[InlineData(8, typeof(string))]
|
||||
[InlineData(13, typeof(int))]
|
||||
[InlineData(15, typeof(string))]
|
||||
public void MapToClrType_AllKnownTypes(int mxDataType, Type expectedType)
|
||||
{
|
||||
MxDataTypeMapper.MapToClrType(mxDataType).ShouldBe(expectedType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MapToClrType_UnknownDefaultsToString()
|
||||
{
|
||||
MxDataTypeMapper.MapToClrType(999).ShouldBe(typeof(string));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetOpcUaTypeName_Boolean()
|
||||
{
|
||||
MxDataTypeMapper.GetOpcUaTypeName(1).ShouldBe("Boolean");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetOpcUaTypeName_Unknown_ReturnsString()
|
||||
{
|
||||
MxDataTypeMapper.GetOpcUaTypeName(999).ShouldBe("String");
|
||||
}
|
||||
}
|
||||
}
|
||||
46
tests/ZB.MOM.WW.LmxOpcUa.Tests/Domain/MxErrorCodesTests.cs
Normal file
46
tests/ZB.MOM.WW.LmxOpcUa.Tests/Domain/MxErrorCodesTests.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.LmxOpcUa.Host.Domain;
|
||||
|
||||
namespace ZB.MOM.WW.LmxOpcUa.Tests.Domain
|
||||
{
|
||||
public class MxErrorCodesTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(1008, "Invalid reference")]
|
||||
[InlineData(1012, "Wrong data type")]
|
||||
[InlineData(1013, "Not writable")]
|
||||
[InlineData(1014, "Request timed out")]
|
||||
[InlineData(1015, "Communication failure")]
|
||||
[InlineData(1016, "Not connected")]
|
||||
public void GetMessage_KnownCodes_ContainsDescription(int code, string expectedSubstring)
|
||||
{
|
||||
MxErrorCodes.GetMessage(code).ShouldContain(expectedSubstring);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetMessage_UnknownCode_ReturnsUnknown()
|
||||
{
|
||||
MxErrorCodes.GetMessage(9999).ShouldContain("Unknown");
|
||||
MxErrorCodes.GetMessage(9999).ShouldContain("9999");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1008, Quality.BadConfigError)]
|
||||
[InlineData(1012, Quality.BadConfigError)]
|
||||
[InlineData(1013, Quality.BadOutOfService)]
|
||||
[InlineData(1014, Quality.BadCommFailure)]
|
||||
[InlineData(1015, Quality.BadCommFailure)]
|
||||
[InlineData(1016, Quality.BadNotConnected)]
|
||||
public void MapToQuality_KnownCodes(int code, Quality expected)
|
||||
{
|
||||
MxErrorCodes.MapToQuality(code).ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MapToQuality_UnknownCode_ReturnsBad()
|
||||
{
|
||||
MxErrorCodes.MapToQuality(9999).ShouldBe(Quality.Bad);
|
||||
}
|
||||
}
|
||||
}
|
||||
101
tests/ZB.MOM.WW.LmxOpcUa.Tests/Domain/QualityMapperTests.cs
Normal file
101
tests/ZB.MOM.WW.LmxOpcUa.Tests/Domain/QualityMapperTests.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.LmxOpcUa.Host.Domain;
|
||||
|
||||
namespace ZB.MOM.WW.LmxOpcUa.Tests.Domain
|
||||
{
|
||||
public class QualityMapperTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(0, Quality.Bad)]
|
||||
[InlineData(4, Quality.BadConfigError)]
|
||||
[InlineData(20, Quality.BadCommFailure)]
|
||||
[InlineData(32, Quality.BadWaitingForInitialData)]
|
||||
public void MapFromMxAccess_BadFamily(int input, Quality expected)
|
||||
{
|
||||
QualityMapper.MapFromMxAccessQuality(input).ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(64, Quality.Uncertain)]
|
||||
[InlineData(68, Quality.UncertainLastUsable)]
|
||||
[InlineData(88, Quality.UncertainSubNormal)]
|
||||
public void MapFromMxAccess_UncertainFamily(int input, Quality expected)
|
||||
{
|
||||
QualityMapper.MapFromMxAccessQuality(input).ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(192, Quality.Good)]
|
||||
[InlineData(216, Quality.GoodLocalOverride)]
|
||||
public void MapFromMxAccess_GoodFamily(int input, Quality expected)
|
||||
{
|
||||
QualityMapper.MapFromMxAccessQuality(input).ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MapFromMxAccess_UnknownBadValue_ReturnsBad()
|
||||
{
|
||||
QualityMapper.MapFromMxAccessQuality(63).ShouldBe(Quality.Bad);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MapFromMxAccess_UnknownUncertainValue_ReturnsUncertain()
|
||||
{
|
||||
QualityMapper.MapFromMxAccessQuality(100).ShouldBe(Quality.Uncertain);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MapFromMxAccess_UnknownGoodValue_ReturnsGood()
|
||||
{
|
||||
QualityMapper.MapFromMxAccessQuality(200).ShouldBe(Quality.Good);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MapToOpcUa_Good_Returns0()
|
||||
{
|
||||
QualityMapper.MapToOpcUaStatusCode(Quality.Good).ShouldBe(0x00000000u);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MapToOpcUa_Bad_Returns80000000()
|
||||
{
|
||||
QualityMapper.MapToOpcUaStatusCode(Quality.Bad).ShouldBe(0x80000000u);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MapToOpcUa_BadCommFailure()
|
||||
{
|
||||
QualityMapper.MapToOpcUaStatusCode(Quality.BadCommFailure).ShouldBe(0x80050000u);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MapToOpcUa_Uncertain()
|
||||
{
|
||||
QualityMapper.MapToOpcUaStatusCode(Quality.Uncertain).ShouldBe(0x40000000u);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void QualityExtensions_IsGood()
|
||||
{
|
||||
Quality.Good.IsGood().ShouldBe(true);
|
||||
Quality.Good.IsBad().ShouldBe(false);
|
||||
Quality.Good.IsUncertain().ShouldBe(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void QualityExtensions_IsBad()
|
||||
{
|
||||
Quality.Bad.IsBad().ShouldBe(true);
|
||||
Quality.Bad.IsGood().ShouldBe(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void QualityExtensions_IsUncertain()
|
||||
{
|
||||
Quality.Uncertain.IsUncertain().ShouldBe(true);
|
||||
Quality.Uncertain.IsGood().ShouldBe(false);
|
||||
Quality.Uncertain.IsBad().ShouldBe(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user