コード例 #1
0
ファイル: AdminControllerTest.cs プロジェクト: iHunt101/POS-1
        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
ファイル: AdminControllerTest.cs プロジェクト: iHunt101/POS-1
        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));
        }
コード例 #3
0
ファイル: AdminControllerTest.cs プロジェクト: iHunt101/POS-1
        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));
        }
コード例 #4
0
ファイル: AdminControllerTest.cs プロジェクト: iHunt101/POS-1
        public void CanSaveValidChanges()
        {
            // Arrange - create a controller
            var controller = new AdminController(this._mockRepository.Object);
            // Arrange - create a product
            Product product = new Product { Name = "Test" };

            // Action - try to save the product
            ActionResult result = controller.Edit(product, null);

            // Assert - check that the repository was called
            this._mockRepository.Verify(m => m.SaveProduct(product));
            // Assert - check the method result type
            Assert.IsNotInstanceOfType(result, typeof(ViewResult));
        }
コード例 #5
0
ファイル: AdminControllerTest.cs プロジェクト: iHunt101/POS-1
        public void CannotSaveInvalidChanges()
        {
            // Arrange - create a controller
            var controller = new AdminController(this._mockRepository.Object);
            // Arrange - create a product
            Product product = new Product { Name = "Test" };
            // Arrange - add an error to the model state
            controller.ModelState.AddModelError("error", "error");

            // Action - try to save the product
            ActionResult result = controller.Edit(product, null);

            // Assert - check that the repository was called
            this._mockRepository.Verify(m => m.SaveProduct(It.IsAny<Product>()), Times.Never());
            // Assert - check the method result type
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
コード例 #6
0
ファイル: AdminControllerTest.cs プロジェクト: iHunt101/POS-1
        public void CannotEditNonexistentParentCategory()
        {
            // Arrange - create a controller
            var controller = new AdminController(this._mockRepository.Object);

            // Action
            var result = (Category)controller.EditParentCategory(6).ViewData.Model;

            // Assert
            Assert.IsNull(result);
        }
コード例 #7
0
ファイル: AdminControllerTest.cs プロジェクト: iHunt101/POS-1
        public void CanEditProductCategory()
        {
            // Arrange - create a controller
            var controller = new AdminController(this._mockRepository.Object);

            // Action
            var pc1 = controller.EditParentCategory(1).ViewData.Model as ParentCategory;
            var pc2 = controller.EditParentCategory(2).ViewData.Model as ParentCategory;
            var pc3 = controller.EditParentCategory(3).ViewData.Model as ParentCategory;

            // Assert
            Assert.AreEqual(1, pc1.ParentCategoryId);
            Assert.AreEqual(2, pc2.ParentCategoryId);
            Assert.AreEqual(3, pc3.ParentCategoryId);
        }
コード例 #8
0
ファイル: AdminControllerTest.cs プロジェクト: iHunt101/POS-1
        public void CanEditCategory()
        {
            // Arrange - create a controller
            var controller = new AdminController(this._mockRepository.Object);

            // Action
            var c1 = controller.EditCategory(1).ViewData.Model as Category;
            var c2 = controller.EditCategory(2).ViewData.Model as Category;
            var c3 = controller.EditCategory(3).ViewData.Model as Category;

            // Assert
            Assert.AreEqual(1, c1.CategoryId);
            Assert.AreEqual(2, c2.CategoryId);
            Assert.AreEqual(3, c3.CategoryId);
        }
コード例 #9
0
ファイル: AdminControllerTest.cs プロジェクト: iHunt101/POS-1
        public void CanEditProduct()
        {
            // Arrange - create a controller
            var controller = new AdminController(this._mockRepository.Object);

            // Action
            var p1 = controller.Edit(1).ViewData.Model as Product;
            var p2 = controller.Edit(2).ViewData.Model as Product;
            var p3 = controller.Edit(3).ViewData.Model as Product;

            // Assert
            Assert.AreEqual(1, p1.ProductId);
            Assert.AreEqual(2, p2.ProductId);
            Assert.AreEqual(3, p3.ProductId);
        }
コード例 #10
0
ファイル: AdminControllerTest.cs プロジェクト: iHunt101/POS-1
        public void IndexReturnsEntireProductList()
        {
            // Arrange - create a controller
            var controller = new AdminController(this._mockRepository.Object);

            // Action
            var result = ((IEnumerable<Product>)controller.Index().ViewData.Model).ToArray();

            // Assert
            Assert.AreEqual(result.Length, 5);
            Assert.AreEqual("P1", result[0].Name);
            Assert.AreEqual("P2", result[1].Name);
            Assert.AreEqual("P3", result[2].Name);
            Assert.AreEqual("P4", result[3].Name);
            Assert.AreEqual("P4", result[4].Name);
        }