예제 #1
0
        public async Task SetDemandAsync(int userId, double totalCalories, double proteins, double carbohydrates, double fats)
        {
            var athlete = await _athleteRepository.GetOrFailAsync(userId);

            if (athlete.CaloricDemand is not null)
            {
                await UpdateDemandAsync(userId, totalCalories, proteins, carbohydrates, fats);

                return;
            }

            athlete.CaloricDemand = CaloricDemand.Create(totalCalories, proteins, carbohydrates, fats);

            await _athleteRepository.UpdateAsync(athlete);
        }
예제 #2
0
        public async Task DeleteAsync(int userId)
        {
            var athlete = await _athleteRepository.GetOrFailAsync(userId);

            _logger.LogInfo($"Athlete with user id: '{userId}' was removed.");

            await _athleteRepository.DeleteAsync(athlete);
        }
        public async Task SetDemandAsync_ShouldSetCalorieDemand_WhenDataIsValid(int userId, double totalCalories,
                                                                                double proteins, double carbohydrates, double fats)
        {
            var athlete = _fixture.Build <Athlete>()
                          .With(a => a.UserId, userId)
                          .Without(a => a.AthleteExercises)
                          .Without(a => a.AthleteProducts)
                          .Without(a => a.CaloricDemand)
                          .Create();

            _athleteRepository.GetOrFailAsync(userId).Returns(athlete);

            await _sut.SetDemandAsync(userId, totalCalories, proteins, carbohydrates, fats);

            await _athleteRepository.Received(1).UpdateAsync(Arg.Is <Athlete>(a =>
                                                                              a.UserId == userId &&
                                                                              a.CaloricDemand.TotalCalories == totalCalories &&
                                                                              a.CaloricDemand.Proteins == proteins &&
                                                                              a.CaloricDemand.Carbohydrates == carbohydrates &&
                                                                              a.CaloricDemand.Fats == fats
                                                                              ));
        }
예제 #4
0
        public async Task DeleteAsync_ShouldDeleteAthlete_WhenAthleteExists()
        {
            var userId  = 5;
            var athlete = _fixture.Build <Athlete>()
                          .With(a => a.UserId, userId)
                          .Without(a => a.AthleteExercises)
                          .Without(a => a.AthleteProducts)
                          .Create();

            _athleteRepository.GetOrFailAsync(userId).Returns(athlete);

            await _sut.DeleteAsync(athlete.UserId);

            await _athleteRepository.Received(1).DeleteAsync(Arg.Any <Athlete>());
        }