title: Weird Behavior Using MOQ
body: <p>I am experiencing some weird behavior using MOQ in my unit tests:</p>
  
  <p>Given the following test:</p>
  
  <pre><code>[Fact]
  public void ShoppingCart_ShouldIncrementQuantity_WhenAddingDuplicateItem()
  {
      var cart = new ShoppingCart();
  
      var item1 = GetMockItem("Test");
      var item2 = GetMockItem("Test", quantity: 2);
  
      cart.AddItem(item1.Object);
      cart.AddItem(item2.Object);
  
      cart.Items.Single(x =&gt; x.Sku == "Test").Quantity
          .Should().Be(3);
  }
  
  private Mock&lt;IShoppingCartItem&gt; GetMockItem(string sku, decimal price = 10, int quantity = 1)
  {
      var mock = new Mock&lt;IShoppingCartItem&gt;();
      mock.Setup(x =&gt; x.Sku).Returns(sku);
      mock.Setup(x =&gt; x.Price).Returns(price);
      mock.Setup(x =&gt; x.Quantity).Returns(quantity);
  
      return mock;
  }
  </code></pre>
  
  <p>And this is the code under test:</p>
  
  <pre><code>public void AddItem(IShoppingCartItem item)
  {
      Enforce.ArgumentNotNull(item, "item");
  
      var existingItem = this.Items.SingleOrDefault(x =&gt; x.Sku == item.Sku);
  
      if (existingItem != null)
      {
          existingItem.Quantity += item.Quantity;
      }
      else
      {
          this.Items.Add(item);
      }
  }
  </code></pre>
  
  <p>I am getting this result: <code>Test 'Titan.Tests.ShoppingCartTests.ShoppingCart_ShouldIncrementQuantity_WhenAddingDuplicateItem' failed: Expected 3, but found 1.</code></p>
  
  <p>I am baffled or I am just having a dumb moment!</p>