public void Create_Category_Redirects_To_Index()
 {
     // Arrange
     CategoryController controller = new CategoryController(commandBus.Object, categoryRepository.Object);
     commandBus.Setup(c => c.Submit(It.IsAny<CreateOrUpdateCategoryCommand>())).Returns(new CommandResult(true));
     // Act
     CategoryFormModel category = new CategoryFormModel();
     category.CategoryId = 0;
     category.Name = "Mock Category";
     Mapper.CreateMap<CategoryFormModel, CreateOrUpdateCategoryCommand>();
     var result = controller.Save(category) as RedirectToRouteResult;
     // Assert
     Assert.AreEqual("Index", result.RouteValues["action"]);
 }
 public void Cannot_Create_Empty_Category()
 {
     // Arrange
     CategoryController controller = new CategoryController(commandBus.Object, categoryRepository.Object);
     // The MVC pipeline doesn't run, so binding and validation don't run.
     controller.ModelState.AddModelError("", "mock error message");
     Mapper.CreateMap<CategoryFormModel, CreateOrUpdateCategoryCommand>();
     // Act
     CategoryFormModel category = new CategoryFormModel();
     category.CategoryId = 0;
     category.Name = string.Empty;
     var result = controller.Save(category) as ViewResult;
     // Assert -  check that we are passing an invalid model to the view
     Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
     Assert.AreEqual("Create", result.ViewName);
 }