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

Unable to match arguments whose type is generic, when their concrete type is not known #786

Open
GianvitoDifilippo opened this issue Mar 13, 2024 · 1 comment
Labels
question Question on NSubstitute behaviour

Comments

@GianvitoDifilippo
Copy link

GianvitoDifilippo commented Mar 13, 2024

Question
Hello everyone. I'm having trouble in verifying a call to a method accepting a single argument, whose type is a generic interface (say, IMyArgument<T>). At compile time, I don't have access to the concrete type of the argument being passed, so I tried Arg.Any<IMyArgument<Arg.AnyType>>(), but that fails.

IMyService service = Substitute.For<IMyService>();
var argument = new MyStringArgument();

service.MyMethod(argument);

// The following line throws. Using ReceivedWithAnyArgs didn't help.
service.Received().MyMethod(Arg.Any<IMyArgument<Arg.AnyType>>());

public interface IMyService
{
  void MyMethod<T>(IMyArgument<T> argument);
}

public interface IMyArgument<T> { }

// Suppose I don't have access to this type at compile time, so I could not have written Arg.Any<MyStringArgument>()
public class MyStringArgument : IMyArgument<string> { }

I couldn't find any information addressing this specific issue in the documentation. Any suggestion is appreciated :)

@304NotModified 304NotModified added feature-request Request for a new NSubstitute feature question Question on NSubstitute behaviour and removed feature-request Request for a new NSubstitute feature labels Apr 29, 2024
@304NotModified
Copy link
Contributor

Duplicate of #757?

dtchepak pushed a commit that referenced this issue Jun 10, 2024
… type is not known (#786) (#814)

Unable to match arguments whose type is generic, when their concrete type is not known (#786)

Co-authored-by: Mihnea Rădulescu <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question on NSubstitute behaviour
Projects
None yet
Development

No branches or pull requests

2 participants