From 2e6bdf72efca754763348605b177e895be0ce46d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96hlund?= Date: Wed, 6 Mar 2024 21:26:04 +0100 Subject: [PATCH] Prepare for RTM (#481) * Prepare for RTM * Tweaks --------- Co-authored-by: Brandon Ording --- .github/workflows/ci.yml | 1 - .github/workflows/release.yml | 1 - src/AcceptanceTests/AcceptanceTests.csproj | 48 ++++++------ .../APIApprovals.cs | 2 +- ...iceBus.UniformSession.Testing.Tests.csproj | 7 +- .../NServiceBus.UniformSession.Testing.csproj | 7 +- .../TestableUniformSession.cs | 24 +++++- src/Tests/APIApprovals.cs | 2 +- src/Tests/Tests.csproj | 2 +- src/UniformSession/Guard.cs | 77 ------------------- .../NServiceBus.UniformSession.csproj | 2 +- .../UniformSessionExtensions.cs | 38 ++++----- 12 files changed, 75 insertions(+), 136 deletions(-) delete mode 100644 src/UniformSession/Guard.cs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 04f1939..035b68e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,7 +29,6 @@ jobs: uses: actions/setup-dotnet@v4.0.0 with: dotnet-version: 8.0.x - dotnet-quality: 'preview' - name: Build run: dotnet build src --configuration Release - name: Upload packages diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1c3e8cd..b9369dd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,6 @@ jobs: uses: actions/setup-dotnet@v4.0.0 with: dotnet-version: 8.0.x - dotnet-quality: 'preview' - name: Build run: dotnet build src --configuration Release - name: Sign NuGet packages diff --git a/src/AcceptanceTests/AcceptanceTests.csproj b/src/AcceptanceTests/AcceptanceTests.csproj index 8bbed9c..0ecbec8 100644 --- a/src/AcceptanceTests/AcceptanceTests.csproj +++ b/src/AcceptanceTests/AcceptanceTests.csproj @@ -12,34 +12,34 @@ - + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/NServiceBus.UniformSession.Testing.Tests/APIApprovals.cs b/src/NServiceBus.UniformSession.Testing.Tests/APIApprovals.cs index 3d039fd..a1f53c9 100644 --- a/src/NServiceBus.UniformSession.Testing.Tests/APIApprovals.cs +++ b/src/NServiceBus.UniformSession.Testing.Tests/APIApprovals.cs @@ -11,7 +11,7 @@ public void Approve() { var publicApi = typeof(TestableUniformSession).Assembly.GeneratePublicApi(new ApiGeneratorOptions { - ExcludeAttributes = new[] { "System.Runtime.Versioning.TargetFrameworkAttribute", "System.Reflection.AssemblyMetadataAttribute" } + ExcludeAttributes = ["System.Runtime.Versioning.TargetFrameworkAttribute", "System.Reflection.AssemblyMetadataAttribute"] }); Approver.Verify(publicApi); diff --git a/src/NServiceBus.UniformSession.Testing.Tests/NServiceBus.UniformSession.Testing.Tests.csproj b/src/NServiceBus.UniformSession.Testing.Tests/NServiceBus.UniformSession.Testing.Tests.csproj index 0e0119a..ccb51e1 100644 --- a/src/NServiceBus.UniformSession.Testing.Tests/NServiceBus.UniformSession.Testing.Tests.csproj +++ b/src/NServiceBus.UniformSession.Testing.Tests/NServiceBus.UniformSession.Testing.Tests.csproj @@ -1,4 +1,4 @@ - + net8.0 @@ -6,14 +6,13 @@ - - - + + diff --git a/src/NServiceBus.UniformSession.Testing/NServiceBus.UniformSession.Testing.csproj b/src/NServiceBus.UniformSession.Testing/NServiceBus.UniformSession.Testing.csproj index 7e97b37..ef10c62 100644 --- a/src/NServiceBus.UniformSession.Testing/NServiceBus.UniformSession.Testing.csproj +++ b/src/NServiceBus.UniformSession.Testing/NServiceBus.UniformSession.Testing.csproj @@ -1,10 +1,9 @@ - + net8.0 true - $(SolutionDir)NServiceBus.snk - $(NoWarn);CS1591 + ..\NServiceBus.snk NServiceBus Uniform Session Testing @@ -13,7 +12,7 @@ - + diff --git a/src/NServiceBus.UniformSession.Testing/TestableUniformSession.cs b/src/NServiceBus.UniformSession.Testing/TestableUniformSession.cs index c8bc639..bb70d33 100644 --- a/src/NServiceBus.UniformSession.Testing/TestableUniformSession.cs +++ b/src/NServiceBus.UniformSession.Testing/TestableUniformSession.cs @@ -5,27 +5,47 @@ using System.Threading.Tasks; using NServiceBus.Testing; + /// + /// A testable implementation of . + /// public class TestableUniformSession : IUniformSession { - TestablePipelineContext innerContext; - TestableMessageSession innerSession; + readonly TestablePipelineContext innerContext; + readonly TestableMessageSession innerSession; + /// + /// Creates a new instance of . + /// public TestableUniformSession() : this(new TestablePipelineContext()) { } + /// + /// Creates a new instance of . + /// + /// The the session should use to send and publish messages. public TestableUniformSession(TestableMessageSession innerSession) { this.innerSession = innerSession; } + /// + /// Creates a new instance of . + /// + /// The the session should use to send and publish messages. public TestableUniformSession(TestablePipelineContext innerContext) { this.innerContext = innerContext; } + /// + /// The messages that have been sent from the session. + /// public SentMessage[] SentMessages => innerContext?.SentMessages ?? innerSession.SentMessages; + /// + /// The messages that have been published from the session. + /// public PublishedMessage[] PublishedMessages => innerContext?.PublishedMessages ?? innerSession.PublishedMessages; Task IUniformSession.Send(object message, SendOptions options, CancellationToken cancellationToken) diff --git a/src/Tests/APIApprovals.cs b/src/Tests/APIApprovals.cs index 6fd67c7..f7a0cc2 100644 --- a/src/Tests/APIApprovals.cs +++ b/src/Tests/APIApprovals.cs @@ -13,7 +13,7 @@ public void Approve() { var publicApi = typeof(IUniformSession).Assembly.GeneratePublicApi(new ApiGeneratorOptions { - ExcludeAttributes = new[] { "System.Runtime.Versioning.TargetFrameworkAttribute", "System.Reflection.AssemblyMetadataAttribute" } + ExcludeAttributes = ["System.Runtime.Versioning.TargetFrameworkAttribute", "System.Reflection.AssemblyMetadataAttribute"] }); Approver.Verify(publicApi); } diff --git a/src/Tests/Tests.csproj b/src/Tests/Tests.csproj index 0c57309..34f831d 100644 --- a/src/Tests/Tests.csproj +++ b/src/Tests/Tests.csproj @@ -13,7 +13,7 @@ - + diff --git a/src/UniformSession/Guard.cs b/src/UniformSession/Guard.cs deleted file mode 100644 index 7439f75..0000000 --- a/src/UniformSession/Guard.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System; -using System.Collections; -using System.Linq; -using System.Reflection; - -static class Guard -{ - public static void TypeHasDefaultConstructor(Type type, string argumentName) - { - if (type.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) - .All(ctor => ctor.GetParameters().Length != 0)) - { - var error = $"Type '{type.FullName}' must have a default constructor."; - throw new ArgumentException(error, argumentName); - } - } - - public static void AgainstNull(string argumentName, object value) - { - if (value == null) - { - throw new ArgumentNullException(argumentName); - } - } - - public static void AgainstNullAndEmpty(string argumentName, string value) - { - if (string.IsNullOrWhiteSpace(value)) - { - throw new ArgumentNullException(argumentName); - } - } - - public static void AgainstNullAndEmpty(string argumentName, ICollection value) - { - if (value == null) - { - throw new ArgumentNullException(argumentName); - } - if (value.Count == 0) - { - throw new ArgumentOutOfRangeException(argumentName); - } - } - - public static void AgainstNegativeAndZero(string argumentName, int value) - { - if (value <= 0) - { - throw new ArgumentOutOfRangeException(argumentName); - } - } - - public static void AgainstNegative(string argumentName, int value) - { - if (value < 0) - { - throw new ArgumentOutOfRangeException(argumentName); - } - } - - public static void AgainstNegativeAndZero(string argumentName, TimeSpan value) - { - if (value <= TimeSpan.Zero) - { - throw new ArgumentOutOfRangeException(argumentName); - } - } - - public static void AgainstNegative(string argumentName, TimeSpan value) - { - if (value < TimeSpan.Zero) - { - throw new ArgumentOutOfRangeException(argumentName); - } - } -} \ No newline at end of file diff --git a/src/UniformSession/NServiceBus.UniformSession.csproj b/src/UniformSession/NServiceBus.UniformSession.csproj index 92e495e..7035855 100644 --- a/src/UniformSession/NServiceBus.UniformSession.csproj +++ b/src/UniformSession/NServiceBus.UniformSession.csproj @@ -8,7 +8,7 @@ - + diff --git a/src/UniformSession/UniformSessionExtensions.cs b/src/UniformSession/UniformSessionExtensions.cs index caa91b0..f3ad4ec 100644 --- a/src/UniformSession/UniformSessionExtensions.cs +++ b/src/UniformSession/UniformSessionExtensions.cs @@ -17,8 +17,8 @@ public static class UniformSessionExtensions /// A to observe. public static Task Send(this IUniformSession session, object message, CancellationToken cancellationToken = default) { - Guard.AgainstNull(nameof(session), session); - Guard.AgainstNull(nameof(message), message); + ArgumentNullException.ThrowIfNull(session); + ArgumentNullException.ThrowIfNull(message); return session.Send(message, new SendOptions(), cancellationToken); } @@ -35,8 +35,8 @@ public static Task Send(this IUniformSession session, object message, Cancellati /// public static Task Send(this IUniformSession session, Action messageConstructor, CancellationToken cancellationToken = default) { - Guard.AgainstNull(nameof(session), session); - Guard.AgainstNull(nameof(messageConstructor), messageConstructor); + ArgumentNullException.ThrowIfNull(session); + ArgumentNullException.ThrowIfNull(messageConstructor); return session.Send(messageConstructor, new SendOptions(), cancellationToken); } @@ -50,9 +50,9 @@ public static Task Send(this IUniformSession session, Action messageConstr /// A to observe. public static Task Send(this IUniformSession session, string destination, object message, CancellationToken cancellationToken = default) { - Guard.AgainstNull(nameof(session), session); - Guard.AgainstNullAndEmpty(nameof(destination), destination); - Guard.AgainstNull(nameof(message), message); + ArgumentNullException.ThrowIfNull(session); + ArgumentException.ThrowIfNullOrWhiteSpace(destination); + ArgumentNullException.ThrowIfNull(message); var options = new SendOptions(); @@ -71,9 +71,9 @@ public static Task Send(this IUniformSession session, string destination, object /// A to observe. public static Task Send(this IUniformSession session, string destination, Action messageConstructor, CancellationToken cancellationToken = default) { - Guard.AgainstNull(nameof(session), session); - Guard.AgainstNullAndEmpty(nameof(destination), destination); - Guard.AgainstNull(nameof(messageConstructor), messageConstructor); + ArgumentNullException.ThrowIfNull(session); + ArgumentException.ThrowIfNullOrWhiteSpace(destination); + ArgumentNullException.ThrowIfNull(messageConstructor); var options = new SendOptions(); @@ -90,8 +90,8 @@ public static Task Send(this IUniformSession session, string destination, Act /// A to observe. public static Task SendLocal(this IUniformSession session, object message, CancellationToken cancellationToken = default) { - Guard.AgainstNull(nameof(session), session); - Guard.AgainstNull(nameof(message), message); + ArgumentNullException.ThrowIfNull(session); + ArgumentNullException.ThrowIfNull(message); var options = new SendOptions(); @@ -109,8 +109,8 @@ public static Task SendLocal(this IUniformSession session, object message, Cance /// A to observe. public static Task SendLocal(this IUniformSession session, Action messageConstructor, CancellationToken cancellationToken = default) { - Guard.AgainstNull(nameof(session), session); - Guard.AgainstNull(nameof(messageConstructor), messageConstructor); + ArgumentNullException.ThrowIfNull(session); + ArgumentNullException.ThrowIfNull(messageConstructor); var options = new SendOptions(); @@ -127,8 +127,8 @@ public static Task SendLocal(this IUniformSession session, Action messageC /// A to observe. public static Task Publish(this IUniformSession session, object message, CancellationToken cancellationToken = default) { - Guard.AgainstNull(nameof(session), session); - Guard.AgainstNull(nameof(message), message); + ArgumentNullException.ThrowIfNull(session); + ArgumentNullException.ThrowIfNull(message); return session.Publish(message, new PublishOptions(), cancellationToken); } @@ -141,7 +141,7 @@ public static Task Publish(this IUniformSession session, object message, Cancell /// The message type. public static Task Publish(this IUniformSession session, CancellationToken cancellationToken = default) { - Guard.AgainstNull(nameof(session), session); + ArgumentNullException.ThrowIfNull(session); return session.Publish(_ => { }, new PublishOptions(), cancellationToken); } @@ -155,8 +155,8 @@ public static Task Publish(this IUniformSession session, CancellationToken ca /// A to observe. public static Task Publish(this IUniformSession session, Action messageConstructor, CancellationToken cancellationToken = default) { - Guard.AgainstNull(nameof(session), session); - Guard.AgainstNull(nameof(messageConstructor), messageConstructor); + ArgumentNullException.ThrowIfNull(session); + ArgumentNullException.ThrowIfNull(messageConstructor); return session.Publish(messageConstructor, new PublishOptions(), cancellationToken); }