public ActionResult CreateCategory(CategoryView categoryView)
        {
            if (ModelState.IsValid)
            {
                categoryView.DateAdded = DateTime.Now;
                categoryView.AddedBy = HttpContext.User.Identity.Name;
                categoryView.Path = categoryView.Title.Trim().Replace(' ', '-');
                string msg = "Category {0} has been created";
                using (var repository = _repositoryProvider.GetRepository())
                {
                    Category category;
                    if (categoryView.CategoryExists)
                    {
                        category = repository.Get<Category>().Where(
                            c => c.Title == categoryView.Title).
                            FirstOrDefault();
                        Mapper.Map(categoryView, category);

                        msg = "Category {0} has been updated";
                    }
                    else
                    {
                        category = Mapper.Map<CategoryView, Category>(categoryView);

                        category.ImageUrl =
                            string.Format("~/Content/images/category/{0}", categoryView.ImageUrl);
                    }
                    repository.SaveOrUpdate(category);
                    ViewBag.SuccessMessage = string.Format(msg, categoryView.Title);
                }
                return RedirectToAction("Index");
            }

            return View(categoryView);
        }
        public void CreateCategory_Redirects_To_ManageArticles_After_Creating_Category()
        {
            var categoryController = CreateController<CategoryController>();
            var category = new Category { Title = "Pies", Path = "All Pies" };
            MockRepository.Setup(x => x.Save(category));
            var categoryView = new CategoryView { Title = "Pies", Path = "All Pies" };

            ActionResult result = categoryController.CreateCategory(categoryView);

            Assert.That(result, Is.TypeOf<RedirectToRouteResult>());
        }