Ejemplo n.º 1
0
        public Exercise Execute(AddExerciseCommand command)
        {
            var exercise = new Exercise()
            {
                ExerciseName = command.ExerciseName, BodyPartsUsed = command.BodyParts
            };

            return(this.repository.AddExercise(exercise));
        }
Ejemplo n.º 2
0
        public void ANewExerciseIsAddedToTheRepository()
        {
            var repo    = new Mock <IExerciseRepository>();
            var command = new AddExerciseCommand("foo", ExerciseType.Strength);
            var handler = new AddExerciseCommandHandler(repo.Object);

            repo.Setup(x => x.Add(It.Is <Exercise>(ex => ex.Description == "foo" && ex.ExerciseType == ExerciseType.Strength))).Verifiable();

            handler.Handle(command);

            repo.VerifyAll();
        }
        public void AddExerciseCommand_Adds_Exercise()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddDbContext <PeSportsTrackingContext>(
                o => o.UseInMemoryDatabase("test"), ServiceLifetime.Transient);
            var provider = serviceCollection.BuildServiceProvider();

            var addUnitCommandHandler = new AddExerciseCommand.AddExerciseCommandHandler(provider.GetService <PeSportsTrackingContext>());
            var command = new AddExerciseCommand(2, "name", "comment");

            // Act
            var result   = addUnitCommandHandler.Handle(command);
            var exercise = provider.GetService <PeSportsTrackingContext>().Exercises.FirstOrDefault();

            // Assert
            Assert.That(result.IsSuccess, Is.True);
            Assert.That(exercise.Name, Is.EqualTo("name"));
            Assert.That(exercise.Comment, Is.EqualTo("comment"));
        }
Ejemplo n.º 4
0
        public IActionResult AddExercise([FromBody] AddExerciseCommand command)
        {
            _commandsBus.Send(command);

            return(Ok());
        }