title: How to mock a method call that takes a dynamic object
body: <p>Say I have the following:</p>
  
  <pre><code>public interface ISession 
  {
     T Get&lt;T&gt;(dynamic filter); }
  }
  </code></pre>
  
  <p>And I have the following code that I want to test:</p>
  
  <pre><code>var user1 = session.Get&lt;User&gt;(new {Name = "test 1"});
  var user2 = session.Get&lt;User&gt;(new {Name = "test 2"});
  </code></pre>
  
  <p>How would I mock this call?</p>
  
  <p>Using Moq, I tired doing this:</p>
  
  <pre><code>var sessionMock = new Mock&lt;ISession&gt;();
  sessionMock.Setup(x =&gt; x.Get&lt;User&gt;(new {Name = "test 1")).Returns(new User{Id = 1});
  sessionMock.Setup(x =&gt; x.Get&lt;User&gt;(new {Name = "test 1")).Returns(new User{Id = 2});
  </code></pre>
  
  <p>And that didn't work. The returned results is null</p>
  
  <p>I also tried to do the following with Rhino Mocks:</p>
  
  <pre><code>var session = MockRepository.GenerateStub&lt;ISession&gt;();
  session.Stub(x =&gt; x.Get&lt;User&gt;(new {Name = "test 1"})).Return(new User{Id=1});
  </code></pre>
  
  <p>No luck either. Null again.</p>
  
  <p>So how would I do this?</p>
  
  <p>Thanks,</p>