Skip to content

Instantly share code, notes, and snippets.

@ferventcoder
Created July 29, 2011 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ferventcoder/1114813 to your computer and use it in GitHub Desktop.
Save ferventcoder/1114813 to your computer and use it in GitHub Desktop.
Moq Issue
mock.Verify(m => m.Subscribe<Message>(someclass.SomeMethod, null, x => true), Times.AtLeastOnce());
@ferventcoder
Copy link
Author

TestCase 'sometest'
failed: System.NotSupportedException : Unsupported expression: x => True
at Moq.MatcherFactory.CreateMatcher(Expression expression, Boolean isParams)
at Moq.MethodCall..ctor(Mock mock, Func1 condition, Expression originalExpression, MethodInfo method, Expression[] arguments) at Moq.MethodCallReturn2..ctor(Mock mock, Func1 condition, Expression originalExpression, MethodInfo method, Expression[] arguments) at Moq.Mock.Verify[T,TResult](Mock mock, Expression1 expression, Times times, String failMessage)
at Moq.Mock1.Verify[TResult](Expression1 expression, Times times)

@ferventcoder
Copy link
Author

I want to call It.IsAny<Method> instead of passing a particular method.

@ferventcoder
Copy link
Author

mock.Verify(sm => m.Subscribe<Message>(someclass.SomeMethod, null, It.IsAny<Func<ModelAlterationMessage, bool>>()), Times.AtLeastOnce());

Cuts the error and fixes my issue...however I would like to not have to pass the some method from the class in there.... It.IsAny<Action> doesn't quite work...

Thanks for the help Jason!

@davidalpert
Copy link

don't know if this is possible with moq (haven't used it in a while due to it's moq.Object tax) but with Rhino you can register a callback to fire when the method is called (if set as a setup/expectation, anyway) and in that callback have access to the method invocation that was matched (m.Subscribe() in this case) including it's args. If moq has a similar idiom then perhaps you could trap the matching method invocation and peek at the type of someclass.SomeMethod as seen by moq. It may not be an Action... even if that's the arg type and how the type of SomeMethod looks to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment