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);
        }
        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
                                                                              ));
        }
        public async Task AddAsync_ShouldAddExercise_WhenAthleteExistsAndExerciseExistsAndDataIsValid(int userId,
                                                                                                      int exerciseId, double weight, int numberOfSets, int numberOfReps, string dayName)
        {
            var athlete = _fixture.Build <Athlete>()
                          .With(a => a.UserId, userId)
                          .With(a => a.AthleteExercises, new List <AthleteExercise>())
                          .With(a => a.AthleteProducts, new List <AthleteProduct>())
                          .Create();

            var exercise = _fixture.Build <Exercise>()
                           .With(e => e.Id, exerciseId)
                           .Create();

            _athleteRepository.FindByCondition(Arg.Any <Expression <Func <Athlete, bool> > >(),
                                               Arg.Any <Func <IQueryable <Athlete>, IIncludableQueryable <Athlete, object> > >()).Returns(athlete);

            _exerciseRepository.GetAsync(exerciseId).Returns(exercise);


            await _sut.AddAsync(userId, exerciseId, weight, numberOfSets, numberOfReps, dayName);

            await _athleteRepository.Received(1).UpdateAsync(athlete);
        }
Example #4
0
        public async Task AddAsync_ShouldAddProduct_WhenAthleteExistsAndProductExistsAndWeightIsValid(int userId, int productId,
                                                                                                      double weight)
        {
            var product = _fixture.Build <Product>().With(p => p.Id, productId).Create();

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

            _athleteRepository.FindByCondition(Arg.Any <Expression <Func <Athlete, bool> > >(),
                                               Arg.Any <Func <IQueryable <Athlete>, IIncludableQueryable <Athlete, object> > >()).Returns(athlete);

            _productRepository.GetAsync(productId).Returns(product);

            await _sut.AddAsync(userId, productId, weight);

            await _athleteRepository.Received(1).UpdateAsync(Arg.Is(athlete));
        }