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

Using Arg.Any<>() in .Returns() causes unexpected behavior #149

Closed
dburik opened this issue Apr 9, 2014 · 1 comment
Closed

Using Arg.Any<>() in .Returns() causes unexpected behavior #149

dburik opened this issue Apr 9, 2014 · 1 comment
Assignees

Comments

@dburik
Copy link

dburik commented Apr 9, 2014

NSubstitute does not complain about the following code:

sub1.GetItem(Arg.Any<string>())
   .Returns(new Item());

sub2.GetSignature(...)
   .Returns(Arg.Any<string>()) // <-- THIS IS THE PROBLEM

// Call to GetItem(...)
sub1.GetItem("mystring");

sub1.ReceivedWithAnyArgs(1).GetItem(...);

// exception is thrown:
// Additional information: Expected to receive exactly 1 call matching:
//  GetItem(any String)
//Actually received no matching calls.

After fixing

sub2.GetSignature(...)
   .Returns(Arg.Any<string>())

to

sub2.GetSignature(...)
   .Returns("")

the exception is gone.

If using Arg.Any<>() in .Returns() statement causes problems it would be good to have a compile time error or at least a self-descriptive exception instead of just missing call.

@dtchepak dtchepak self-assigned this Jul 12, 2014
dtchepak added a commit that referenced this issue Jul 13, 2014
@dtchepak
Copy link
Member

Thanks for raising this @dburik, and for providing the great repro case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants