I suggest you ...

Matching parameters which are expressions

Maybe it is already somehow possible, but I need to be able to do something like this:

mock.Verify(x => x.Foo(y => Bar(It.Is<int>(z => z == 2))), Times.Once);

Verify must match calls to Foo where the parameter is an expression calling 'Bar' with a parameter which must equal '2'.

I know I can write the following, which however is not quite specific enough.

mock.Verify(x => x.Foo(It.IsAny<Expression<Func<int, int>>()), Times.Once);

10 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Søren shared this idea  ·   ·  Admin →

    1 comment

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • AdminDaniel Cazzulino (Admin, moq) commented  · 

        Comparison of expression trees is not provided by the underlying .NET, so Moq can't compare equality on them, hence the comparison fails.

      Feedback and Knowledge Base