示例#1
0
        public void CannotDeleteInvalidParentCategories()
        {
            // Arrange - create a controller
            var controller = new AdminController(this._mockRepository.Object);

            // Action - attempt to delete using a ParentCategoryId that does not exist
            controller.DeleteParentCategory(95);

            // assert - ensure that the repository DeleteParentCategory method was not called
            this._mockRepository.Verify(m => m.DeleteParentCategory(It.IsAny<ParentCategory>()), Times.Never());
        }
示例#2
0
        public void CanDeleteValidParentCategories()
        {
            // Arrange - create a parentCategory
            ParentCategory parentCategory = new ParentCategory { ParentCategoryId = 2, Name = "Test" };

            // Arrange - create a local mock repository
            var localMock = new Mock<IProductRepository>();
            localMock.Setup(m => m.ParentCategories).Returns(new ParentCategory[]
                {
                    new ParentCategory {ParentCategoryId = 1, Name = "PC1"},
                    parentCategory,
                    new ParentCategory {ParentCategoryId = 3, Name = "PC3"}
                }.AsQueryable());

            // Arrange - create a controller
            var controller = new AdminController(localMock.Object);

            // Action - delete the parentCategory
            controller.DeleteParentCategory(parentCategory.ParentCategoryId);

            // assert - ensure that the repository delete method was called with the correct ParentCategory
            localMock.Verify(m => m.DeleteParentCategory(parentCategory));
        }