Пример #1
0
        public void CanEditEstablishment()
        {
            // Arrange - create a controller
            var controller = new EstablishmentController(_mockRepository.Object);

            // Action
            var e1 = controller.Edit(1).ViewData.Model as Establishment;
            var e2 = controller.Edit(2).ViewData.Model as Establishment;
            var e3 = controller.Edit(3).ViewData.Model as Establishment;

            // Assert
            Assert.AreEqual(1, e1.EstablishmentId);
            Assert.AreEqual(2, e2.EstablishmentId);
            Assert.AreEqual(3, e3.EstablishmentId);
        }
Пример #2
0
        public void CannotEditNonexistentProduct()
        {
            // Arrange - create a controller
            var controller = new EstablishmentController(_mockRepository.Object);

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

            // Assert
            Assert.IsNull(result);
        }
Пример #3
0
        public void CanSaveValidChanges()
        {
            // Arrange - create a controller
            var controller = new EstablishmentController(_mockRepository.Object);
            // Arrange - create a product
            var establishment = new Establishment {
                Name = "Test"
            };

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

            // Assert - check that the repository was called
            _mockRepository.Verify(m => m.SaveEstablishment(establishment));
            // Assert - check the method result type
            Assert.IsNotInstanceOfType(result, typeof(ViewResult));
        }
Пример #4
0
        public void CannotSaveInvalidChanges()
        {
            // Arrange - create a controller
            var controller = new EstablishmentController(_mockRepository.Object);
            // Arrange - create a product
            var establishment = new Establishment {
                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(establishment, null);

            // Assert - check that the repository was called
            _mockRepository.Verify(m => m.SaveEstablishment(It.IsAny <Establishment>()), Times.Never());
            // Assert - check the method result type
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }