I think that you may misinterpret the purpose of .Verify ().
It checks that this method has been called with the expected value.
On page 187 of the book, Steve says: βNotice how he uses the Moqs.Verify () method to ensure that AdminController actually called DeleteProduct () with the correct parameter. '
So, in your case, the test passes because it is just a call test, not a functionality.
As TDD Follows the Book, Addendum
productsRepository.DeleteProduct(product);
should first add to test
// Assert: Saved product to repository, then deleted and redirected mockRepos.Verify(x => x.SaveProduct(newProduct)) mockRepos.Verify(x => x.DeleteProduct(newProduct)); Assert.AreEqual("Index", result.RouteValues["action"]);
and then added to code
[AcceptVerbs(HttpVerbs.Post)] public ActionResult Edit(Product product, HttpPostedFileBase image) { ... productsRepository.SaveProduct(product); productsRepository.DeleteProduct(product); ...
source share