64e3fbe035
v2-ci / build (push) Failing after 1m43s
v2-ci / unit-tests (tests/Core/ZB.MOM.WW.OtOpcUa.Cluster.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.ControlPlane.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.Security.Tests) (push) Has been skipped
v2-ci / integration (tests/Server/ZB.MOM.WW.OtOpcUa.Host.IntegrationTests) (push) Has been skipped
v2-ci / integration (tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.IntegrationTests) (push) Has been skipped
Adds <summary>, <param>, <typeparam>, and <inheritdoc/> tags to public members surfaced by commentchecker — resolves 5,847 of 5,869 issues (99.6%) across three /fixdocs passes.
93 lines
3.3 KiB
C#
93 lines
3.3 KiB
C#
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Client.CLI.Commands;
|
|
using ZB.MOM.WW.OtOpcUa.Client.CLI.Tests.Fakes;
|
|
using ZB.MOM.WW.OtOpcUa.Client.Shared.Models;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Client.CLI.Tests;
|
|
|
|
public class CommandBaseTests
|
|
{
|
|
/// <summary>Verifies that common options map to connection settings correctly.</summary>
|
|
[Fact]
|
|
public async Task CommonOptions_MapToConnectionSettings_Correctly()
|
|
{
|
|
var fakeService = new FakeOpcUaClientService();
|
|
var factory = new FakeOpcUaClientServiceFactory(fakeService);
|
|
var command = new ConnectCommand(factory)
|
|
{
|
|
Url = "opc.tcp://myserver:4840",
|
|
Username = "admin",
|
|
Password = "secret",
|
|
Security = "sign",
|
|
FailoverUrls = "opc.tcp://backup1:4840,opc.tcp://backup2:4840"
|
|
};
|
|
|
|
using var console = TestConsoleHelper.CreateConsole();
|
|
await command.ExecuteAsync(console);
|
|
|
|
var settings = fakeService.LastConnectionSettings;
|
|
settings.ShouldNotBeNull();
|
|
settings.EndpointUrl.ShouldBe("opc.tcp://myserver:4840");
|
|
settings.Username.ShouldBe("admin");
|
|
settings.Password.ShouldBe("secret");
|
|
settings.SecurityMode.ShouldBe(SecurityMode.Sign);
|
|
settings.FailoverUrls.ShouldNotBeNull();
|
|
settings.FailoverUrls!.Length.ShouldBe(3); // primary + 2 failover
|
|
settings.FailoverUrls[0].ShouldBe("opc.tcp://myserver:4840");
|
|
settings.AutoAcceptCertificates.ShouldBeTrue();
|
|
}
|
|
|
|
/// <summary>Verifies that encrypt option maps to SignAndEncrypt.</summary>
|
|
[Fact]
|
|
public async Task SecurityOption_Encrypt_MapsToSignAndEncrypt()
|
|
{
|
|
var fakeService = new FakeOpcUaClientService();
|
|
var factory = new FakeOpcUaClientServiceFactory(fakeService);
|
|
var command = new ConnectCommand(factory)
|
|
{
|
|
Url = "opc.tcp://localhost:4840",
|
|
Security = "encrypt"
|
|
};
|
|
|
|
using var console = TestConsoleHelper.CreateConsole();
|
|
await command.ExecuteAsync(console);
|
|
|
|
fakeService.LastConnectionSettings!.SecurityMode.ShouldBe(SecurityMode.SignAndEncrypt);
|
|
}
|
|
|
|
/// <summary>Verifies that none option maps to None.</summary>
|
|
[Fact]
|
|
public async Task SecurityOption_None_MapsToNone()
|
|
{
|
|
var fakeService = new FakeOpcUaClientService();
|
|
var factory = new FakeOpcUaClientServiceFactory(fakeService);
|
|
var command = new ConnectCommand(factory)
|
|
{
|
|
Url = "opc.tcp://localhost:4840",
|
|
Security = "none"
|
|
};
|
|
|
|
using var console = TestConsoleHelper.CreateConsole();
|
|
await command.ExecuteAsync(console);
|
|
|
|
fakeService.LastConnectionSettings!.SecurityMode.ShouldBe(SecurityMode.None);
|
|
}
|
|
|
|
/// <summary>Verifies that no failover URLs results in null FailoverUrls.</summary>
|
|
[Fact]
|
|
public async Task NoFailoverUrls_FailoverUrlsIsNull()
|
|
{
|
|
var fakeService = new FakeOpcUaClientService();
|
|
var factory = new FakeOpcUaClientServiceFactory(fakeService);
|
|
var command = new ConnectCommand(factory)
|
|
{
|
|
Url = "opc.tcp://localhost:4840"
|
|
};
|
|
|
|
using var console = TestConsoleHelper.CreateConsole();
|
|
await command.ExecuteAsync(console);
|
|
|
|
fakeService.LastConnectionSettings!.FailoverUrls.ShouldBeNull();
|
|
}
|
|
} |