From bbe1ce13d9decd91a2248573df0094710a711aca Mon Sep 17 00:00:00 2001
From: Trivalik <3148279+trivalik@users.noreply.github.com>
Date: Tue, 3 Jan 2023 14:43:08 +0100
Subject: [PATCH 1/3] Update README.md after rename UaTcpSessionChannel
---
README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 37efd62..3e134f4 100644
--- a/README.md
+++ b/README.md
@@ -35,8 +35,8 @@ public class Program
ApplicationType = ApplicationType.Client
};
- // create a 'UaTcpSessionChannel', a client-side channel that opens a 'session' with the server.
- var channel = new UaTcpSessionChannel(
+ // create a 'ClientTransportChannel', a client-side channel that opens a 'session' with the server.
+ var channel = new ClientTransportChannel(
clientDescription,
null, // no x509 certificates
new AnonymousIdentity(), // no user identity
From 094217dbf676f35d7545cb8bce45d24446f65e97 Mon Sep 17 00:00:00 2001
From: Trivalik <3148279+trivalik@users.noreply.github.com>
Date: Tue, 3 Jan 2023 14:53:36 +0100
Subject: [PATCH 2/3] do not create empty arrays
---
UaClient/Collections/ErrorsContainer.cs | 2 +-
.../ServiceModel/Ua/Channels/ClientSessionChannel.cs | 9 ++++-----
UaClient/ServiceModel/Ua/EventHelper.cs | 2 +-
3 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/UaClient/Collections/ErrorsContainer.cs b/UaClient/Collections/ErrorsContainer.cs
index 947b60e..38225cd 100644
--- a/UaClient/Collections/ErrorsContainer.cs
+++ b/UaClient/Collections/ErrorsContainer.cs
@@ -13,7 +13,7 @@ namespace Workstation.Collections
/// The type of the error object.
public class ErrorsContainer
{
- private static readonly T[] _noErrors = new T[0];
+ private static readonly T[] _noErrors = Array.Empty();
private readonly Action _raiseErrorsChanged;
private readonly Dictionary> _validationResults;
diff --git a/UaClient/ServiceModel/Ua/Channels/ClientSessionChannel.cs b/UaClient/ServiceModel/Ua/Channels/ClientSessionChannel.cs
index 4445965..ccc54ce 100644
--- a/UaClient/ServiceModel/Ua/Channels/ClientSessionChannel.cs
+++ b/UaClient/ServiceModel/Ua/Channels/ClientSessionChannel.cs
@@ -9,9 +9,8 @@
using System.Threading.Tasks.Dataflow;
using Microsoft.Extensions.Logging;
using Org.BouncyCastle.Crypto;
-using Org.BouncyCastle.Security;
-using System.Collections.Generic;
using Org.BouncyCastle.Crypto.Parameters;
+using Org.BouncyCastle.Security;
using Org.BouncyCastle.X509;
namespace Workstation.ServiceModel.Ua.Channels
@@ -619,7 +618,7 @@ protected override async Task OnOpenAsync(CancellationToken token = default)
throw new ServiceResultException(StatusCodes.BadIdentityTokenRejected);
}
- byte[] passwordBytes = userNameIdentity.Password != null ? System.Text.Encoding.UTF8.GetBytes(userNameIdentity.Password) : new byte[0];
+ byte[] passwordBytes = userNameIdentity.Password != null ? System.Text.Encoding.UTF8.GetBytes(userNameIdentity.Password) : Array.Empty();
int plainTextLength = passwordBytes.Length + RemoteNonce!.Length;
IBufferedCipher encryptor;
byte[] cipherText;
@@ -809,7 +808,7 @@ private async Task PublishAsync(CancellationToken token = default)
var publishRequest = new PublishRequest
{
RequestHeader = new RequestHeader { TimeoutHint = _publishTimeoutHint, ReturnDiagnostics = _options.DiagnosticsHint },
- SubscriptionAcknowledgements = new SubscriptionAcknowledgement[0]
+ SubscriptionAcknowledgements = Array.Empty()
};
while (!token.IsCancellationRequested)
{
@@ -836,7 +835,7 @@ private async Task PublishAsync(CancellationToken token = default)
SubscriptionId = publishResponse.SubscriptionId
}
}
- : new SubscriptionAcknowledgement[0]
+ : Array.Empty()
};
}
catch (Exception ex)
diff --git a/UaClient/ServiceModel/Ua/EventHelper.cs b/UaClient/ServiceModel/Ua/EventHelper.cs
index f25ebb5..8853bd3 100644
--- a/UaClient/ServiceModel/Ua/EventHelper.cs
+++ b/UaClient/ServiceModel/Ua/EventHelper.cs
@@ -81,7 +81,7 @@ private static void RegisterSelectClauseAndDeserializer(Type type)
var clause = new SimpleAttributeOperand
{
TypeDefinitionId = NodeId.Parse(efa.TypeDefinitionId!),
- BrowsePath = !String.IsNullOrWhiteSpace(efa.BrowsePath) ? efa.BrowsePath!.Split('/').Select(s => QualifiedName.Parse(s)).ToArray() : new QualifiedName[0],
+ BrowsePath = !String.IsNullOrWhiteSpace(efa.BrowsePath) ? efa.BrowsePath!.Split('/').Select(s => QualifiedName.Parse(s)).ToArray() : Array.Empty(),
AttributeId = efa.AttributeId,
IndexRange = efa.IndexRange
};
From 65ab757aa3266580ae10a751f69b2aedcbf6dad1 Mon Sep 17 00:00:00 2001
From: Andrew Cullen
Date: Mon, 16 Jan 2023 10:46:14 -0500
Subject: [PATCH 3/3] Update packages
---
.../UnitTests/ArraySegmentExtensionTests.cs | 2 +-
.../BinaryDecoderTests.Equivalency.cs | 29 +++++-----
.../UnitTests/Channels/BinaryDecoderTests.cs | 4 +-
.../BinaryEncoderTests.Equivalency.cs | 21 ++++---
.../UnitTests/Channels/BinaryEncoderTests.cs | 4 +-
.../UnitTests/DictionaryStoreTests.cs | 4 +-
.../UnitTests/ErrorsContainerTests.cs | 4 +-
.../UnitTests/ExpandedNodeIdTests.cs | 8 +--
UaClient.UnitTests/UnitTests/NodeIdTests.cs | 17 +++---
.../UnitTests/QualifiedNameTests.cs | 8 +--
.../UnitTests/ServiceExtensionsTests.cs | 8 +--
.../UnitTests/ServiceSetTests.cs | 56 +++++++++----------
.../Workstation.UaClient.UnitTests.csproj | 20 +++----
UaClient/Workstation.UaClient.csproj | 26 ++++-----
14 files changed, 106 insertions(+), 105 deletions(-)
diff --git a/UaClient.UnitTests/UnitTests/ArraySegmentExtensionTests.cs b/UaClient.UnitTests/UnitTests/ArraySegmentExtensionTests.cs
index 9f5c748..9e061c2 100644
--- a/UaClient.UnitTests/UnitTests/ArraySegmentExtensionTests.cs
+++ b/UaClient.UnitTests/UnitTests/ArraySegmentExtensionTests.cs
@@ -84,7 +84,7 @@ public void CreateBinaryWriter()
}
array
- .Should().BeEquivalentTo(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
+ .Should().BeEquivalentTo(new byte[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
}
}
diff --git a/UaClient.UnitTests/UnitTests/Channels/BinaryDecoderTests.Equivalency.cs b/UaClient.UnitTests/UnitTests/Channels/BinaryDecoderTests.Equivalency.cs
index d34fb60..593d9d0 100644
--- a/UaClient.UnitTests/UnitTests/Channels/BinaryDecoderTests.Equivalency.cs
+++ b/UaClient.UnitTests/UnitTests/Channels/BinaryDecoderTests.Equivalency.cs
@@ -12,6 +12,7 @@
using Workstation.ServiceModel.Ua;
using Workstation.ServiceModel.Ua.Channels;
using Xunit;
+using Newtonsoft.Json.Linq;
namespace Workstation.UaClient.UnitTests.Channels
{
@@ -19,19 +20,19 @@ public partial class BinaryDecoderTests
{
private abstract class TypeMappingEquivalency : IEquivalencyStep
{
- public bool CanHandle(IEquivalencyValidationContext context,
- IEquivalencyAssertionOptions config)
- => context.Subject is TSubject && context.Expectation is TExpectation;
- public bool Handle(IEquivalencyValidationContext context, IEquivalencyValidator
- parent, IEquivalencyAssertionOptions config)
+ public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, IEquivalencyValidator nestedValidator)
{
- var subject = (TSubject)context.Subject;
- var expectation = (TExpectation)context.Expectation;
+ if (comparands.Subject is TSubject subject)
+ {
+ if (comparands.Expectation is TExpectation expectation)
+ {
+ Test(subject, expectation, context.Reason.FormattedMessage, context.Reason.Arguments);
+ return EquivalencyResult.AssertionCompleted;
+ }
+ }
+ return EquivalencyResult.ContinueWithNext;
- Test(subject, expectation, context.Because, context.BecauseArgs);
-
- return true;
}
protected abstract void Test(TSubject subject, TExpectation expectation, string because, object[] becauseArgs);
@@ -45,7 +46,7 @@ protected override void Test(Guid subject, Opc.Ua.Uuid expectation, string becau
.Should().Be((Guid)expectation);
}
}
-
+
private class VariantEquivalency : TypeMappingEquivalency
{
protected override void Test(Variant subject, Opc.Ua.Variant expectation, string because, object[] becauseArgs)
@@ -166,7 +167,7 @@ private class XmlEquivalency : TypeMappingEquivalency
protected override void Test(XElement subject, XmlElement expectation, string because, object[] becauseArgs)
{
var xml = ToXmlNode(subject);
-
+
xml
.Should().BeEquivalentTo(expectation, because, becauseArgs);
}
@@ -201,7 +202,7 @@ static BinaryDecoderTests()
// NodeId
AssertionOptions.AssertEquivalencyUsing(options => options.Using(new NodeIdEquivalency()));
-
+
// ExpandedNodeId
AssertionOptions.AssertEquivalencyUsing(options => options.Using(new ExpandedNodeIdEquivalency()));
@@ -216,7 +217,7 @@ static BinaryDecoderTests()
// TimeZoneDataType
AssertionOptions.AssertEquivalencyUsing(options => options.ComparingByMembers().ExcludingMissingMembers());
-
+
// Matrix/Multidim array
AssertionOptions.AssertEquivalencyUsing(options => options.Using(new MatrixEquivalency()));
}
diff --git a/UaClient.UnitTests/UnitTests/Channels/BinaryDecoderTests.cs b/UaClient.UnitTests/UnitTests/Channels/BinaryDecoderTests.cs
index 6186806..7a1880a 100644
--- a/UaClient.UnitTests/UnitTests/Channels/BinaryDecoderTests.cs
+++ b/UaClient.UnitTests/UnitTests/Channels/BinaryDecoderTests.cs
@@ -49,8 +49,8 @@ public void CreateWithNullStream()
{
Stream stream = null;
- stream.Invoking(s => new BinaryDecoder(s))
- .Should().Throw();
+ Action act = () => new BinaryDecoder(stream);
+ act.Should().Throw();
}
[InlineData(true)]
diff --git a/UaClient.UnitTests/UnitTests/Channels/BinaryEncoderTests.Equivalency.cs b/UaClient.UnitTests/UnitTests/Channels/BinaryEncoderTests.Equivalency.cs
index 8142ae3..270f460 100644
--- a/UaClient.UnitTests/UnitTests/Channels/BinaryEncoderTests.Equivalency.cs
+++ b/UaClient.UnitTests/UnitTests/Channels/BinaryEncoderTests.Equivalency.cs
@@ -19,19 +19,18 @@ public partial class BinaryEncoderTests
{
private abstract class TypeMappingEquivalency : IEquivalencyStep
{
- public bool CanHandle(IEquivalencyValidationContext context,
- IEquivalencyAssertionOptions config)
- => context.Subject is TSubject && context.Expectation is TExpectation;
- public bool Handle(IEquivalencyValidationContext context, IEquivalencyValidator
- parent, IEquivalencyAssertionOptions config)
+ public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, IEquivalencyValidator nestedValidator)
{
- var subject = (TSubject)context.Subject;
- var expectation = (TExpectation)context.Expectation;
-
- Test(subject, expectation, context.Because, context.BecauseArgs);
-
- return true;
+ if (comparands.Subject is TSubject subject)
+ {
+ if (comparands.Expectation is TExpectation expectation)
+ {
+ Test(subject, expectation, context.Reason.FormattedMessage, context.Reason.Arguments);
+ return EquivalencyResult.AssertionCompleted;
+ }
+ }
+ return EquivalencyResult.ContinueWithNext;
}
protected abstract void Test(TSubject subject, TExpectation expectation, string because, object[] becauseArgs);
diff --git a/UaClient.UnitTests/UnitTests/Channels/BinaryEncoderTests.cs b/UaClient.UnitTests/UnitTests/Channels/BinaryEncoderTests.cs
index ccfbd34..43f39e7 100644
--- a/UaClient.UnitTests/UnitTests/Channels/BinaryEncoderTests.cs
+++ b/UaClient.UnitTests/UnitTests/Channels/BinaryEncoderTests.cs
@@ -33,8 +33,8 @@ public void CreateWithNullStream()
{
Stream stream = null;
- stream.Invoking(s => new BinaryEncoder(s))
- .Should().Throw();
+ Action act = () => new BinaryEncoder(stream);
+ act.Should().Throw();
}
[InlineData(true)]
diff --git a/UaClient.UnitTests/UnitTests/DictionaryStoreTests.cs b/UaClient.UnitTests/UnitTests/DictionaryStoreTests.cs
index 96d7a02..4a1283b 100644
--- a/UaClient.UnitTests/UnitTests/DictionaryStoreTests.cs
+++ b/UaClient.UnitTests/UnitTests/DictionaryStoreTests.cs
@@ -29,8 +29,8 @@ public void Constructor()
[Theory]
public void ConstructorNull(string dir)
{
- dir.Invoking(d => new DirectoryStore(d))
- .Should().Throw();
+ Action act = () => new DirectoryStore(dir);
+ act.Should().Throw();
}
[Fact]
diff --git a/UaClient.UnitTests/UnitTests/ErrorsContainerTests.cs b/UaClient.UnitTests/UnitTests/ErrorsContainerTests.cs
index 2e72e62..4b47ee5 100644
--- a/UaClient.UnitTests/UnitTests/ErrorsContainerTests.cs
+++ b/UaClient.UnitTests/UnitTests/ErrorsContainerTests.cs
@@ -39,8 +39,8 @@ public void CreateNull()
{
Action action = null;
- action.Invoking(a => new ErrorsContainer(a))
- .Should().Throw();
+ Action act = () => new ErrorsContainer(action);
+ act.Should().Throw();
}
[MemberData(nameof(TestProperties))]
diff --git a/UaClient.UnitTests/UnitTests/ExpandedNodeIdTests.cs b/UaClient.UnitTests/UnitTests/ExpandedNodeIdTests.cs
index 016b545..0889560 100644
--- a/UaClient.UnitTests/UnitTests/ExpandedNodeIdTests.cs
+++ b/UaClient.UnitTests/UnitTests/ExpandedNodeIdTests.cs
@@ -308,8 +308,8 @@ public static IEnumerable