You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for raising this. This behaviour is due to re-entrant substitute use, which is an unfortunate limitation of the trick NSubstitute's syntax uses (see also: nsubstitute/NSubstitute.Analyzers#12).
When running the Received call, NSubsitute sees something like this:
candidate.Perform(candidate.Name,new[]{"a"});
candidate
.Received()// puts sub in "assert next call was received" mode.Perform(// Perform is not run yet, as args need to be evaluated...
candidate.Name // <-- this is the next call, and it WAS received in the line above (second line of the test)
...)// assert passes as candidate.Name was received
We can see this by commenting out the second line:
varcandidate= Substitute.For<ICandidate>();// candidate.Perform("", new[] { "a" });
candidate.Received().Perform(candidate.Name, Arg.Is<IEnumerable<string>>(new[]{"b"}));/*ReceivedCallsException : Expected to receive a call matching: NameActually received no matching calls.*/
To fix this it is best to pass the values directly to the substitute:
varcandidate= Substitute.For<ICandidate>();
candidate.Perform("test",new[]{"a"});
candidate.Received().Perform("test", Arg.Is<IEnumerable<string>>(new[]{"b"}));/*.ReceivedCallsException : Expected to receive a call matching: Perform("test", String[])Actually received no matching calls.Received 1 non-matching call (non-matching arguments indicated with '*' characters): Perform("test", *String[]*)*/
@tpodolak is it possible for Analyzers to detect this case with Receivedsimilar to how it works for Returns? Not sure if this is one of those cases you tried but it ended up taking too long for the analysis to run or one that could not be detected reliably. 🤔
Describe the bug
When passing a parameter from the substitute itself to a (received) assertion it passes although it clearly shouldn't.
To Reproduce
Expected behaviour
The example test should not pass due to the not matching second argument.
Environment:
The text was updated successfully, but these errors were encountered: