-
Notifications
You must be signed in to change notification settings - Fork 266
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
Compiler error when using Arg.Is<Arg.AnyType> #757
Comments
It's possible to remove the compile error by changing
to
but no match will be found.
|
Not sure what you are trying to do. The Arg.AnyType was introduced to say "I dont care which type, I just want to test that the method was called". So the combination of Arg.Is with Arg.AnyType doesnt make sense for me. You want to check that SomeFunction was called with the integer 3409, so just write:
which can be shortened to:
|
Arg.Is with Arg.AnyType is for testing the generic parameter. If i would like to mock the ILogger method and assert that the logger was called with a log message that contained a specific message.
|
I ran into this exact same issue while converting from Moq, except I was using |
Funny, as there is some case in the code for this? NSubstitute/src/NSubstitute/Arg.cs Line 56 in 1f2fb0f
|
Describe the bug
When using Arg.Is<Arg.AnyType>(expression), depending on the expression, the code can't compile.
The compiler error is
Error CS0121 : The call is ambiguous between the following methods or properties: 'Arg.Is(Expression<Predicate>)' and 'Arg.Is(Expression<Predicate>)'
To Reproduce
The lambda expression: state => (int)state == 3409) is legal
The lambda expression: state => state.ToString() == 3409.ToString() produces the compile error:
NotificationServiceTest.cs(315, 64): [CS0121] The call is ambiguous between the following methods or properties: 'Arg.Is<T>(Expression<Predicate<T>>)' and 'Arg.Is<T>(Expression<Predicate<object>>)'
Expected behaviour
No compiler error
Environment:
Additional context
Trying to migrate away from Moq.
The text was updated successfully, but these errors were encountered: