Files
lmxopcua/tests/ZB.MOM.WW.LmxOpcUa.Tests/Wiring/ServiceStartupSequenceTest.cs
Joseph Doherty a7576ffb38 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>
2026-03-25 05:55:27 -04:00

74 lines
2.7 KiB
C#

using System.Collections.Generic;
using Shouldly;
using Xunit;
using ZB.MOM.WW.LmxOpcUa.Host;
using ZB.MOM.WW.LmxOpcUa.Host.Configuration;
using ZB.MOM.WW.LmxOpcUa.Host.Domain;
using ZB.MOM.WW.LmxOpcUa.Tests.Helpers;
namespace ZB.MOM.WW.LmxOpcUa.Tests.Wiring
{
/// <summary>
/// Verifies: OpcUaService Start() creates and wires all components with fakes.
/// </summary>
public class ServiceStartupSequenceTest
{
[Fact]
public void Start_WithFakes_AllComponentsCreated()
{
var config = new AppConfiguration
{
OpcUa = new OpcUaConfiguration
{
Port = 14840,
GalaxyName = "TestGalaxy",
EndpointPath = "/LmxOpcUa"
},
MxAccess = new MxAccessConfiguration { ClientName = "Test" },
GalaxyRepository = new GalaxyRepositoryConfiguration(),
Dashboard = new DashboardConfiguration { Enabled = false } // Don't start HTTP listener in tests
};
var proxy = new FakeMxProxy();
var repo = new FakeGalaxyRepository
{
Hierarchy = new List<GalaxyObjectInfo>
{
new GalaxyObjectInfo { GobjectId = 1, TagName = "TestObj", BrowseName = "TestObj", ParentGobjectId = 0, IsArea = false }
},
Attributes = new List<GalaxyAttributeInfo>
{
new GalaxyAttributeInfo { GobjectId = 1, TagName = "TestObj", AttributeName = "TestAttr", FullTagReference = "TestObj.TestAttr", MxDataType = 5, IsArray = false }
}
};
var service = new OpcUaService(config, proxy, repo);
service.Start();
try
{
// Verify all components were created
service.MxClient.ShouldNotBeNull();
service.MxClient!.State.ShouldBe(ConnectionState.Connected);
service.Metrics.ShouldNotBeNull();
service.ServerHost.ShouldNotBeNull();
service.ChangeDetectionInstance.ShouldNotBeNull();
service.GalaxyStatsInstance.ShouldNotBeNull();
service.GalaxyStatsInstance!.GalaxyName.ShouldBe("TestGalaxy");
service.GalaxyStatsInstance.DbConnected.ShouldBe(true);
service.StatusReportInstance.ShouldNotBeNull();
// Dashboard disabled → no web server
service.StatusWeb.ShouldBeNull();
// MxProxy should have been registered
proxy.IsRegistered.ShouldBe(true);
}
finally
{
service.Stop();
}
}
}
}