title: Strange "Expected invocation on the mock at least once, but was never performed" error when I am setting up the Mock
body: <p>I'm getting this error from Moq via NUnit, and it doesn't make much in the way of sense to me.</p>
  
  <p>"Expected invocation on the mock at least once, but was never performed: x => x.DeleteItem(.$VB$Local_item)"</p>
  
  <p>"at Moq.Mock.ThrowVerifyException(MethodCall expected, IEnumerable<code>1 setups, IEnumerable</code>1 actualCalls, Expression expression, Times times, Int32 callCount)
  at Moq.Mock.VerifyCalls(Interceptor targetInterceptor, MethodCall expected, Expression expression, Times times)
  at Moq.Mock.Verify[T](Mock mock, Expression<code>1 expression, Times times, String failMessage)
  at Moq.Mock</code>1.Verify(Expression`1 expression)
  at PeekABookEditor.UnitTests.ItemBrowsing.Can_Delete_Item() in C:\Projects\MyProject\MyProject.UnitTests\Tests\ItemBrowsing.vb:line 167"</p>
  
  <p>Very similar code works well in C#, so the error might be minor and syntactical on my part.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>    &lt;Test()&gt; _
  Public Sub Can_Delete_Item()
      'Arrange: Given a repository containing some item...
      Dim mockRepository = New Mock(Of IItemsRepository)()
      Dim item As New Item With {.ItemID = "24", .Title = "i24"}
  
      mockRepository.Setup(Function(x) x.Items).Returns(New Item() {item}.AsQueryable())
  
      'Act ... when the user tries to delete that product
      Dim controller = New ItemsController(mockRepository.Object)
      Dim result = controller.Delete(24)
  
      'Assert ... then it's deleted, and the user sees a confirmation
      mockRepository.Verify(Sub(x) x.DeleteItem(item))
      result.ShouldBeRedirectionTo(New With {Key .action = "List"})
      Assert.AreEqual(DirectCast(controller.TempData("message"), String), "i24 was deleted")
  
  End Sub
  </code></pre>
  
  <p>The guilty line appears to be "mockRepository.Verify(Sub(x) x.DeleteItem(item))"</p>
  
  <p>Any thoughts on how to fix this?</p>
  
  <p>Working C# code isn't the exact same, but here it is:</p>
  
  <pre><code>[Test] 
  public void Can_Delete_Product() 
  { 
  // Arrange: Given a repository containing some product... 
  var mockRepository = new Mock&lt;IProductsRepository&gt;(); 
  var product = new Product { ProductID = 24, Name = "P24"}; 
  mockRepository.Setup(x =&gt; x.Products).Returns( 
      new[] { product }.AsQueryable() 
  ); 
  
  // Act: ... when the user tries to delete that product 
  var controller = new AdminController(mockRepository.Object); 
  var result = controller.Delete(24); 
  
  // Assert: ... then it's deleted, and the user sees a confirmation
  mockRepository.Verify(x =&gt; x.DeleteProduct(product)); 
  result.ShouldBeRedirectionTo(new { action = "Index" }); 
  controller.TempData["message"].ShouldEqual("P24 was deleted"); 
  </code></pre>
  
  <p>}  </p>