Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update target frameworks and other infrastructure changes #831

Merged
merged 9 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,20 @@ jobs:
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macOS-latest]
framework: [net6.0, net7.0, net8.0]
framework: [net8.0]
include:
- os: windows-latest
framework: net462

runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x

- name: Build
Expand All @@ -38,16 +36,14 @@ jobs:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x

# used for documentation
Expand All @@ -64,10 +60,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

Expand Down
23 changes: 15 additions & 8 deletions BreakingChanges.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
6.0.0 Release
================

* Update target frameworks: .NET 8, .NET Standard 2.0.
* Obsolete api is removed
* CompatArg is marked as obsolete

5.0.0 Release
================

Expand Down Expand Up @@ -91,7 +98,7 @@ Workaround: Use `NSubstitute.Received.InOrder`.

Signed v3.x package to fix libraries that work with a mix of NSubstitute verisons. See #324.

3.0.0 Release
3.0.0 Release
================

NOTE: unsigned. Fixed in 3.0.1.
Expand All @@ -108,15 +115,15 @@ Standard 1.3 compatible target such as .NET 4.6 or later. See compatibility matr
https://github.com/dotnet/standard/blob/master/docs/versions.md


1.10.0 Release
1.10.0 Release
================

Substitutes will now automatically return an empty `IQueryable<T>` for
members that return that type. Tests previously relying on a
substitute `IQueryable<T>` will no longer work properly.

