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

Feature: allow interception of any generic method call when using Arg.AnyType #855

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 5 additions & 2 deletions src/NSubstitute/Core/CallInfo.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System.Diagnostics.CodeAnalysis;
using NSubstitute.Exceptions;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;

// Disable nullability for entry-point API
#nullable disable annotations

namespace NSubstitute.Core;

public class CallInfo(Argument[] callArguments)
public class CallInfo(Argument[] callArguments, MethodInfo methodInfo)
{

/// <summary>
Expand All @@ -25,6 +26,8 @@ public object this[int index]
}
}

public MethodInfo MethodInfo => methodInfo;

private void EnsureArgIsSettable(Argument argument, int index, object value)
{
if (!argument.IsByRef)
Expand Down
2 changes: 1 addition & 1 deletion src/NSubstitute/Core/CallInfoFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class CallInfoFactory : ICallInfoFactory
public CallInfo Create(ICall call)
{
var arguments = GetArgumentsFromCall(call);
return new CallInfo(arguments);
return new CallInfo(arguments, call.GetMethodInfo());
}

private static Argument[] GetArgumentsFromCall(ICall call)
Expand Down
4 changes: 2 additions & 2 deletions src/NSubstitute/Core/CallSpecification.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Reflection;
using NSubstitute.Core.Arguments;
using System.Reflection;

namespace NSubstitute.Core;

Expand Down Expand Up @@ -93,7 +93,7 @@ internal static bool TypesAreAllEquivalent(Type[] aArgs, Type[] bArgs)
private static bool AreEquivalentDefinitions(MethodInfo a, MethodInfo b)
{
return a.IsGenericMethod == b.IsGenericMethod
&& a.ReturnType == b.ReturnType
&& TypesAreAllEquivalent([a.ReturnType], [b.ReturnType])
&& a.Name.Equals(b.Name, StringComparison.Ordinal);
}

Expand Down