Reputation: 3139
I have the following code in a test in my code. Note that this test was not written by me, the code it is calling was also not written by me, but I have changed it.
mockedIMessage.Setup(m => m.ScriptMethodInvoker(EnumFunction.MsgFullSetPosition, It.IsAny<Result>())).Returns(1).Verifiable();
var result = GetTestExecutionResult(script);
mockedIMessage.Verify(m => m.ScriptMethodInvoker(EnumFunction.MsgFullSetPosition, It.IsAny<Result>()), Times.Once);
On the original code, this works. On mine, it doesn't - it tells me that the expected invocation on the mock was 0 times, not the once expected.
However, when I step it through in debug mode, it most definitely does call this code, and completes without throwing an exception. So the code appears to work, but the Moq is not detecting that it has been called.
Upvotes: 1
Views: 2880
Reputation: 8500
From what you provided, multiple mistakes could have been made:
ScriptMethodInvoker()
on the mocked IMessage
instance ScriptMethodInvoker()
has overloads, make sure the right one is calledEnumFunction
is an enumEnumFunction
is not an enum then make sure that EnumFunction.MsgFullSetPosition
always returns the same instanceGetTestExecutionResult()
actually calls ScriptMethodInvoker()
.Upvotes: 1