public void Cannot_Create_Empty_Expense()
 {
     // Arrange
     ExpenseController controller = new ExpenseController(commandBus.Object, categoryRepository.Object, expenseRepository.Object);
     // The MVC pipeline doesn't run, so binding and validation don't run.
     controller.ModelState.AddModelError("", "mock error message");
     Mapper.CreateMap<ExpenseFormModel, CreateOrUpdateExpenseCommand>();
     // Act
     ExpenseFormModel expense = new ExpenseFormModel();
     expense.ExpenseId = 0;
     var result = controller.Save(expense) 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);
 }
 public void Create_Expense_Redirects_To_Index()
 {
     // Arrange
     ExpenseController controller = new ExpenseController(commandBus.Object, categoryRepository.Object, expenseRepository.Object);
     commandBus.Setup(c => c.Submit(It.IsAny<CreateOrUpdateExpenseCommand>())).Returns(new CommandResult(true));
     Mapper.CreateMap<ExpenseFormModel, CreateOrUpdateExpenseCommand>();
     // Act
     ExpenseFormModel expense = new ExpenseFormModel
     {
         Transaction = "Mock Transaction",
         Date = DateTime.Now,
         Amount = 1000,
         CategoryId = 1
     };
     var result = controller.Save(expense) as RedirectToRouteResult;
     // Assert
     Assert.AreEqual("Index", result.RouteValues["action"]);
 }