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
The workaround work, but feels less type safe since we have to match the method cal by name rather than by the expression tree (or do our own expression three handling to get the MethodInfo from an expression.)
The text was updated successfully, but these errors were encountered:
It appears that Moq's behavior regarding this changed as a consequence of #844 (more specifically, 84324d1). /cc @ocoanet
However, I believe that the new behavior is correct, since Verify is not supposed to cause any side effects. Capture.In is meant to be used in conjunction with Setup:
varcriteriaMock=newMock<ICriteria>();varnaturalIds=newList<NaturalIdentifier>();
criteriaMock.Setup(x => x.Add(Capture.In(naturalIds)));
...// exercise the mock
var naturalId = naturalIds.Single();
I suggest you change your tests accordingly, it seems unlikely to me that we'll go back to the old behavior.
Let me know if you have any questions. If not, I'll close this issue as "won't fix" in a few days' time.
I took a closer look, and this turned out fairly easy to fix. While Capture.In perhaps wasn't meant to be used with Verify at all, fact is that it did work for some time. I don't see any direct harm it getting it working again. Just don't tell anyone this is a thing that works (i.e. please don't put it in the wiki) 😄
With Moq 4.10.1 we used to be able to do the following to capture a NaturalIdentifier NHibernate criterion added to an NHibernate criteria:
After upgarding to 4.13.1, the
naturalIds
list is empty after passing theVerify
call, resuting in an exception from theSingle
call.As a workaround we've had to change our test to instead work on the
Invocations
collection:The workaround work, but feels less type safe since we have to match the method cal by name rather than by the expression tree (or do our own expression three handling to get the
MethodInfo
from an expression.)The text was updated successfully, but these errors were encountered: