Implements Client.Shared (IOpcUaClientService with connection lifecycle, failover, browse, read/write, subscriptions, alarms, history, redundancy), Client.CLI (8 CliFx commands mirroring tools/opcuacli-dotnet), and Client.UI (Avalonia desktop app with tree browser, read/write, subscriptions, alarms, and history tabs). All three target .NET 10 and are covered by 249 unit tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
94 lines
3.1 KiB
C#
94 lines
3.1 KiB
C#
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.LmxOpcUa.Client.CLI.Commands;
|
|
using ZB.MOM.WW.LmxOpcUa.Client.CLI.Tests.Fakes;
|
|
using ZB.MOM.WW.LmxOpcUa.Client.Shared.Models;
|
|
|
|
namespace ZB.MOM.WW.LmxOpcUa.Client.CLI.Tests;
|
|
|
|
public class RedundancyCommandTests
|
|
{
|
|
[Fact]
|
|
public async Task Execute_PrintsRedundancyInfo()
|
|
{
|
|
var fakeService = new FakeOpcUaClientService
|
|
{
|
|
RedundancyInfoResult = new RedundancyInfo(
|
|
"Hot", 250, new[] { "urn:server:primary", "urn:server:secondary" }, "urn:app:myserver")
|
|
};
|
|
var factory = new FakeOpcUaClientServiceFactory(fakeService);
|
|
var command = new RedundancyCommand(factory)
|
|
{
|
|
Url = "opc.tcp://localhost:4840"
|
|
};
|
|
|
|
using var console = TestConsoleHelper.CreateConsole();
|
|
await command.ExecuteAsync(console);
|
|
|
|
var output = TestConsoleHelper.GetOutput(console);
|
|
output.ShouldContain("Redundancy Mode: Hot");
|
|
output.ShouldContain("Service Level: 250");
|
|
output.ShouldContain("Server URIs:");
|
|
output.ShouldContain(" - urn:server:primary");
|
|
output.ShouldContain(" - urn:server:secondary");
|
|
output.ShouldContain("Application URI: urn:app:myserver");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Execute_NoServerUris_OmitsUriSection()
|
|
{
|
|
var fakeService = new FakeOpcUaClientService
|
|
{
|
|
RedundancyInfoResult = new RedundancyInfo(
|
|
"None", 100, Array.Empty<string>(), "urn:app:standalone")
|
|
};
|
|
var factory = new FakeOpcUaClientServiceFactory(fakeService);
|
|
var command = new RedundancyCommand(factory)
|
|
{
|
|
Url = "opc.tcp://localhost:4840"
|
|
};
|
|
|
|
using var console = TestConsoleHelper.CreateConsole();
|
|
await command.ExecuteAsync(console);
|
|
|
|
var output = TestConsoleHelper.GetOutput(console);
|
|
output.ShouldContain("Redundancy Mode: None");
|
|
output.ShouldContain("Service Level: 100");
|
|
output.ShouldNotContain("Server URIs:");
|
|
output.ShouldContain("Application URI: urn:app:standalone");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Execute_CallsGetRedundancyInfo()
|
|
{
|
|
var fakeService = new FakeOpcUaClientService();
|
|
var factory = new FakeOpcUaClientServiceFactory(fakeService);
|
|
var command = new RedundancyCommand(factory)
|
|
{
|
|
Url = "opc.tcp://localhost:4840"
|
|
};
|
|
|
|
using var console = TestConsoleHelper.CreateConsole();
|
|
await command.ExecuteAsync(console);
|
|
|
|
fakeService.GetRedundancyInfoCalled.ShouldBeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Execute_DisconnectsInFinally()
|
|
{
|
|
var fakeService = new FakeOpcUaClientService();
|
|
var factory = new FakeOpcUaClientServiceFactory(fakeService);
|
|
var command = new RedundancyCommand(factory)
|
|
{
|
|
Url = "opc.tcp://localhost:4840"
|
|
};
|
|
|
|
using var console = TestConsoleHelper.CreateConsole();
|
|
await command.ExecuteAsync(console);
|
|
|
|
fakeService.DisconnectCalled.ShouldBeTrue();
|
|
fakeService.DisposeCalled.ShouldBeTrue();
|
|
}
|
|
}
|