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
mock.Protected().Verify(...) does not work correctly when used with wildcard matchers such as It.IsAny.
Steps to Reproduce
using Moq;using Moq.Protected;namespace TestProject1;publicclassUnitTest1{[Fact]publicvoidVerify_that_the_Public_method_is_called_with_the_specific_value_for_the_argument(){varmock=newMock<X>();
mock.Object.CallPublic(1);
mock.Verify(static x => x.Public(1), Times.Once());}[Fact]publicvoidVerify_that_the_Public_method_is_called_regardless_of_the_value_of_its_argument(){varmock=newMock<X>();
mock.Object.CallPublic(2);
mock.Verify(static x => x.Public(It.IsAny<int>()), Times.Once());}[Fact]publicvoidVerify_that_the_Protected_method_is_called_with_the_specific_value_for_the_argument(){varmock=newMock<X>();
mock.Object.CallProtected(3);
mock.Protected().Verify("Protected", Times.Once(),3);}[Fact]publicvoidVerify_that_the_Protected_method_is_called_regardless_of_the_value_of_its_argument(){varmock=newMock<X>();
mock.Object.CallProtected(4);
mock.Protected().Verify("Protected", Times.Once(), It.IsAny<int>());}}publicabstractclassX{publicvoidCallPublic(intvalue)=> Public(value);publicvoidCallProtected(intvalue)=> Protected(value);publicabstractvoidPublic(intvalue);protectedabstractvoidProtected(intvalue);}
Expected Behavior
All tests passed.
Exception with Stack Trace
Moq.MockException
Expected invocation on the mock once, but was 0 times: mock => mock.Protected(0)
Performed invocations:
Mock<X:3> (mock):
X.Protected(4)
at Moq.Mock.Verify(Mock mock, LambdaExpression expression, Times times, String failMessage) in /_/src/Moq/Mock.cs:line 331
at Moq.Protected.ProtectedMock`1.InternalVerify(String methodName, Type[] genericTypeArguments, Times times, Boolean exactParameterMatch, Object[] args) in /_/src/Moq/Protected/ProtectedMock.cs:line 234
at Moq.Protected.ProtectedMock`1.Verify(String methodName, Times times, Object[] args) in /_/src/Moq/Protected/ProtectedMock.cs:line 206
at TestProject1.UnitTest1.Verify_that_the_Protected_method_is_called_regardless_of_the_value_of_its_argument() in D:\Source\TestProject1\UnitTest1.cs:line 37
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
Describe the Bug
mock.Protected().Verify(...)
does not work correctly when used with wildcard matchers such asIt.IsAny
.Steps to Reproduce
Expected Behavior
All tests passed.
Exception with Stack Trace
Version Info
Additional Info
The text was updated successfully, but these errors were encountered: