diff --git a/.github/workflows/release_packages.yml b/.github/workflows/release_packages.yml index 1a8bf1eb..773eea94 100644 --- a/.github/workflows/release_packages.yml +++ b/.github/workflows/release_packages.yml @@ -15,13 +15,13 @@ jobs: dotnet-version: 9.0.x - name: Build package - run: dotnet pack src/NSubstitute/NSubstitute.csproj -p:CI=true + run: dotnet pack src/NSubstitute/NSubstitute.csproj -o bin -p:CI=true - name: Upload packages uses: actions/upload-artifact@v4 with: name: packages path: | - bin/Release/NSubstitute/*.nupkg - bin/Release/NSubstitute/*.snupkg + bin/*.nupkg + bin/*.snupkg retention-days: 7 \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index faf7574b..fe70426f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * [UPDATE] Migrate to slnx format for solution file * [UPDATE] Migrate documentation validation from build.fsproj to Roslyn code generator * [NEW] Added NuGet Package README file. +* [UPDATE] Make public api and tests the same for all TFMs ### 5.3.0 (October 2024) diff --git a/src/NSubstitute/Extensions/ExceptionExtensions.cs b/src/NSubstitute/Extensions/ExceptionExtensions.cs index 41968ce1..655706cb 100644 --- a/src/NSubstitute/Extensions/ExceptionExtensions.cs +++ b/src/NSubstitute/Extensions/ExceptionExtensions.cs @@ -161,7 +161,6 @@ public static ConfiguredCall ThrowsAsyncForAnyArgs(this Task value, Func(this Task value, Func createException) => value.ReturnsForAnyArgs(ci => Task.FromException(createException(ci))); -#if NET5_0_OR_GREATER /// /// Throw an exception for this call. /// @@ -169,7 +168,11 @@ public static ConfiguredCall ThrowsAsyncForAnyArgs(this Task value, FuncException to throw /// public static ConfiguredCall ThrowsAsync(this ValueTask value, Exception ex) => +#if NETSTANDARD2_0 + value.Returns(_ => new ValueTask(Task.FromException(ex))); +#else value.Returns(_ => ValueTask.FromException(ex)); +#endif /// /// Throw an exception of the given type for this call. @@ -181,7 +184,11 @@ public static ConfiguredCall ThrowsAsync(this ValueTask value, Exception e public static ConfiguredCall ThrowsAsync(this ValueTask value) where TException : notnull, Exception, new() { +#if NETSTANDARD2_0 + return value.Returns(_ => new ValueTask(Task.FromException(new TException()))); +#else return value.Returns(_ => ValueTask.FromException(new TException())); +#endif } /// @@ -191,7 +198,11 @@ public static ConfiguredCall ThrowsAsync(this ValueTaskFunc creating exception object /// public static ConfiguredCall ThrowsAsync(this ValueTask value, Func createException) => +#if NETSTANDARD2_0 + value.Returns(ci => new ValueTask(Task.FromException(createException(ci)))); +#else value.Returns(ci => ValueTask.FromException(createException(ci))); +#endif /// /// Throws an exception of the given type for this call made with any arguments. @@ -203,7 +214,11 @@ public static ConfiguredCall ThrowsAsync(this ValueTask value, Func(this ValueTask value) where TException : notnull, Exception, new() { +#if NETSTANDARD2_0 + return value.ReturnsForAnyArgs(_ => new ValueTask(Task.FromException(new TException()))); +#else return value.ReturnsForAnyArgs(_ => ValueTask.FromException(new TException())); +#endif } /// @@ -213,7 +228,11 @@ public static ConfiguredCall ThrowsAsyncForAnyArgs(this ValueTask /// Exception to throw /// public static ConfiguredCall ThrowsAsyncForAnyArgs(this ValueTask value, Exception ex) => +#if NETSTANDARD2_0 + value.ReturnsForAnyArgs(_ => new ValueTask(Task.FromException(ex))); +#else value.ReturnsForAnyArgs(_ => ValueTask.FromException(ex)); +#endif /// /// Throws an exception for this call made with any arguments, as generated by the specified function. @@ -222,7 +241,11 @@ public static ConfiguredCall ThrowsAsyncForAnyArgs(this ValueTask value, E /// Func creating exception object /// public static ConfiguredCall ThrowsAsyncForAnyArgs(this ValueTask value, Func createException) => +#if NETSTANDARD2_0 + value.ReturnsForAnyArgs(ci => new ValueTask(Task.FromException(createException(ci)))); +#else value.ReturnsForAnyArgs(ci => ValueTask.FromException(createException(ci))); +#endif /// /// Throw an exception for this call. @@ -231,7 +254,11 @@ public static ConfiguredCall ThrowsAsyncForAnyArgs(this ValueTask value, F /// Exception to throw /// public static ConfiguredCall ThrowsAsync(this ValueTask value, Exception ex) => +#if NETSTANDARD2_0 + value.Returns(_ => new ValueTask(Task.FromException(ex))); +#else value.Returns(_ => ValueTask.FromException(ex)); +#endif /// /// Throw an exception of the given type for this call. @@ -242,7 +269,11 @@ public static ConfiguredCall ThrowsAsync(this ValueTask value, Exception ex) => public static ConfiguredCall ThrowsAsync(this ValueTask value) where TException : notnull, Exception, new() { +#if NETSTANDARD2_0 + return value.Returns(_ => new ValueTask(Task.FromException(new TException()))); +#else return value.Returns(_ => ValueTask.FromException(new TException())); +#endif } /// @@ -252,7 +283,11 @@ public static ConfiguredCall ThrowsAsync(this ValueTask value) /// Func creating exception object /// public static ConfiguredCall ThrowsAsync(this ValueTask value, Func createException) => +#if NETSTANDARD2_0 + value.Returns(ci => new ValueTask(Task.FromException(createException(ci)))); +#else value.Returns(ci => ValueTask.FromException(createException(ci))); +#endif /// /// Throws an exception of the given type for this call made with any arguments. @@ -263,7 +298,11 @@ public static ConfiguredCall ThrowsAsync(this ValueTask value, Func(this ValueTask value) where TException : notnull, Exception, new() { +#if NETSTANDARD2_0 + return value.ReturnsForAnyArgs(_ => new ValueTask(Task.FromException(new TException()))); +#else return value.ReturnsForAnyArgs(_ => ValueTask.FromException(new TException())); +#endif } /// @@ -273,7 +312,11 @@ public static ConfiguredCall ThrowsAsyncForAnyArgs(this ValueTask va /// Exception to throw /// public static ConfiguredCall ThrowsAsyncForAnyArgs(this ValueTask value, Exception ex) => +#if NETSTANDARD2_0 + value.ReturnsForAnyArgs(_ => new ValueTask(Task.FromException(ex))); +#else value.ReturnsForAnyArgs(_ => ValueTask.FromException(ex)); +#endif /// /// Throws an exception for this call made with any arguments, as generated by the specified function. @@ -282,6 +325,9 @@ public static ConfiguredCall ThrowsAsyncForAnyArgs(this ValueTask value, Excepti /// Func creating exception object /// public static ConfiguredCall ThrowsAsyncForAnyArgs(this ValueTask value, Func createException) => +#if NETSTANDARD2_0 + value.ReturnsForAnyArgs(ci => new ValueTask(Task.FromException(createException(ci)))); +#else value.ReturnsForAnyArgs(ci => ValueTask.FromException(createException(ci))); #endif diff --git a/src/NSubstitute/NSubstitute.csproj b/src/NSubstitute/NSubstitute.csproj index b2df3bc7..20db4d49 100644 --- a/src/NSubstitute/NSubstitute.csproj +++ b/src/NSubstitute/NSubstitute.csproj @@ -54,7 +54,7 @@ - + diff --git a/tests/NSubstitute.Acceptance.Specs/ThrowingAsyncExceptions.cs b/tests/NSubstitute.Acceptance.Specs/ThrowingAsyncExceptions.cs index 62b5e73e..598f52d7 100644 --- a/tests/NSubstitute.Acceptance.Specs/ThrowingAsyncExceptions.cs +++ b/tests/NSubstitute.Acceptance.Specs/ThrowingAsyncExceptions.cs @@ -207,7 +207,6 @@ public void TearDown() } } -#if NET5_0_OR_GREATER public class ForValueTask { @@ -421,7 +420,6 @@ public static void AssertDoesNotThrow(Func act) Assert.That(actual.IsFaulted, Is.False); } } -#endif public static TException AssertFaultedTaskException(Func act) where TException : Exception