public void AfterAnExcerciseIsAddedTheUserIsShownAConfirmationPage()
            {
                var model = new AddExerciseInputModel();
                var invoker = new Mock<ICommandInvoker>();
                var controller = new ExercisesController(invoker.Object, null);

                var result = (RedirectToRouteResult) controller.Add(model);
                result.RouteName.ShouldEqual("");
            }
            public void WhenTheInputModelIsNotValidTheUserIsShownTheAddView()
            {
                var model = new AddExerciseInputModel();
                var invoker = new Mock<ICommandInvoker>();
                var controller = new ExercisesController(invoker.Object, null);
                controller.ModelState.AddModelError("foo", "bad");

                var result = (ViewResult) controller.Add(model);
                result.ViewName.ShouldEqual("Index");
            }
Exemplo n.º 3
0
 public ActionResult Add(AddExerciseInputModel inputModel)
 {
     if (ModelState.IsValid)
     {
         _invoker.Execute(new AddExerciseCommand(inputModel.Description, inputModel.Type));
         TempData["Message"] = "Added new {0} exercise -- {1}".ToFormat(inputModel.Type, inputModel.Description);
         return RedirectToAction("Index");
     }
     else
     {
         return View("Index", inputModel);
     }
 }
            public void WhenTheInputModelIsValidAnExerciseIsAdded()
            {
                var inputModel = new AddExerciseInputModel {Description = "foo", Type = ExerciseType.Cardio};
                var invoker = new Mock<ICommandInvoker>();
                invoker.Setup(
                    i => i.Execute(
                        It.Is<AddExerciseCommand>(
                            c => c.Description == inputModel.Description && c.Type == inputModel.Type)));
                var controller = new ExercisesController(invoker.Object, null);

                controller.Add(inputModel);

                invoker.VerifyAll();
            }