public async Task SetDemandAsync_ShouldUpdateDemandAsync_WhenDemandIsAlreadySet(int userId, double totalCalories,
                                                                                        double proteins, double carbohydrates, double fats)
        {
            var newTotalCalories = totalCalories + 200;
            var newProteins      = proteins + 20;

            var calorieDemand = _fixture.Build <CaloricDemand>()
                                .With(cd => cd.TotalCalories, totalCalories)
                                .With(cd => cd.Proteins, proteins)
                                .With(cd => cd.Carbohydrates, carbohydrates)
                                .With(cd => cd.Fats, fats)
                                .Create();

            var athlete = _fixture.Build <Athlete>()
                          .With(a => a.UserId, userId)
                          .With(a => a.CaloricDemand, calorieDemand)
                          .Without(a => a.AthleteExercises)
                          .Without(a => a.AthleteProducts)
                          .Create();

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

            await _sut.SetDemandAsync(userId, newTotalCalories, newProteins, carbohydrates, fats);

            await _athleteRepository.Received(1).UpdateAsync(Arg.Is <Athlete>(a =>
                                                                              a.UserId == userId &&
                                                                              a.CaloricDemand.TotalCalories == newTotalCalories &&
                                                                              a.CaloricDemand.Proteins == newProteins &&
                                                                              a.CaloricDemand.Carbohydrates == carbohydrates &&
                                                                              a.CaloricDemand.Fats == fats));
        }
        public static async Task CheckIfAthleteAsync(this IAthleteRepository repository, User user, string roleName)
        {
            var athlete = await repository.GetAsync(user.Id);

            if (athlete is null && roleName != RoleId.Admin.ToString())
            {
                athlete = new Athlete(user);
                await repository.AddAsync(athlete);
            }
        }
        public static async Task <Athlete> GetOrFailAsync(this IAthleteRepository repository, int userId)
        {
            var athlete = await repository.GetAsync(userId);

            if (athlete == null)
            {
                throw new AthleteNotFoundException(userId);
            }

            return(athlete);
        }
        public async Task GetAsync_ShouldReturnAthleteDto(int id)
        {
            var athlete = _fixture.Build <Athlete>()
                          .Without(a => a.AthleteExercises)
                          .Without(a => a.AthleteProducts)
                          .Create();

            _athleteRepository.GetAsync(id).Returns(athlete);

            var dto = await _sut.GetAsync(id);

            dto.ShouldNotBeNull();
            dto.Id.ShouldBe(athlete.Id);
            dto.UserId.ShouldBe(athlete.UserId);
            await _athleteRepository.Received(1).GetAsync(id);
        }
Esempio n. 5
0
        public async Task <AthleteDto> GetAsync(int userId)
        {
            var athlete = await _athleteRepository.GetAsync(userId);

            return(_mapper.Map <AthleteDto>(athlete));
        }