Skip to content

Commit 72d146d

Browse files
authored
Update target frameworks and other infrastructure changes (#831)
* Update target frameworks * Simplify build system * Remove legacy obsolete api * Mark `CompatArg` as obsolete * Update github actions * Update changelogs * Suppress some warnings in tests * Update changelog
1 parent 45e00e3 commit 72d146d

25 files changed

+74
-438
lines changed

Diff for: .github/workflows/build_and_test.yml

+7-11
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,20 @@ jobs:
1010
strategy:
1111
matrix:
1212
os: [windows-latest, ubuntu-latest, macOS-latest]
13-
framework: [net6.0, net7.0, net8.0]
13+
framework: [net8.0]
1414
include:
1515
- os: windows-latest
1616
framework: net462
1717

1818
runs-on: ${{ matrix.os }}
1919
steps:
2020
- name: Checkout
21-
uses: actions/checkout@v3
21+
uses: actions/checkout@v4
2222

2323
- name: Setup .NET
24-
uses: actions/setup-dotnet@v3
24+
uses: actions/setup-dotnet@v4
2525
with:
2626
dotnet-version: |
27-
6.0.x
28-
7.0.x
2927
8.0.x
3028
3129
- name: Build
@@ -38,16 +36,14 @@ jobs:
3836
runs-on: windows-latest
3937
steps:
4038
- name: Checkout
41-
uses: actions/checkout@v3
39+
uses: actions/checkout@v4
4240
with:
4341
fetch-depth: 0
4442

4543
- name: Setup .NET
46-
uses: actions/setup-dotnet@v3
44+
uses: actions/setup-dotnet@v4
4745
with:
4846
dotnet-version: |
49-
6.0.x
50-
7.0.x
5147
8.0.x
5248
5349
# used for documentation
@@ -64,10 +60,10 @@ jobs:
6460
runs-on: ubuntu-latest
6561
steps:
6662
- name: Checkout
67-
uses: actions/checkout@v3
63+
uses: actions/checkout@v4
6864

6965
- name: Setup .NET
70-
uses: actions/setup-dotnet@v3
66+
uses: actions/setup-dotnet@v4
7167
with:
7268
dotnet-version: 8.0.x
7369

Diff for: BreakingChanges.md

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
6.0.0 Release
2+
================
3+
4+
* Update target frameworks: .NET 8, .NET Standard 2.0.
5+
* Obsolete api is removed
6+
* CompatArg is marked as obsolete
7+
18
5.0.0 Release
29
================
310

@@ -91,7 +98,7 @@ Workaround: Use `NSubstitute.Received.InOrder`.
9198

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

94-
3.0.0 Release
101+
3.0.0 Release
95102
================
96103

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

110117

111-
1.10.0 Release
118+
1.10.0 Release
112119
================
113120

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

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

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

130137

131-
1.9.1 Release
138+
1.9.1 Release
132139
================
133140

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

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

149-
1.8.0 Release
156+
1.8.0 Release
150157
================
151158

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

215222
---------------
216223

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

219226
Reason:
220227
- 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.
@@ -229,7 +236,7 @@ Fix:
229236
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.
230237

231238
Reason:
232-
- Reduced setup when substituting for `Func` delegates, and consistency with behaviour for properties and methods.
239+
- Reduced setup when substituting for `Func` delegates, and consistency with behaviour for properties and methods.
233240

234241
Fix:
235242
- Explicitly return null from substitute delegates when required for a test.

Diff for: CHANGELOG.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
### 6.x (work in progress)
2+
3+
* [UPDATE] Update target frameworks: .NET8, .NET Standard 2.0
4+
* [UPDATE] Drop EOL .NET 6/7 platforms from testing matrix
5+
* [UPDATE] Update github actions steps versions
6+
* [UPDATE] Remove legacy obsolete API
7+
* [UPDATE] Mark as obsolete api CompatArg with pre c# 7.0 support
8+
9+
110
### 5.3.0 (October 2024)
211

312
* [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.
@@ -40,7 +49,7 @@ Many thanks to @alexandrnikitin, @Romfos, @brad, and @304NotModified for their c
4049

4150
### 4.4.0 (Jul 2022)
4251

43-
* [FIX] Fix issue checking for constructor args on null object. Thanks to @phongphanq, and @appel1! Thanks also to
52+
* [FIX] Fix issue checking for constructor args on null object. Thanks to @phongphanq, and @appel1! Thanks also to
4453
@Mandroide for code review. (#683, #685)
4554
* [UPDATE] Update to Castle Core v5. Thanks @Havunen! (#690, #673)
4655
* [NEW] Add `.ThrowsAsync()` that will correctly mock exception on async methods. Thanks @Socolin! (#609, #663)

Diff for: Directory.Build.props

-6
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
See more here https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build?view=vs-2019 -->
66

77
<PropertyGroup>
8-
<TargetIsNetFx Condition="$(TargetFramework.StartsWith('net4'))">true</TargetIsNetFx>
9-
<TargetIsNet5OrNewer Condition="'$(TargetFramework)' == 'net6.0'">true</TargetIsNet5OrNewer>
108
<LangVersion>latest</LangVersion>
119
<ImplicitUsings>enable</ImplicitUsings>
1210
</PropertyGroup>
@@ -15,8 +13,4 @@
1513
<OutputPath>$(MSBuildThisFileDirectory)\bin\$(Configuration)\$(MSBuildProjectName)\</OutputPath>
1614
</PropertyGroup>
1715

18-
<ItemGroup Condition="'$(TargetIsNetFx)' == 'true'">
19-
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="All" />
20-
</ItemGroup>
21-
2216
</Project>

Diff for: src/NSubstitute/Compatibility/CompatArg.cs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace NSubstitute.Compatibility;
1717
/// For more information see <see href="https://nsubstitute.github.io/help/compat-args">Compatibility Argument
1818
/// Matchers</see> in the NSubstitute documentation.
1919
/// </summary>
20+
[Obsolete("This api is deprecated and will be removed in future versions of product.")]
2021
public class CompatArg
2122
{
2223
private CompatArg() { }

Diff for: src/NSubstitute/Compatibility/DiagnosticsNullabilityAttributes.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if !SYSTEM_DIAGNOSTICS_CODEANALYSIS_NULLABILITY
1+
#if NETSTANDARD2_0
22

33
// This was copied from https://github.com/dotnet/runtime/blob/39b9607807f29e48cae4652cd74735182b31182e/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/NullableAttributes.cs
44
// and updated to have the scope of the attributes be internal.

Diff for: src/NSubstitute/Core/Argument.cs

+5-34
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,18 @@
11
namespace NSubstitute.Core;
22

3-
public class Argument
3+
public class Argument(ICall call, int argIndex)
44
{
5-
private readonly ICall? _call;
6-
private readonly int _argIndex;
7-
8-
private readonly Type? _declaredType;
9-
private readonly Func<object?>? _getValue;
10-
private readonly Action<object?>? _setValue;
11-
12-
[Obsolete("This constructor overload is deprecated and will be removed in the next version.")]
13-
public Argument(Type declaredType, Func<object?> getValue, Action<object?> setValue)
14-
{
15-
_declaredType = declaredType;
16-
_getValue = getValue;
17-
_setValue = setValue;
18-
}
19-
20-
public Argument(ICall call, int argIndex)
21-
{
22-
_call = call;
23-
_argIndex = argIndex;
24-
}
5+
private readonly ICall? _call = call;
256

267
public object? Value
278
{
28-
get => _getValue != null ? _getValue() : _call!.GetArguments()[_argIndex];
29-
set
30-
{
31-
if (_setValue != null)
32-
{
33-
_setValue(value);
34-
}
35-
else
36-
{
37-
_call!.GetArguments()[_argIndex] = value;
38-
}
39-
}
9+
get => _call!.GetArguments()[argIndex];
10+
set => _call!.GetArguments()[argIndex] = value;
4011
}
4112

4213
public bool IsByRef => DeclaredType.IsByRef;
4314

44-
public Type DeclaredType => _declaredType ?? _call!.GetParameterInfos()[_argIndex].ParameterType;
15+
public Type DeclaredType => _call!.GetParameterInfos()[argIndex].ParameterType;
4516

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

Diff for: src/NSubstitute/Core/ArgumentSpecificationDequeue.cs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.Reflection;
2-
using NSubstitute.Core.Arguments;
1+
using NSubstitute.Core.Arguments;
32

43
namespace NSubstitute.Core;
54

@@ -20,9 +19,4 @@ public IList<IArgumentSpecification> DequeueAllArgumentSpecificationsForMethod(i
2019
var queuedArgSpecifications = dequeueAllQueuedArgSpecs.Invoke();
2120
return queuedArgSpecifications;
2221
}
23-
24-
public IList<IArgumentSpecification> DequeueAllArgumentSpecificationsForMethod(MethodInfo methodInfo)
25-
{
26-
return DequeueAllArgumentSpecificationsForMethod(methodInfo.GetParameters().Length);
27-
}
2822
}

Diff for: src/NSubstitute/Core/Call.cs

+3-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using System.Reflection;
21
using NSubstitute.Core.Arguments;
32
using NSubstitute.Exceptions;
3+
using System.Reflection;
44

55
namespace NSubstitute.Core;
66

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

18-
[Obsolete("This constructor is deprecated and will be removed in future version of product.")]
19-
public Call(MethodInfo methodInfo,
20-
object?[] arguments,
21-
object target,
22-
IList<IArgumentSpecification> argumentSpecifications,
23-
IParameterInfo[] parameterInfos,
24-
Func<object> baseMethod)
25-
: this(methodInfo, arguments, target, argumentSpecifications, baseMethod)
26-
{
27-
_parameterInfosCached = parameterInfos ?? throw new ArgumentNullException(nameof(parameterInfos));
28-
}
29-
30-
public Call(MethodInfo methodInfo,
18+
public Call(
19+
MethodInfo methodInfo,
3120
object?[] arguments,
3221
object target,
3322
IList<IArgumentSpecification> argumentSpecifications,

Diff for: src/NSubstitute/Core/CallRouter.cs

-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ public IEnumerable<ICall> ReceivedCalls()
4242
return substituteState.ReceivedCalls.AllCalls();
4343
}
4444

45-
public void SetRoute(Func<ISubstituteState, IRoute> getRoute) =>
46-
threadContext.SetNextRoute(this, getRoute);
47-
4845
public object? Route(ICall call)
4946
{
5047
threadContext.SetLastCallRouter(this);

Diff for: src/NSubstitute/Core/CallSpecificationFactoryFactoryYesThatsRight.cs

-14
This file was deleted.
+1-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
using System.Reflection;
2-
using NSubstitute.Core.Arguments;
1+
using NSubstitute.Core.Arguments;
32

43
namespace NSubstitute.Core;
54

65
public interface IArgumentSpecificationDequeue
76
{
8-
[Obsolete("This method is deprecated and will be removed in future versions of product.")]
9-
IList<IArgumentSpecification> DequeueAllArgumentSpecificationsForMethod(MethodInfo methodInfo);
10-
117
IList<IArgumentSpecification> DequeueAllArgumentSpecificationsForMethod(int parametersCount);
128
}

Diff for: src/NSubstitute/Core/ICallRouter.cs

-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using NSubstitute.Routing;
2-
31
namespace NSubstitute.Core;
42

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

0 commit comments

Comments
 (0)