public void CannotDeleteInvalidCategories() { // Arrange - create a controller var controller = new AdminController(this._mockRepository.Object); // Action - attempt to delete using a CategoryId that does not exist controller.DeleteCategory(95); // assert - ensure that the repository DeleteCategory method was not called this._mockRepository.Verify(m => m.DeleteCategory(It.IsAny<Category>()), Times.Never()); }
public void CanDeleteValidCategories() { // Arrange - create a category Category category = new Category { CategoryId = 2, Name = "Test"}; // Arrange - create a local mock repository var localMock = new Mock<IProductRepository>(); localMock.Setup(m => m.Categories).Returns(new Category[] { new Category {CategoryId = 1, Name = "C1"}, category, new Category {CategoryId = 3, Name = "C3"} }.AsQueryable()); // Arrange - create a controller var controller = new AdminController(localMock.Object); // Action - delete the category controller.DeleteCategory(category.CategoryId); // assert - ensure that the repository DeleteCategory method was called with the correct category localMock.Verify(m => m.DeleteCategory(category)); }