title: Verify method calls using with different state of object using Moq
body: <p>Recently I discovered quite interesting behaviour of <code>Moq</code> library (4.5.21) in one of mine C# projects. Below is the class that I am trying to test.</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class Order
  {
      public string State { get; set; }
  }
  
  public interface IOrderService
  {
      Task UpdateOrderAsync(Order order);
  }
  
  public class Program
  {
      public async Task RunAsync(IOrderService orderService)
      {
          var order = new Order();
  
          order.State = "new";
          await orderService.UpdateOrderAsync(order);
  
          order.State = "open";
          await orderService.UpdateOrderAsync(order);
      }
  }
  </code></pre>
  
  <p>Below is my TestClass:</p>
  
  <pre class="lang-cs prettyprint-override"><code>[TestMethod]
  public async Task TestMethod()
  {
      var mock = new Mock&lt;IOrderService&gt;();
      await new Program().RunAsync(mock.Object);
  
      mock.Verify(x =&gt; x.UpdateOrderAsync(It.Is&lt;Order&gt;(o =&gt; o.State == "new")), Times.Once);
      mock.Verify(x =&gt; x.UpdateOrderAsync(It.Is&lt;Order&gt;(o =&gt; o.State == "open")), Times.Once);
  }
  </code></pre>
  
  <p>I get following output:</p>
  
  <pre><code>Moq.MockException:
  Expected invocation on the mock once, but was 0 times: x =&gt; x.UpdateOrderAsync(It.Is&lt;Order&gt;(o =&gt; o.State == "new"))
  
  
  Configured setups:
  x =&gt; x.UpdateOrderAsync(It.Is&lt;Order&gt;(o =&gt; o.State == "new")), Times.Once
  x =&gt; x.UpdateOrderAsync(It.Is&lt;Order&gt;(o =&gt; o.State == "open")), Times.Once
  
  Performed invocations:
  IOrderService.UpdateOrderAsync(Order&lt;State:open&gt;)
  IOrderService.UpdateOrderAsync(Order&lt;State:open&gt;)
  </code></pre>
  
  <p>I'd expect that I can <code>Verify</code> that the method was called <code>Once</code> each time with an <code>object</code> with different <code>State</code>. Any thoughts on what am I doing wrong?</p>
  
  <p>Thank you!</p>