After upgrading to NCrunch 3.13.0.7, I'm getting regular occurrences of an UnexpectedArgumentMatcherException. They're occurring at most once per test run, and the exception message is like this:
SetUp : NSubstitute.Exceptions.UnexpectedArgumentMatcherException : Argument matchers (Arg.Is, Arg.Any) should only be used in place of member arguments. Do not use in a Returns() statement or anywhere else outside of a member call.
Correct use:
sub.MyMethod(Arg.Any<string>()).Returns("hi")
Incorrect use:
sub.MyMethod("hi").Returns(Arg.Any<string>())
Re-running the test always clears the exception.
However, none of my tests use Arg.Any inside a Returns method call. An example line that produces this exception is
Thanks for the reply. I found that this issue was raised on StackOverflow a while ago - https://stackoverflow.com/questions/38283104.
In our case, a couple of tests were using AutoFixture's fixture.Create<T1>() method to build an object, and then passing Arg.Any<T2>() as a parameter in a method call on this object. This causes NSubstitute's static queue to get out-of-sync, as explained well here: https://weareadaptive.com/2014/09/30/why-nsubstitute/
Replacing these parameters with fixture.Create<T2>() fixed the issue.
So this was not a problem with NCrunch, but some change between 3.12.0.15 and 3.13.0.7 made this problem more likely to be visible. But that's a good thing!