Beispiel #1
0
        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));
        }
Beispiel #2
0
        public void CannotEditNonexistentProduct()
        {
            // Arrange - create a controller
            var controller = new AdminController(this._mockRepository.Object);

            // Action
            var result = (Product)controller.Edit(6).ViewData.Model;

            // Assert
            Assert.IsNull(result);
        }
Beispiel #3
0
        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));
        }
Beispiel #4
0
        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);
        }