Apply code style formatting and restore partial modifiers on Avalonia views
Linter/formatter pass across the full codebase. Restores required partial keyword on AXAML code-behind classes that the formatter incorrectly removed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -35,4 +35,4 @@ internal sealed class FakeApplicationConfigurationFactory : IApplicationConfigur
|
||||
|
||||
return Task.FromResult(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,8 @@ internal sealed class FakeEndpointDiscovery : IEndpointDiscovery
|
||||
public int SelectCallCount { get; private set; }
|
||||
public string? LastEndpointUrl { get; private set; }
|
||||
|
||||
public EndpointDescription SelectEndpoint(ApplicationConfiguration config, string endpointUrl, MessageSecurityMode requestedMode)
|
||||
public EndpointDescription SelectEndpoint(ApplicationConfiguration config, string endpointUrl,
|
||||
MessageSecurityMode requestedMode)
|
||||
{
|
||||
SelectCallCount++;
|
||||
LastEndpointUrl = endpointUrl;
|
||||
@@ -31,4 +32,4 @@ internal sealed class FakeEndpointDiscovery : IEndpointDiscovery
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,17 +5,8 @@ namespace ZB.MOM.WW.LmxOpcUa.Client.Shared.Tests.Fakes;
|
||||
|
||||
internal sealed class FakeSessionAdapter : ISessionAdapter
|
||||
{
|
||||
private readonly List<FakeSubscriptionAdapter> _createdSubscriptions = [];
|
||||
private Action<bool>? _keepAliveCallback;
|
||||
private readonly List<FakeSubscriptionAdapter> _createdSubscriptions = new();
|
||||
|
||||
public bool Connected { get; set; } = true;
|
||||
public string SessionId { get; set; } = "ns=0;i=12345";
|
||||
public string SessionName { get; set; } = "FakeSession";
|
||||
public string EndpointUrl { get; set; } = "opc.tcp://localhost:4840";
|
||||
public string ServerName { get; set; } = "FakeServer";
|
||||
public string SecurityMode { get; set; } = "None";
|
||||
public string SecurityPolicyUri { get; set; } = "http://opcfoundation.org/UA/SecurityPolicy#None";
|
||||
public NamespaceTable NamespaceUris { get; set; } = new();
|
||||
|
||||
public bool Closed { get; private set; }
|
||||
public bool Disposed { get; private set; }
|
||||
@@ -35,38 +26,39 @@ internal sealed class FakeSessionAdapter : ISessionAdapter
|
||||
public bool ThrowOnWrite { get; set; }
|
||||
public bool ThrowOnBrowse { get; set; }
|
||||
|
||||
public ReferenceDescriptionCollection BrowseResponse { get; set; } = new();
|
||||
public ReferenceDescriptionCollection BrowseResponse { get; set; } = [];
|
||||
public byte[]? BrowseContinuationPoint { get; set; }
|
||||
public ReferenceDescriptionCollection BrowseNextResponse { get; set; } = new();
|
||||
public ReferenceDescriptionCollection BrowseNextResponse { get; set; } = [];
|
||||
public byte[]? BrowseNextContinuationPoint { get; set; }
|
||||
public bool HasChildrenResponse { get; set; } = false;
|
||||
|
||||
public List<DataValue> HistoryReadRawResponse { get; set; } = new();
|
||||
public List<DataValue> HistoryReadAggregateResponse { get; set; } = new();
|
||||
public List<DataValue> HistoryReadRawResponse { get; set; } = [];
|
||||
public List<DataValue> HistoryReadAggregateResponse { get; set; } = [];
|
||||
public bool ThrowOnHistoryReadRaw { get; set; }
|
||||
public bool ThrowOnHistoryReadAggregate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The next FakeSubscriptionAdapter to return from CreateSubscriptionAsync.
|
||||
/// If null, a new one is created automatically.
|
||||
/// The next FakeSubscriptionAdapter to return from CreateSubscriptionAsync.
|
||||
/// If null, a new one is created automatically.
|
||||
/// </summary>
|
||||
public FakeSubscriptionAdapter? NextSubscription { get; set; }
|
||||
|
||||
public IReadOnlyList<FakeSubscriptionAdapter> CreatedSubscriptions => _createdSubscriptions;
|
||||
|
||||
public bool Connected { get; set; } = true;
|
||||
public string SessionId { get; set; } = "ns=0;i=12345";
|
||||
public string SessionName { get; set; } = "FakeSession";
|
||||
public string EndpointUrl { get; set; } = "opc.tcp://localhost:4840";
|
||||
public string ServerName { get; set; } = "FakeServer";
|
||||
public string SecurityMode { get; set; } = "None";
|
||||
public string SecurityPolicyUri { get; set; } = "http://opcfoundation.org/UA/SecurityPolicy#None";
|
||||
public NamespaceTable NamespaceUris { get; set; } = new();
|
||||
|
||||
public void RegisterKeepAliveHandler(Action<bool> callback)
|
||||
{
|
||||
_keepAliveCallback = callback;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Simulates a keep-alive event.
|
||||
/// </summary>
|
||||
public void SimulateKeepAlive(bool isGood)
|
||||
{
|
||||
_keepAliveCallback?.Invoke(isGood);
|
||||
}
|
||||
|
||||
public Task<DataValue> ReadValueAsync(NodeId nodeId, CancellationToken ct)
|
||||
{
|
||||
ReadCount++;
|
||||
@@ -119,7 +111,8 @@ internal sealed class FakeSessionAdapter : ISessionAdapter
|
||||
}
|
||||
|
||||
public Task<IReadOnlyList<DataValue>> HistoryReadAggregateAsync(
|
||||
NodeId nodeId, DateTime startTime, DateTime endTime, NodeId aggregateId, double intervalMs, CancellationToken ct)
|
||||
NodeId nodeId, DateTime startTime, DateTime endTime, NodeId aggregateId, double intervalMs,
|
||||
CancellationToken ct)
|
||||
{
|
||||
HistoryReadAggregateCount++;
|
||||
if (ThrowOnHistoryReadAggregate)
|
||||
@@ -147,4 +140,12 @@ internal sealed class FakeSessionAdapter : ISessionAdapter
|
||||
Disposed = true;
|
||||
Connected = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Simulates a keep-alive event.
|
||||
/// </summary>
|
||||
public void SimulateKeepAlive(bool isGood)
|
||||
{
|
||||
_keepAliveCallback?.Invoke(isGood);
|
||||
}
|
||||
}
|
||||
@@ -5,21 +5,13 @@ namespace ZB.MOM.WW.LmxOpcUa.Client.Shared.Tests.Fakes;
|
||||
|
||||
internal sealed class FakeSessionFactory : ISessionFactory
|
||||
{
|
||||
private readonly List<FakeSessionAdapter> _createdSessions = [];
|
||||
private readonly Queue<FakeSessionAdapter> _sessions = new();
|
||||
private readonly List<FakeSessionAdapter> _createdSessions = new();
|
||||
|
||||
public int CreateCallCount { get; private set; }
|
||||
public bool ThrowOnCreate { get; set; }
|
||||
public string? LastEndpointUrl { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Enqueues a session adapter to be returned on the next call to CreateSessionAsync.
|
||||
/// </summary>
|
||||
public void EnqueueSession(FakeSessionAdapter session)
|
||||
{
|
||||
_sessions.Enqueue(session);
|
||||
}
|
||||
|
||||
public IReadOnlyList<FakeSessionAdapter> CreatedSessions => _createdSessions;
|
||||
|
||||
public Task<ISessionAdapter> CreateSessionAsync(
|
||||
@@ -34,11 +26,8 @@ internal sealed class FakeSessionFactory : ISessionFactory
|
||||
|
||||
FakeSessionAdapter session;
|
||||
if (_sessions.Count > 0)
|
||||
{
|
||||
session = _sessions.Dequeue();
|
||||
}
|
||||
else
|
||||
{
|
||||
session = new FakeSessionAdapter
|
||||
{
|
||||
EndpointUrl = endpoint.EndpointUrl,
|
||||
@@ -46,11 +35,18 @@ internal sealed class FakeSessionFactory : ISessionFactory
|
||||
SecurityMode = endpoint.SecurityMode.ToString(),
|
||||
SecurityPolicyUri = endpoint.SecurityPolicyUri ?? string.Empty
|
||||
};
|
||||
}
|
||||
|
||||
// Ensure endpoint URL matches
|
||||
session.EndpointUrl = endpoint.EndpointUrl;
|
||||
_createdSessions.Add(session);
|
||||
return Task.FromResult<ISessionAdapter>(session);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enqueues a session adapter to be returned on the next call to CreateSessionAsync.
|
||||
/// </summary>
|
||||
public void EnqueueSession(FakeSessionAdapter session)
|
||||
{
|
||||
_sessions.Enqueue(session);
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,11 @@ namespace ZB.MOM.WW.LmxOpcUa.Client.Shared.Tests.Fakes;
|
||||
|
||||
internal sealed class FakeSubscriptionAdapter : ISubscriptionAdapter
|
||||
{
|
||||
private uint _nextHandle = 100;
|
||||
private readonly Dictionary<uint, (NodeId NodeId, Action<string, DataValue>? DataCallback, Action<EventFieldList>? EventCallback)> _items = new();
|
||||
private readonly
|
||||
Dictionary<uint, (NodeId NodeId, Action<string, DataValue>? DataCallback, Action<EventFieldList>? EventCallback
|
||||
)> _items = new();
|
||||
|
||||
public uint SubscriptionId { get; set; } = 42;
|
||||
private uint _nextHandle = 100;
|
||||
public bool Deleted { get; private set; }
|
||||
public bool ConditionRefreshCalled { get; private set; }
|
||||
public bool ThrowOnConditionRefresh { get; set; }
|
||||
@@ -16,7 +17,15 @@ internal sealed class FakeSubscriptionAdapter : ISubscriptionAdapter
|
||||
public int AddEventCount { get; private set; }
|
||||
public int RemoveCount { get; private set; }
|
||||
|
||||
public Task<uint> AddDataChangeMonitoredItemAsync(NodeId nodeId, int samplingIntervalMs, Action<string, DataValue> onDataChange, CancellationToken ct)
|
||||
/// <summary>
|
||||
/// Gets the handles of all active items.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<uint> ActiveHandles => _items.Keys.ToList();
|
||||
|
||||
public uint SubscriptionId { get; set; } = 42;
|
||||
|
||||
public Task<uint> AddDataChangeMonitoredItemAsync(NodeId nodeId, int samplingIntervalMs,
|
||||
Action<string, DataValue> onDataChange, CancellationToken ct)
|
||||
{
|
||||
AddDataChangeCount++;
|
||||
var handle = _nextHandle++;
|
||||
@@ -31,7 +40,8 @@ internal sealed class FakeSubscriptionAdapter : ISubscriptionAdapter
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task<uint> AddEventMonitoredItemAsync(NodeId nodeId, int samplingIntervalMs, EventFilter filter, Action<EventFieldList> onEvent, CancellationToken ct)
|
||||
public Task<uint> AddEventMonitoredItemAsync(NodeId nodeId, int samplingIntervalMs, EventFilter filter,
|
||||
Action<EventFieldList> onEvent, CancellationToken ct)
|
||||
{
|
||||
AddEventCount++;
|
||||
var handle = _nextHandle++;
|
||||
@@ -60,29 +70,19 @@ internal sealed class FakeSubscriptionAdapter : ISubscriptionAdapter
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Simulates a data change notification for testing.
|
||||
/// Simulates a data change notification for testing.
|
||||
/// </summary>
|
||||
public void SimulateDataChange(uint handle, DataValue value)
|
||||
{
|
||||
if (_items.TryGetValue(handle, out var item) && item.DataCallback != null)
|
||||
{
|
||||
item.DataCallback(item.NodeId.ToString(), value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Simulates an event notification for testing.
|
||||
/// Simulates an event notification for testing.
|
||||
/// </summary>
|
||||
public void SimulateEvent(uint handle, EventFieldList eventFields)
|
||||
{
|
||||
if (_items.TryGetValue(handle, out var item) && item.EventCallback != null)
|
||||
{
|
||||
item.EventCallback(eventFields);
|
||||
}
|
||||
if (_items.TryGetValue(handle, out var item) && item.EventCallback != null) item.EventCallback(eventFields);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the handles of all active items.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<uint> ActiveHandles => _items.Keys.ToList();
|
||||
}
|
||||
}
|
||||
@@ -64,4 +64,4 @@ public class AggregateTypeMapperTests
|
||||
Should.Throw<ArgumentOutOfRangeException>(() =>
|
||||
AggregateTypeMapper.ToNodeId((AggregateType)99));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,101 +10,101 @@ public class FailoverUrlParserTests
|
||||
public void Parse_CsvNull_ReturnsPrimaryOnly()
|
||||
{
|
||||
var result = FailoverUrlParser.Parse("opc.tcp://primary:4840", (string?)null);
|
||||
result.ShouldBe(new[] { "opc.tcp://primary:4840" });
|
||||
result.ShouldBe(["opc.tcp://primary:4840"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_CsvEmpty_ReturnsPrimaryOnly()
|
||||
{
|
||||
var result = FailoverUrlParser.Parse("opc.tcp://primary:4840", "");
|
||||
result.ShouldBe(new[] { "opc.tcp://primary:4840" });
|
||||
result.ShouldBe(["opc.tcp://primary:4840"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_CsvWhitespace_ReturnsPrimaryOnly()
|
||||
{
|
||||
var result = FailoverUrlParser.Parse("opc.tcp://primary:4840", " ");
|
||||
result.ShouldBe(new[] { "opc.tcp://primary:4840" });
|
||||
result.ShouldBe(["opc.tcp://primary:4840"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_SingleFailover_ReturnsBoth()
|
||||
{
|
||||
var result = FailoverUrlParser.Parse("opc.tcp://primary:4840", "opc.tcp://backup:4840");
|
||||
result.ShouldBe(new[] { "opc.tcp://primary:4840", "opc.tcp://backup:4840" });
|
||||
result.ShouldBe(["opc.tcp://primary:4840", "opc.tcp://backup:4840"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_MultipleFailovers_ReturnsAll()
|
||||
{
|
||||
var result = FailoverUrlParser.Parse("opc.tcp://primary:4840", "opc.tcp://backup1:4840,opc.tcp://backup2:4840");
|
||||
result.ShouldBe(new[] { "opc.tcp://primary:4840", "opc.tcp://backup1:4840", "opc.tcp://backup2:4840" });
|
||||
result.ShouldBe(["opc.tcp://primary:4840", "opc.tcp://backup1:4840", "opc.tcp://backup2:4840"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_TrimsWhitespace()
|
||||
{
|
||||
var result = FailoverUrlParser.Parse("opc.tcp://primary:4840", " opc.tcp://backup:4840 ");
|
||||
result.ShouldBe(new[] { "opc.tcp://primary:4840", "opc.tcp://backup:4840" });
|
||||
result.ShouldBe(["opc.tcp://primary:4840", "opc.tcp://backup:4840"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_DeduplicatesPrimaryInFailoverList()
|
||||
{
|
||||
var result = FailoverUrlParser.Parse("opc.tcp://primary:4840", "opc.tcp://primary:4840,opc.tcp://backup:4840");
|
||||
result.ShouldBe(new[] { "opc.tcp://primary:4840", "opc.tcp://backup:4840" });
|
||||
result.ShouldBe(["opc.tcp://primary:4840", "opc.tcp://backup:4840"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_DeduplicatesCaseInsensitive()
|
||||
{
|
||||
var result = FailoverUrlParser.Parse("opc.tcp://Primary:4840", "opc.tcp://primary:4840");
|
||||
result.ShouldBe(new[] { "opc.tcp://Primary:4840" });
|
||||
result.ShouldBe(["opc.tcp://Primary:4840"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_ArrayNull_ReturnsPrimaryOnly()
|
||||
{
|
||||
var result = FailoverUrlParser.Parse("opc.tcp://primary:4840", (string[]?)null);
|
||||
result.ShouldBe(new[] { "opc.tcp://primary:4840" });
|
||||
result.ShouldBe(["opc.tcp://primary:4840"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_ArrayEmpty_ReturnsPrimaryOnly()
|
||||
{
|
||||
var result = FailoverUrlParser.Parse("opc.tcp://primary:4840", Array.Empty<string>());
|
||||
result.ShouldBe(new[] { "opc.tcp://primary:4840" });
|
||||
var result = FailoverUrlParser.Parse("opc.tcp://primary:4840", []);
|
||||
result.ShouldBe(["opc.tcp://primary:4840"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_ArrayWithUrls_ReturnsAll()
|
||||
{
|
||||
var result = FailoverUrlParser.Parse("opc.tcp://primary:4840",
|
||||
new[] { "opc.tcp://backup1:4840", "opc.tcp://backup2:4840" });
|
||||
result.ShouldBe(new[] { "opc.tcp://primary:4840", "opc.tcp://backup1:4840", "opc.tcp://backup2:4840" });
|
||||
["opc.tcp://backup1:4840", "opc.tcp://backup2:4840"]);
|
||||
result.ShouldBe(["opc.tcp://primary:4840", "opc.tcp://backup1:4840", "opc.tcp://backup2:4840"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_ArrayDeduplicates()
|
||||
{
|
||||
var result = FailoverUrlParser.Parse("opc.tcp://primary:4840",
|
||||
new[] { "opc.tcp://primary:4840", "opc.tcp://backup:4840" });
|
||||
result.ShouldBe(new[] { "opc.tcp://primary:4840", "opc.tcp://backup:4840" });
|
||||
["opc.tcp://primary:4840", "opc.tcp://backup:4840"]);
|
||||
result.ShouldBe(["opc.tcp://primary:4840", "opc.tcp://backup:4840"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_ArrayTrimsWhitespace()
|
||||
{
|
||||
var result = FailoverUrlParser.Parse("opc.tcp://primary:4840",
|
||||
new[] { " opc.tcp://backup:4840 " });
|
||||
result.ShouldBe(new[] { "opc.tcp://primary:4840", "opc.tcp://backup:4840" });
|
||||
[" opc.tcp://backup:4840 "]);
|
||||
result.ShouldBe(["opc.tcp://primary:4840", "opc.tcp://backup:4840"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_ArraySkipsNullAndEmpty()
|
||||
{
|
||||
var result = FailoverUrlParser.Parse("opc.tcp://primary:4840",
|
||||
new[] { null!, "", "opc.tcp://backup:4840" });
|
||||
result.ShouldBe(new[] { "opc.tcp://primary:4840", "opc.tcp://backup:4840" });
|
||||
[null!, "", "opc.tcp://backup:4840"]);
|
||||
result.ShouldBe(["opc.tcp://primary:4840", "opc.tcp://backup:4840"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,4 +55,4 @@ public class SecurityModeMapperTests
|
||||
{
|
||||
SecurityModeMapper.FromString(null!).ShouldBe(SecurityMode.None);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,4 +107,4 @@ public class ValueConverterTests
|
||||
{
|
||||
Should.Throw<OverflowException>(() => ValueConverter.ConvertValue("256", (byte)0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,4 +92,4 @@ public class ConnectionSettingsTests
|
||||
};
|
||||
Should.NotThrow(() => settings.Validate());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using Opc.Ua;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.LmxOpcUa.Client.Shared.Models;
|
||||
using BrowseResult = ZB.MOM.WW.LmxOpcUa.Client.Shared.Models.BrowseResult;
|
||||
|
||||
namespace ZB.MOM.WW.LmxOpcUa.Client.Shared.Tests.Models;
|
||||
|
||||
@@ -10,7 +11,7 @@ public class ModelConstructionTests
|
||||
[Fact]
|
||||
public void BrowseResult_ConstructsCorrectly()
|
||||
{
|
||||
var result = new ZB.MOM.WW.LmxOpcUa.Client.Shared.Models.BrowseResult("ns=2;s=MyNode", "MyNode", "Variable", true);
|
||||
var result = new BrowseResult("ns=2;s=MyNode", "MyNode", "Variable", true);
|
||||
|
||||
result.NodeId.ShouldBe("ns=2;s=MyNode");
|
||||
result.DisplayName.ShouldBe("MyNode");
|
||||
@@ -21,7 +22,7 @@ public class ModelConstructionTests
|
||||
[Fact]
|
||||
public void BrowseResult_WithoutChildren()
|
||||
{
|
||||
var result = new ZB.MOM.WW.LmxOpcUa.Client.Shared.Models.BrowseResult("ns=2;s=Leaf", "Leaf", "Variable", false);
|
||||
var result = new BrowseResult("ns=2;s=Leaf", "Leaf", "Variable", false);
|
||||
result.HasChildren.ShouldBeFalse();
|
||||
}
|
||||
|
||||
@@ -56,7 +57,7 @@ public class ModelConstructionTests
|
||||
[Fact]
|
||||
public void RedundancyInfo_WithEmptyUris()
|
||||
{
|
||||
var info = new RedundancyInfo("None", 0, Array.Empty<string>(), string.Empty);
|
||||
var info = new RedundancyInfo("None", 0, [], string.Empty);
|
||||
info.ServerUris.ShouldBeEmpty();
|
||||
info.ApplicationUri.ShouldBeEmpty();
|
||||
}
|
||||
@@ -126,4 +127,4 @@ public class ModelConstructionTests
|
||||
{
|
||||
Enum.GetValues<AggregateType>().Length.ShouldBe(6);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,8 +10,8 @@ public class OpcUaClientServiceTests : IDisposable
|
||||
{
|
||||
private readonly FakeApplicationConfigurationFactory _configFactory = new();
|
||||
private readonly FakeEndpointDiscovery _endpointDiscovery = new();
|
||||
private readonly FakeSessionFactory _sessionFactory = new();
|
||||
private readonly OpcUaClientService _service;
|
||||
private readonly FakeSessionFactory _sessionFactory = new();
|
||||
|
||||
public OpcUaClientServiceTests()
|
||||
{
|
||||
@@ -23,11 +23,14 @@ public class OpcUaClientServiceTests : IDisposable
|
||||
_service.Dispose();
|
||||
}
|
||||
|
||||
private ConnectionSettings ValidSettings(string url = "opc.tcp://localhost:4840") => new()
|
||||
private ConnectionSettings ValidSettings(string url = "opc.tcp://localhost:4840")
|
||||
{
|
||||
EndpointUrl = url,
|
||||
SessionTimeoutSeconds = 60
|
||||
};
|
||||
return new ConnectionSettings
|
||||
{
|
||||
EndpointUrl = url,
|
||||
SessionTimeoutSeconds = 60
|
||||
};
|
||||
}
|
||||
|
||||
// --- Connection tests ---
|
||||
|
||||
@@ -243,15 +246,15 @@ public class OpcUaClientServiceTests : IDisposable
|
||||
{
|
||||
var session = new FakeSessionAdapter
|
||||
{
|
||||
BrowseResponse = new ReferenceDescriptionCollection
|
||||
{
|
||||
BrowseResponse =
|
||||
[
|
||||
new ReferenceDescription
|
||||
{
|
||||
NodeId = new ExpandedNodeId("ns=2;s=Child1"),
|
||||
DisplayName = new LocalizedText("Child1"),
|
||||
NodeClass = NodeClass.Variable
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
_sessionFactory.EnqueueSession(session);
|
||||
await _service.ConnectAsync(ValidSettings());
|
||||
@@ -269,12 +272,12 @@ public class OpcUaClientServiceTests : IDisposable
|
||||
{
|
||||
var session = new FakeSessionAdapter
|
||||
{
|
||||
BrowseResponse = new ReferenceDescriptionCollection()
|
||||
BrowseResponse = []
|
||||
};
|
||||
_sessionFactory.EnqueueSession(session);
|
||||
await _service.ConnectAsync(ValidSettings());
|
||||
|
||||
await _service.BrowseAsync(null);
|
||||
await _service.BrowseAsync();
|
||||
|
||||
session.BrowseCount.ShouldBe(1);
|
||||
}
|
||||
@@ -284,15 +287,15 @@ public class OpcUaClientServiceTests : IDisposable
|
||||
{
|
||||
var session = new FakeSessionAdapter
|
||||
{
|
||||
BrowseResponse = new ReferenceDescriptionCollection
|
||||
{
|
||||
BrowseResponse =
|
||||
[
|
||||
new ReferenceDescription
|
||||
{
|
||||
NodeId = new ExpandedNodeId("ns=2;s=Folder1"),
|
||||
DisplayName = new LocalizedText("Folder1"),
|
||||
NodeClass = NodeClass.Object
|
||||
}
|
||||
},
|
||||
],
|
||||
HasChildrenResponse = true
|
||||
};
|
||||
_sessionFactory.EnqueueSession(session);
|
||||
@@ -309,25 +312,25 @@ public class OpcUaClientServiceTests : IDisposable
|
||||
{
|
||||
var session = new FakeSessionAdapter
|
||||
{
|
||||
BrowseResponse = new ReferenceDescriptionCollection
|
||||
{
|
||||
BrowseResponse =
|
||||
[
|
||||
new ReferenceDescription
|
||||
{
|
||||
NodeId = new ExpandedNodeId("ns=2;s=A"),
|
||||
DisplayName = new LocalizedText("A"),
|
||||
NodeClass = NodeClass.Variable
|
||||
}
|
||||
},
|
||||
BrowseContinuationPoint = new byte[] { 1, 2, 3 },
|
||||
BrowseNextResponse = new ReferenceDescriptionCollection
|
||||
{
|
||||
],
|
||||
BrowseContinuationPoint = [1, 2, 3],
|
||||
BrowseNextResponse =
|
||||
[
|
||||
new ReferenceDescription
|
||||
{
|
||||
NodeId = new ExpandedNodeId("ns=2;s=B"),
|
||||
DisplayName = new LocalizedText("B"),
|
||||
NodeClass = NodeClass.Variable
|
||||
}
|
||||
},
|
||||
],
|
||||
BrowseNextContinuationPoint = null
|
||||
};
|
||||
_sessionFactory.EnqueueSession(session);
|
||||
@@ -436,7 +439,7 @@ public class OpcUaClientServiceTests : IDisposable
|
||||
_sessionFactory.EnqueueSession(session);
|
||||
await _service.ConnectAsync(ValidSettings());
|
||||
|
||||
await _service.SubscribeAlarmsAsync(null, 1000);
|
||||
await _service.SubscribeAlarmsAsync();
|
||||
|
||||
session.CreatedSubscriptions.Count.ShouldBe(1);
|
||||
session.CreatedSubscriptions[0].AddEventCount.ShouldBe(1);
|
||||
@@ -472,21 +475,21 @@ public class OpcUaClientServiceTests : IDisposable
|
||||
var handle = fakeSub.ActiveHandles.First();
|
||||
var fields = new EventFieldList
|
||||
{
|
||||
EventFields = new VariantCollection
|
||||
{
|
||||
new Variant(new byte[] { 1, 2, 3 }), // 0: EventId
|
||||
new Variant(ObjectTypeIds.AlarmConditionType), // 1: EventType
|
||||
new Variant("Source1"), // 2: SourceName
|
||||
new Variant(DateTime.UtcNow), // 3: Time
|
||||
new Variant(new LocalizedText("High temp")), // 4: Message
|
||||
new Variant((ushort)500), // 5: Severity
|
||||
new Variant("HighTemp"), // 6: ConditionName
|
||||
new Variant(true), // 7: Retain
|
||||
new Variant(false), // 8: AckedState
|
||||
new Variant(true), // 9: ActiveState
|
||||
new Variant(true), // 10: EnabledState
|
||||
new Variant(false) // 11: SuppressedOrShelved
|
||||
}
|
||||
EventFields =
|
||||
[
|
||||
new Variant(new byte[] { 1, 2, 3 }), // 0: EventId
|
||||
new Variant(ObjectTypeIds.AlarmConditionType), // 1: EventType
|
||||
new Variant("Source1"), // 2: SourceName
|
||||
new Variant(DateTime.UtcNow), // 3: Time
|
||||
new Variant(new LocalizedText("High temp")), // 4: Message
|
||||
new Variant((ushort)500), // 5: Severity
|
||||
new Variant("HighTemp"), // 6: ConditionName
|
||||
new Variant(true), // 7: Retain
|
||||
new Variant(false), // 8: AckedState
|
||||
new Variant(true), // 9: ActiveState
|
||||
new Variant(true), // 10: EnabledState
|
||||
new Variant(false)
|
||||
]
|
||||
};
|
||||
fakeSub.SimulateEvent(handle, fields);
|
||||
|
||||
@@ -563,8 +566,8 @@ public class OpcUaClientServiceTests : IDisposable
|
||||
{
|
||||
var expectedValues = new List<DataValue>
|
||||
{
|
||||
new DataValue(new Variant(1.0), StatusCodes.Good),
|
||||
new DataValue(new Variant(2.0), StatusCodes.Good)
|
||||
new(new Variant(1.0), StatusCodes.Good),
|
||||
new(new Variant(2.0), StatusCodes.Good)
|
||||
};
|
||||
var session = new FakeSessionAdapter { HistoryReadRawResponse = expectedValues };
|
||||
_sessionFactory.EnqueueSession(session);
|
||||
@@ -600,7 +603,7 @@ public class OpcUaClientServiceTests : IDisposable
|
||||
{
|
||||
var expectedValues = new List<DataValue>
|
||||
{
|
||||
new DataValue(new Variant(1.5), StatusCodes.Good)
|
||||
new(new Variant(1.5), StatusCodes.Good)
|
||||
};
|
||||
var session = new FakeSessionAdapter { HistoryReadAggregateResponse = expectedValues };
|
||||
_sessionFactory.EnqueueSession(session);
|
||||
@@ -650,9 +653,9 @@ public class OpcUaClientServiceTests : IDisposable
|
||||
if (nodeId == VariableIds.Server_ServiceLevel)
|
||||
return new DataValue(new Variant((byte)200), StatusCodes.Good);
|
||||
if (nodeId == VariableIds.Server_ServerRedundancy_ServerUriArray)
|
||||
return new DataValue(new Variant(new[] { "urn:server1", "urn:server2" }), StatusCodes.Good);
|
||||
return new DataValue(new Variant(["urn:server1", "urn:server2"]), StatusCodes.Good);
|
||||
if (nodeId == VariableIds.Server_ServerArray)
|
||||
return new DataValue(new Variant(new[] { "urn:server1" }), StatusCodes.Good);
|
||||
return new DataValue(new Variant(["urn:server1"]), StatusCodes.Good);
|
||||
return new DataValue(StatusCodes.BadNodeIdUnknown);
|
||||
}
|
||||
};
|
||||
@@ -663,14 +666,14 @@ public class OpcUaClientServiceTests : IDisposable
|
||||
|
||||
info.Mode.ShouldBe("Warm");
|
||||
info.ServiceLevel.ShouldBe((byte)200);
|
||||
info.ServerUris.ShouldBe(new[] { "urn:server1", "urn:server2" });
|
||||
info.ServerUris.ShouldBe(["urn:server1", "urn:server2"]);
|
||||
info.ApplicationUri.ShouldBe("urn:server1");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetRedundancyInfoAsync_MissingOptionalArrays_ReturnsGracefully()
|
||||
{
|
||||
int readCallIndex = 0;
|
||||
var readCallIndex = 0;
|
||||
var session = new FakeSessionAdapter
|
||||
{
|
||||
ReadResponseFunc = nodeId =>
|
||||
@@ -712,7 +715,7 @@ public class OpcUaClientServiceTests : IDisposable
|
||||
_sessionFactory.EnqueueSession(session2);
|
||||
|
||||
var settings = ValidSettings("opc.tcp://primary:4840");
|
||||
settings.FailoverUrls = new[] { "opc.tcp://backup:4840" };
|
||||
settings.FailoverUrls = ["opc.tcp://backup:4840"];
|
||||
|
||||
var stateChanges = new List<ConnectionStateChangedEventArgs>();
|
||||
_service.ConnectionStateChanged += (_, e) => stateChanges.Add(e);
|
||||
@@ -728,7 +731,7 @@ public class OpcUaClientServiceTests : IDisposable
|
||||
// Should have reconnected
|
||||
stateChanges.ShouldContain(e => e.NewState == ConnectionState.Reconnecting);
|
||||
stateChanges.ShouldContain(e => e.NewState == ConnectionState.Connected &&
|
||||
e.EndpointUrl == "opc.tcp://backup:4840");
|
||||
e.EndpointUrl == "opc.tcp://backup:4840");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -744,7 +747,7 @@ public class OpcUaClientServiceTests : IDisposable
|
||||
_sessionFactory.EnqueueSession(session2);
|
||||
|
||||
var settings = ValidSettings("opc.tcp://primary:4840");
|
||||
settings.FailoverUrls = new[] { "opc.tcp://backup:4840" };
|
||||
settings.FailoverUrls = ["opc.tcp://backup:4840"];
|
||||
|
||||
await _service.ConnectAsync(settings);
|
||||
session1.SimulateKeepAlive(false);
|
||||
@@ -813,4 +816,4 @@ public class OpcUaClientServiceTests : IDisposable
|
||||
service.ShouldBeAssignableTo<IOpcUaClientService>();
|
||||
service.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<RootNamespace>ZB.MOM.WW.LmxOpcUa.Client.Shared.Tests</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<RootNamespace>ZB.MOM.WW.LmxOpcUa.Client.Shared.Tests</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="xunit.v3" Version="1.1.0" />
|
||||
<PackageReference Include="Shouldly" Version="4.3.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="xunit.v3" Version="1.1.0"/>
|
||||
<PackageReference Include="Shouldly" Version="4.3.0"/>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0"/>
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\ZB.MOM.WW.LmxOpcUa.Client.Shared\ZB.MOM.WW.LmxOpcUa.Client.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\ZB.MOM.WW.LmxOpcUa.Client.Shared\ZB.MOM.WW.LmxOpcUa.Client.Shared.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user