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
Describe the bug
The effect of Arg.Any<T>() depends on whether it's stored in a variable or passed directly.
To Reproduce
publicinterfaceINumberChecker{publicboolExists(intnum);}publicclassMyApp{privatereadonlyINumberChecker_numberChecker;publicMyApp(INumberCheckermyInterfaceImpl){_numberChecker=myInterfaceImpl;}publicvoidCheckIfNumberExists(intnum){
_numberChecker.Exists(num);}}[Fact]publicvoidMinimalReproducibleExample(){varsub= Substitute.For<INumberChecker>();varanyInt= Arg.Any<int>();//storing this as a variable here..
sub.Exists(anyInt).Returns(true);//..and using it herevarapp=new MyApp(sub);
app.CheckIfNumberExists(1);
sub.DidNotReceive().Exists(anyInt);//..and here}
Expected behaviour
With the given code, I'd expect the test to fail, since subdoes receive a call to its Exists(). However, the test passes.
However, if I pass Arg.Any<int>() directly to the methods it's used in, I get expected behaviour (i.e. an error saying that Exists() was called):
[Fact]publicvoidMinimalReproducibleExample(){varsub= Substitute.For<INumberChecker>();
sub.Exists(Arg.Any<int>()).Returns(true);//return value doesn't matter herevarapp=new MyApp(sub);
app.CheckIfNumberExists(1);
sub.DidNotReceive().Exists(Arg.Any<int>());}
Describe the bug
The effect of
Arg.Any<T>()
depends on whether it's stored in a variable or passed directly.To Reproduce
Expected behaviour
With the given code, I'd expect the test to fail, since
sub
does receive a call to itsExists()
. However, the test passes.However, if I pass
Arg.Any<int>()
directly to the methods it's used in, I get expected behaviour (i.e. an error saying thatExists()
was called):Environment:
Additional context
The text was updated successfully, but these errors were encountered: