public void Can_Save_Valid_Changes() { // Arrange // - Create the mock repository Mock<IProductRepository> mock = new Mock<IProductRepository>(); AdminController target = new AdminController(mock.Object); Product product = new Product { Name = "Test" }; // Act ActionResult result = target.Save(product, null); // Assert mock.Verify(m => m.SaveProduct(product)); Assert.IsNotInstanceOfType(result, typeof(ViewResult)); }
public void Cannot_Save_Invalid_Changes() { // Arrange // - Create the mock repository Mock<IProductRepository> mock = new Mock<IProductRepository>(); AdminController target = new AdminController(mock.Object); Product product = new Product { Name = "Test" }; target.ModelState.AddModelError("error", "error"); // Act ActionResult result = target.Save(product, null); // Assert mock.Verify(m => m.SaveProduct(product), Times.Never()); Assert.IsInstanceOfType(result, typeof(ViewResult)); }