using System; using System.Threading.Tasks; using MxGateway.Contracts.Proto; using MxGateway.Worker.MxAccess; using MxGateway.Worker.Sta; namespace MxGateway.Worker.Tests.MxAccess; public sealed class MxAccessLiveComCreationTests { [Fact] public async Task StartAsync_WhenOptedIn_CreatesInstalledMxAccessComObjectOnSta() { if (!string.Equals( Environment.GetEnvironmentVariable("MXGATEWAY_RUN_LIVE_MXACCESS_TESTS"), "1", StringComparison.Ordinal)) { return; } using MxAccessStaSession session = new(); await session.StartAsync(workerProcessId: 1234); } [Fact] public async Task RegisterAndUnregister_WhenOptedIn_RoundTripsInstalledMxAccessServerHandle() { if (!RunLiveMxAccessTests()) { return; } using MxAccessStaSession session = new(); await session.StartAsync(workerProcessId: 1234); MxCommandReply registerReply = await session.DispatchAsync(new StaCommand( "session-1", "live-register", new MxCommand { Kind = MxCommandKind.Register, Register = new RegisterCommand { ClientName = "MxGateway.Worker.Tests", }, })); Assert.Equal(ProtocolStatusCode.Ok, registerReply.ProtocolStatus.Code); Assert.True(registerReply.Register.ServerHandle > 0); MxCommandReply unregisterReply = await session.DispatchAsync(new StaCommand( "session-1", "live-unregister", new MxCommand { Kind = MxCommandKind.Unregister, Unregister = new UnregisterCommand { ServerHandle = registerReply.Register.ServerHandle, }, })); Assert.Equal(ProtocolStatusCode.Ok, unregisterReply.ProtocolStatus.Code); } private static bool RunLiveMxAccessTests() { return string.Equals( Environment.GetEnvironmentVariable("MXGATEWAY_RUN_LIVE_MXACCESS_TESTS"), "1", StringComparison.Ordinal); } }