public ActionResult Edit(Product product)
        {
            if (!ModelState.IsValid)
            {
                return View(product);
            }
            _productRepository.Save(product);

            return RedirectToAction("index");
        }
        public void Edit_should_save_and_redirect_when_no_model_errors_present()
        {
            var goodProduct = new Product {Name = "Good value"};

            var repository =
                MockRepository.GenerateStub<IProductRepository>();

            var productsController = new ProductsController(repository);

            ActionResult result = productsController.Edit(goodProduct);

            repository.AssertWasCalled(rep => rep.Save(goodProduct));
            var redirectResult = result as RedirectToRouteResult;
            Assert.IsNotNull(redirectResult);
            Assert.AreEqual(1, redirectResult.RouteValues.Count);
            Assert.AreEqual("index", redirectResult.RouteValues["action"]);
        }
        public void Edit_should_redirect_back_when_model_errors_present()
        {
            var badProduct = new Product {Name = "Bad value"};

            var repository =
                MockRepository.GenerateStub<IProductRepository>();

            var controller = new ProductsController(repository);
            controller.ModelState
                .AddModelError("Name",
                               "Name already exists");

            ActionResult result = controller.Edit(badProduct);

            Assert.AreEqual("", result.AssertViewRendered().ViewName);
            repository.AssertWasNotCalled(rep => rep.Save(badProduct));
        }
 public void Save(Product product)
 {
 }