-
-
Notifications
You must be signed in to change notification settings - Fork 812
VerifyNoOtherCalls fails reporting issue with different mock when using factory pattern #1181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Yes, this situation is not ideal. Moq's current recursive verification algorithm is indeed problematic. Since it is That is, the observed failure would be OK if you had instead done this: -mockTwo.Setup(x => x.MethodTwo()).Returns(true);
mockOne.Setup(x => x.MethodOne()).Returns(mockTwo.Object);
+mockOne.Setup(x => x.MethodOne().MethodTwo()).Returns(true); (But it's not OK to fail I've added your issue to the list of use cases in #1093. If you need a temporary workaround, you can make the following change: -mockOne.Setup(x => x.MethodOne()).Returns( mockTwo.Object);
+mockOne.Setup(x => x.MethodOne()).Returns(() => mockTwo.Object); |
@stakx Thank you. Somehow I saw your original response and never noticed that you provided a workaround after editing your response. Someone else at my organization tried to upgrade above 4.10.1 and ran into this issue. I can confirm that the workaround you provided DOES work. Thanks again. |
Due to lack of recent activity, this issue has been labeled as 'stale'. |
Due to lack of recent activity, this issue has been labeled as 'stale'. |
This issue will now be closed since it has been labeled 'stale' without activity for 30 days. |
The code below passes unit tests successfully up to moq version 4.10.1. After that the code fails as described in the code.
I read through the release notes for version 4.11 and I didn't see anything to point to this change. In addition, the behavior is NOT expected (in my opinion) because the code is asking for
VerifyNoOtherCalls()
from a specific mock therefore I would NOT expect an error message citing a different mock.In addition to the code below I have also created a repository that reproduces the pass on version 4.10.1 and the fail on the latest version of moq.
See https://github.com/benrobot/moq4BugReport
The text was updated successfully, but these errors were encountered: