Add cross-platform OPC UA client stack: shared library, CLI tool, and Avalonia UI
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>
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.LmxOpcUa.Client.Shared.Models;
|
||||
|
||||
namespace ZB.MOM.WW.LmxOpcUa.Client.Shared.Tests.Models;
|
||||
|
||||
public class ConnectionSettingsTests
|
||||
{
|
||||
[Fact]
|
||||
public void Defaults_AreCorrect()
|
||||
{
|
||||
var settings = new ConnectionSettings();
|
||||
|
||||
settings.EndpointUrl.ShouldBe(string.Empty);
|
||||
settings.FailoverUrls.ShouldBeNull();
|
||||
settings.Username.ShouldBeNull();
|
||||
settings.Password.ShouldBeNull();
|
||||
settings.SecurityMode.ShouldBe(SecurityMode.None);
|
||||
settings.SessionTimeoutSeconds.ShouldBe(60);
|
||||
settings.AutoAcceptCertificates.ShouldBeTrue();
|
||||
settings.CertificateStorePath.ShouldContain("LmxOpcUaClient");
|
||||
settings.CertificateStorePath.ShouldContain("pki");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_ThrowsOnNullEndpointUrl()
|
||||
{
|
||||
var settings = new ConnectionSettings { EndpointUrl = null! };
|
||||
Should.Throw<ArgumentException>(() => settings.Validate())
|
||||
.ParamName.ShouldBe("EndpointUrl");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_ThrowsOnEmptyEndpointUrl()
|
||||
{
|
||||
var settings = new ConnectionSettings { EndpointUrl = "" };
|
||||
Should.Throw<ArgumentException>(() => settings.Validate())
|
||||
.ParamName.ShouldBe("EndpointUrl");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_ThrowsOnWhitespaceEndpointUrl()
|
||||
{
|
||||
var settings = new ConnectionSettings { EndpointUrl = " " };
|
||||
Should.Throw<ArgumentException>(() => settings.Validate())
|
||||
.ParamName.ShouldBe("EndpointUrl");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_ThrowsOnZeroTimeout()
|
||||
{
|
||||
var settings = new ConnectionSettings
|
||||
{
|
||||
EndpointUrl = "opc.tcp://localhost:4840",
|
||||
SessionTimeoutSeconds = 0
|
||||
};
|
||||
Should.Throw<ArgumentException>(() => settings.Validate())
|
||||
.ParamName.ShouldBe("SessionTimeoutSeconds");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_ThrowsOnNegativeTimeout()
|
||||
{
|
||||
var settings = new ConnectionSettings
|
||||
{
|
||||
EndpointUrl = "opc.tcp://localhost:4840",
|
||||
SessionTimeoutSeconds = -1
|
||||
};
|
||||
Should.Throw<ArgumentException>(() => settings.Validate())
|
||||
.ParamName.ShouldBe("SessionTimeoutSeconds");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_ThrowsOnTimeoutAbove3600()
|
||||
{
|
||||
var settings = new ConnectionSettings
|
||||
{
|
||||
EndpointUrl = "opc.tcp://localhost:4840",
|
||||
SessionTimeoutSeconds = 3601
|
||||
};
|
||||
Should.Throw<ArgumentException>(() => settings.Validate())
|
||||
.ParamName.ShouldBe("SessionTimeoutSeconds");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_SucceedsWithValidSettings()
|
||||
{
|
||||
var settings = new ConnectionSettings
|
||||
{
|
||||
EndpointUrl = "opc.tcp://localhost:4840",
|
||||
SessionTimeoutSeconds = 120
|
||||
};
|
||||
Should.NotThrow(() => settings.Validate());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user