Issue with multiple identical setups
Seen with 4.18.1.
Suppose we have this interface:
public interface ISample
{
void Mock(object fi);
}
And the following code:
var mock = new Mock<ISample>();
mock.Setup(x => x.Execute(It.Is<object>(_ => true))).Verifiable();
var flag = true;
mock.Setup(x => x.Execute(It.Is<object>(_ => flag))).Verifiable();
mock.Object.Execute(new object());
mock.Verify();
Calling to mock.Verify():
- Expected behaviour: call succeeds (behaviour in 4.18.0 and before).
- Actual behaviour: call fails with error:
This mock failed verification due to the following:
MockSetupTests.ISample x => x.Execute(It.Is<object>(_ => True)):
This setup was not matched.
Except those setups aren't truly identical. The question here is when captured variables should be resolved to their values: at the time when the setup is created vs. when an invocation happens that could match the setup.
There have been a few recent changes to this, so not sure we can go back to the previous behavior in your precise use case... but I'll look into it.
Due to lack of recent activity, this issue has been labeled as 'stale'. It will be closed if no further activity occurs within 30 more days. Any new comment will remove the label.
This issue will now be closed since it has been labeled 'stale' without activity for 30 days.