Exemplo n.º 1
0
            public void TheUserIsRedirectedToTheWorkoutSummary()
            {
                var invoker = new Mock<ICommandInvoker>();
                var controller = new AddController(invoker.Object, null);
                var input = new AddCardioInputModel { ExerciseId = 1, Level = 1, Duration = 45, Notes = string.Empty };

                var result = (RedirectToRouteResult)controller.Cardio(input);
                result.RouteValues["action"].ShouldEqual("Index");
            }
Exemplo n.º 2
0
            public void AnAddCommandIsSubmitted()
            {
                var invoker = new Mock<ICommandInvoker>();
                var controller = new AddController(invoker.Object, null);
                var input = new AddCardioInputModel {ExerciseId = 1, Level = 1, Duration = 45, Notes = string.Empty};

                var result = controller.Cardio(input);

                invoker.Verify(i => i.Execute(It.Is<AddCardioCommand>(cmd => cmd.Duration == input.Duration && cmd.ExerciseId == input.ExerciseId && cmd.Level == input.Level && cmd.Notes == input.Notes)));
            }
Exemplo n.º 3
0
            public void IfTheModelStateIsNotValidTheUserIsPromptedToReEnter()
            {
                var invoker = new Mock<ICommandInvoker>();
                var controller = new AddController(invoker.Object, null);
                controller.ModelState.AddModelError("Level", "foo");
                var input = new AddCardioInputModel { ExerciseId = 1, Level = 1, Duration = 45, Notes = string.Empty };

                var res = (ViewResult) controller.Cardio(input);

                res.ViewName.ShouldEqual("");
            }
Exemplo n.º 4
0
        public ActionResult Cardio(AddCardioInputModel input)
        {
            if (!ModelState.IsValid) return View(input);

            var command = new AddCardioCommand
                {
                    Duration = input.Duration,
                    ExerciseId = input.ExerciseId,
                    Level = input.Level,
                    Notes = input.Notes
                };

            _commandInvoker.Execute(command);

            return RedirectToAction("Index", "Workout");
        }