public ActionResult Edit(Establishment establishment, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                if (image != null)
                {
                    establishment.ImageMimeType = image.ContentType;
                    establishment.ImageData = new byte[image.ContentLength];
                    image.InputStream.Read(establishment.ImageData, 0, image.ContentLength);
                }

                _establishmentRepository.SaveEstablishment(establishment);
                // TODO: _establishmentRepository.Add(establishment);
                TempData["message"] = string.Format("Establishment {0} has been saved", establishment.Name);
                return RedirectToAction("Index");
            }
            else
            {
                // there is something wrong with the data values
                return View(establishment);
            }
        }
        public void CanDeleteValidEstablishments()
        {
            // Arrange - create a establishment
            var establishment = new Establishment {EstablishmentId = 2, Name = "Test"};

            // Arrange - create a local mock repository
            var localMock = new Mock<IEstablishmentRepository>();
            localMock.Setup(m => m.Establishments).Returns(new[]
                {
                    new Establishment {EstablishmentId = 1, Name = "P1"},
                    establishment,
                    new Establishment {EstablishmentId = 3, Name = "P3"}
                }.AsQueryable());

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

            // Action - delete the product
            controller.Delete(establishment.EstablishmentId);

            // assert - ensure that the repository Delete method was called with the correct Product
            localMock.Verify(m => m.DeleteEstablishment(establishment));
        }
        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));
        }
        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));
        }