Reason:
- Code that uses an `IQueryable<T>` can now run using the auto-subbed
- Code that uses an `IQueryable<T>` can now run using the auto-subbed
value without causing null pointer exceptions (see issue #67).

Fix:
Expand All @@ -128,10 +135,10 @@ to return a real `IQueryable<T>` instead. If a substitute is required, explicitl
```


1.9.1 Release
1.9.1 Release
================

Substitutes set up to throw exception for methods with return type Task<T>
Substitutes set up to throw exception for methods with return type Task<T>
cause compilation to fail due to the call being ambiguous (CS0121).
"The call is ambiguous between the following methods or properties:
`.Returns<Task<T>>` and `.Returns<T>`"
Expand All @@ -146,7 +153,7 @@ Fix:

New: `sub.Method().Returns<string>(x => { throw new Exception() });`

1.8.0 Release
1.8.0 Release
================

Incorrect use of argument matchers outside of a member call, particularly within a
Expand Down Expand Up @@ -214,7 +221,7 @@ Fix:

---------------

In rare cases the new `Returns()` and `ReturnsForAnyArgs()` overloads can cause compilation to fail due to the call being ambiguous (CS0121).
In rare cases the new `Returns()` and `ReturnsForAnyArgs()` overloads can cause compilation to fail due to the call being ambiguous (CS0121).

Reason:
- The new overloads allow a sequence of callbacks to be used for return values. A common example is return several values, then throwing an exception.
Expand All @@ -229,7 +236,7 @@ Fix:
Auto-substitute from substitutes of `Func` delegates (following the same rules as auto-subbing for methods and properties). So the delegate returned from `Substitute.For<Func<IFoo>>()` will return a substitute of `IFoo`. This means some substitutes for delegates that used to return null will now return a new substitute.

Reason:
- Reduced setup when substituting for `Func` delegates, and consistency with behaviour for properties and methods.
- Reduced setup when substituting for `Func` delegates, and consistency with behaviour for properties and methods.

Fix:
- Explicitly return null from substitute delegates when required for a test.
Expand Down
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
### 6.x (work in progress)

* [UPDATE] Update target frameworks: .NET8, .NET Standard 2.0
* [UPDATE] Drop EOL .NET 6/7 platforms from testing matrix
* [UPDATE] Update github actions steps versions
* [UPDATE] Remove legacy obsolete API
* [UPDATE] Mark as obsolete api CompatArg with pre c# 7.0 support
dtchepak marked this conversation as resolved.
Show resolved Hide resolved


### 5.3.0 (October 2024)

* [NEW] Introduced `Substitute.ForTypeForwardingTo` to create substitutes that forward interceptable calls to a concrete class. This provides an easy way of implementing a test spy over an existing type. Designed and implemented by @marcoregueira in https://github.com/nsubstitute/NSubstitute/pull/700 from a proposal by @wsaeed. Thanks to all who contributed to discussions of this feature.
Expand Down Expand Up @@ -40,7 +49,7 @@ Many thanks to @alexandrnikitin, @Romfos, @brad, and @304NotModified for their c

### 4.4.0 (Jul 2022)

* [FIX] Fix issue checking for constructor args on null object. Thanks to @phongphanq, and @appel1! Thanks also to
* [FIX] Fix issue checking for constructor args on null object. Thanks to @phongphanq, and @appel1! Thanks also to
@Mandroide for code review. (#683, #685)
* [UPDATE] Update to Castle Core v5. Thanks @Havunen! (#690, #673)
* [NEW] Add `.ThrowsAsync()` that will correctly mock exception on async methods. Thanks @Socolin! (#609, #663)
Expand Down
6 changes: 0 additions & 6 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
See more here https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build?view=vs-2019 -->

<PropertyGroup>
<TargetIsNetFx Condition="$(TargetFramework.StartsWith('net4'))">true</TargetIsNetFx>
<TargetIsNet5OrNewer Condition="'$(TargetFramework)' == 'net6.0'">true</TargetIsNet5OrNewer>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand All @@ -15,8 +13,4 @@
<OutputPath>$(MSBuildThisFileDirectory)\bin\$(Configuration)\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>

<ItemGroup Condition="'$(TargetIsNetFx)' == 'true'">
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="All" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions src/NSubstitute/Compatibility/CompatArg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace NSubstitute.Compatibility;
/// For more information see <see href="https://nsubstitute.github.io/help/compat-args">Compatibility Argument
/// Matchers</see> in the NSubstitute documentation.
/// </summary>
[Obsolete("This api is deprecated and will be removed in future versions of product.")]
public class CompatArg
{
private CompatArg() { }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !SYSTEM_DIAGNOSTICS_CODEANALYSIS_NULLABILITY
#if NETSTANDARD2_0

// This was copied from https://github.com/dotnet/runtime/blob/39b9607807f29e48cae4652cd74735182b31182e/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/NullableAttributes.cs
// and updated to have the scope of the attributes be internal.
Expand Down
39 changes: 5 additions & 34 deletions src/NSubstitute/Core/Argument.cs
Original file line number Diff line number Diff line change
@@ -1,47 +1,18 @@
namespace NSubstitute.Core;

public class Argument
public class Argument(ICall call, int argIndex)
{
private readonly ICall? _call;
private readonly int _argIndex;

private readonly Type? _declaredType;
private readonly Func<object?>? _getValue;
private readonly Action<object?>? _setValue;

[Obsolete("This constructor overload is deprecated and will be removed in the next version.")]
public Argument(Type declaredType, Func<object?> getValue, Action<object?> setValue)
{
_declaredType = declaredType;
_getValue = getValue;
_setValue = setValue;
}

public Argument(ICall call, int argIndex)
{
_call = call;
_argIndex = argIndex;
}
private readonly ICall? _call = call;

public object? Value
{
get => _getValue != null ? _getValue() : _call!.GetArguments()[_argIndex];
set
{
if (_setValue != null)
{
_setValue(value);
}
else
{
_call!.GetArguments()[_argIndex] = value;
}
}
get => _call!.GetArguments()[argIndex];
set => _call!.GetArguments()[argIndex] = value;
}

public bool IsByRef => DeclaredType.IsByRef;

public Type DeclaredType => _declaredType ?? _call!.GetParameterInfos()[_argIndex].ParameterType;
public Type DeclaredType => _call!.GetParameterInfos()[argIndex].ParameterType;

public Type ActualType => Value == null ? DeclaredType : Value.GetType();

Expand Down
8 changes: 1 addition & 7 deletions src/NSubstitute/Core/ArgumentSpecificationDequeue.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using NSubstitute.Core.Arguments;
using NSubstitute.Core.Arguments;

namespace NSubstitute.Core;

Expand All @@ -20,9 +19,4 @@ public IList<IArgumentSpecification> DequeueAllArgumentSpecificationsForMethod(i
var queuedArgSpecifications = dequeueAllQueuedArgSpecs.Invoke();
return queuedArgSpecifications;
}

public IList<IArgumentSpecification> DequeueAllArgumentSpecificationsForMethod(MethodInfo methodInfo)
{
return DequeueAllArgumentSpecificationsForMethod(methodInfo.GetParameters().Length);
}
}
17 changes: 3 additions & 14 deletions src/NSubstitute/Core/Call.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Reflection;
using NSubstitute.Core.Arguments;
using NSubstitute.Exceptions;
using System.Reflection;

namespace NSubstitute.Core;

Expand All @@ -15,19 +15,8 @@ public class Call : ICall, /* Performance optimization */ CallCollection.IReceiv
private long? _sequenceNumber;
private readonly Func<object>? _baseMethod;

[Obsolete("This constructor is deprecated and will be removed in future version of product.")]
public Call(MethodInfo methodInfo,
object?[] arguments,
object target,
IList<IArgumentSpecification> argumentSpecifications,
IParameterInfo[] parameterInfos,
Func<object> baseMethod)
: this(methodInfo, arguments, target, argumentSpecifications, baseMethod)
{
_parameterInfosCached = parameterInfos ?? throw new ArgumentNullException(nameof(parameterInfos));
}

public Call(MethodInfo methodInfo,
public Call(
MethodInfo methodInfo,
object?[] arguments,
object target,
IList<IArgumentSpecification> argumentSpecifications,
Expand Down
3 changes: 0 additions & 3 deletions src/NSubstitute/Core/CallRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ public IEnumerable<ICall> ReceivedCalls()
return substituteState.ReceivedCalls.AllCalls();
}

public void SetRoute(Func<ISubstituteState, IRoute> getRoute) =>
threadContext.SetNextRoute(this, getRoute);

public object? Route(ICall call)
{
threadContext.SetLastCallRouter(this);
Expand Down

This file was deleted.

6 changes: 1 addition & 5 deletions src/NSubstitute/Core/IArgumentSpecificationDequeue.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using System.Reflection;
using NSubstitute.Core.Arguments;
using NSubstitute.Core.Arguments;

namespace NSubstitute.Core;

public interface IArgumentSpecificationDequeue
{
[Obsolete("This method is deprecated and will be removed in future versions of product.")]
IList<IArgumentSpecification> DequeueAllArgumentSpecificationsForMethod(MethodInfo methodInfo);

IList<IArgumentSpecification> DequeueAllArgumentSpecificationsForMethod(int parametersCount);
}
5 changes: 0 additions & 5 deletions src/NSubstitute/Core/ICallRouter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using NSubstitute.Routing;

namespace NSubstitute.Core;

public interface ICallRouter
Expand All @@ -15,9 +13,6 @@ public interface ICallRouter
ConfiguredCall LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs, PendingSpecificationInfo pendingSpecInfo);
object? Route(ICall call);
IEnumerable<ICall> ReceivedCalls();
[Obsolete("This method is deprecated and will be removed in future versions of the product. " +
"Please use " + nameof(IThreadLocalContext) + "." + nameof(IThreadLocalContext.SetNextRoute) + " method instead.")]
void SetRoute(Func<ISubstituteState, IRoute> getRoute);
void SetReturnForType(Type type, IReturn returnValue);
void RegisterCustomCallHandlerFactory(CallHandlerFactory factory);
void Clear(ClearOptions clear);
Expand Down
Loading
Loading