I\'m using Moq and want to create builder classes to create my mocks with preset reasonable defaults that can be overridden during test setup as needed. The approach I took
It.IsAny
has return type of int and returns 0
, so your second setup is equivalent to:
mock.Setup(x => x.Bar2(0)).Returns(true);
I didn't check the moq code, but I'm pretty sure that when it evaluates the expression in the setup method, it takes into account that the parameter is actually It.IsAny vs. a normal number.
You are better off if you create the setups directly in your helper methods, and not pass It.IsAny.