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>
75 lines
2.1 KiB
C#
75 lines
2.1 KiB
C#
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.LmxOpcUa.Host.MxAccess;
|
|
|
|
namespace ZB.MOM.WW.LmxOpcUa.Tests.MxAccess
|
|
{
|
|
public class StaComThreadTests : IDisposable
|
|
{
|
|
private readonly StaComThread _thread;
|
|
|
|
public StaComThreadTests()
|
|
{
|
|
_thread = new StaComThread();
|
|
_thread.Start();
|
|
}
|
|
|
|
public void Dispose() => _thread.Dispose();
|
|
|
|
[Fact]
|
|
public async Task RunAsync_ExecutesOnStaThread()
|
|
{
|
|
var apartmentState = await _thread.RunAsync(() => Thread.CurrentThread.GetApartmentState());
|
|
apartmentState.ShouldBe(ApartmentState.STA);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task RunAsync_Action_Completes()
|
|
{
|
|
var executed = false;
|
|
await _thread.RunAsync(() => executed = true);
|
|
executed.ShouldBe(true);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task RunAsync_Func_ReturnsResult()
|
|
{
|
|
var result = await _thread.RunAsync(() => 42);
|
|
result.ShouldBe(42);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task RunAsync_PropagatesException()
|
|
{
|
|
await Should.ThrowAsync<InvalidOperationException>(
|
|
_thread.RunAsync(() => throw new InvalidOperationException("test error")));
|
|
}
|
|
|
|
[Fact]
|
|
public void Dispose_Stops_Thread()
|
|
{
|
|
var thread = new StaComThread();
|
|
thread.Start();
|
|
thread.IsRunning.ShouldBe(true);
|
|
thread.Dispose();
|
|
// After dispose, should not accept new work
|
|
Should.Throw<ObjectDisposedException>(() => thread.RunAsync(() => { }).GetAwaiter().GetResult());
|
|
}
|
|
|
|
[Fact]
|
|
public async Task MultipleWorkItems_ExecuteInOrder()
|
|
{
|
|
var results = new System.Collections.Concurrent.ConcurrentBag<int>();
|
|
await Task.WhenAll(
|
|
_thread.RunAsync(() => results.Add(1)),
|
|
_thread.RunAsync(() => results.Add(2)),
|
|
_thread.RunAsync(() => results.Add(3)));
|
|
|
|
results.Count.ShouldBe(3);
|
|
}
|
|
}
|
|
}
|