title: Moq Setup for method with expression<Func<t,bool>> argument
body: <p>I'm trying to mock the following repository method</p>
  
  <pre><code>IEnumerable&lt;T&gt; All(Expression&lt;Func&lt;T, bool&gt;&gt; criteria)
  </code></pre>
  
  <p>below mock setup works fine</p>
  
  <pre><code>repository.Setup(repo =&gt; repo.All(It.IsAny&lt;Expression&lt;Func&lt;UserLog, bool&gt;&gt;&gt;())).Returns(userLogs);
  </code></pre>
  
  <p>however, when I want to setup with a specific expression, it does not work. When called, method "All" doesn't return the userlogs object as specified.</p>
  
  <pre><code>repository.Setup(repo =&gt; repo.All(v=&gt;v.UserId==userId)).Returns(userLogs);
  </code></pre>
  
  <p>I've also tried the following. I know its ugly but I got curious if it would work, and it did.</p>
  
  <pre><code>repository.Setup(ulr =&gt; 
                          ulr.All(It.Is&lt;Expression&lt;Func&lt;UserLog, bool&gt;&gt;&gt;(e =&gt; 
                          e.Compile().Invoke(new UserLog { UserId = userId }))))
  .Returns(userLogs);
  </code></pre>
  
  <p>However, weirdly enough, moving that cumbersome expression into a seperate variable and passing it in instead, did not work. like below</p>
  
  <pre><code>var itis = It.Is&lt;Expression&lt;Func&lt;UserLog, bool&gt;&gt;&gt;(e =&gt; e.Compile().Invoke(new UserLog { UserId = userId }));
  repository.Setup(ulr =&gt; ulr.All(itis)).Returns(userLogs);
  </code></pre>
  
  <p>The mocked method is being called as follows;</p>
  
  <pre><code>repository.All(u=&gt;u.UserId==userId);
  </code></pre>
  
  <p>What I want to do is to mock a method for a specific Expression>. </p>
  
  <p>I can't figure this one out, would love some help.</p>
  
  <p>Thanks.</p>