public void CannotDeleteInvalidProducts() { // Arrange - create a controller var controller = new AdminController(this._mockRepository.Object); // Action - attempt to delete using a ProductId that does not exist controller.Delete(95); // assert - ensure that the repository Delete method was not called this._mockRepository.Verify(m => m.DeleteProduct(It.IsAny<Product>()), Times.Never()); }
public void CanDeleteValidProducts() { // Arrange - create a product var product = new Product { ProductId = 2, Name = "Test" }; // Arrange - create a local mock repository var localMock = new Mock<IProductRepository>(); localMock.Setup(m => m.Products).Returns(new Product[] { new Product {ProductId = 1, Name = "P1"}, product, new Product {ProductId = 3, Name = "P3"} }.AsQueryable()); // Arrange - create a controller var controller = new AdminController(localMock.Object); // Action - delete the product controller.Delete(product.ProductId); // assert - ensure that the repository Delete method was called with the correct Product localMock.Verify(m => m.DeleteProduct(product)); }