public void IfThereIsNoCurrentWorkoutAnExceptionIsThrown()
        {
            var ws = new Mock<IWorkoutService>();
            var repo = new Mock<IExerciseRepository>();
            var handler = new AddStrengthCommandHandler(ws.Object, repo.Object);
            var command = new AddStrengthCommand { Weight = 20, ExerciseId = 1, Repetitions = 99, Notes = "foo" };

            ws.Setup(x => x.CurrentWorkout()).Returns<Workout>(null);
            repo.Setup(x => x.Load(1)).Returns(new Exercise(new ExerciseDocument { Description = "exer" }));

            Assert.Throws<ApplicationException>(() => handler.Handle(command));
        }
        public void TheStrengthActivityIsAddedToTheCurrentWorkout()
        {
            var workOut = new Workout(new WorkoutDocument());
            var repo = new Mock<IExerciseRepository>();
            var ws = new Mock<IWorkoutService>();
            var handler = new AddStrengthCommandHandler(ws.Object, repo.Object);
            var command = new AddStrengthCommand { Weight = 20, ExerciseId = 1, Repetitions= 99, Notes = "foo" };

            ws.Setup(x => x.CurrentWorkout()).Returns(workOut);
            repo.Setup(x => x.Load(1)).Returns(new Exercise(new ExerciseDocument { Description = "exer" }));
            handler.Handle(command);

            workOut.StrengthSegments.Count().ShouldEqual(1);
        }
Пример #3
0
        public ActionResult Strength(AddStrengthInputModel input)
        {
            if (!ModelState.IsValid) return View(input);

            var command = new AddStrengthCommand
                {
                    ExerciseId = input.ExerciseId,
                    Notes = input.Notes,
                    Repetitions = input.Repetitions,
                    Weight = input.Weight
                };

            _commandInvoker.Execute(command);

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