예제 #1
0
        public IActionResult Search(SearchExerciseInputModel inputModel, int id = 1)
        {
            if (id <= 0)
            {
                return(this.NotFound());
            }

            const int ItemsPerPage = 15;

            var result = this.exercisesService.GetAllSearched <ExerciseViewModel>(inputModel, id);

            if (result.Count == 0)
            {
                return(this.NotFound());
            }

            var viewModel = new ExercisesListViewModel
            {
                PageNumber   = id,
                ItemsPerPage = ItemsPerPage,
                TotalCount   = result.Count,
                Exercises    = result.Exercises,
                Name         = inputModel.Name,
                BodyPart     = inputModel.BodyPart,
                Difficulty   = inputModel.Difficulty,
                ExerciseType = inputModel.ExerciseType,
                EquipmentId  = inputModel.EquipmentId,
            };

            return(this.View(viewModel));
        }
예제 #2
0
        public IActionResult Index()
        {
            var viewModel = new SearchExerciseInputModel();

            viewModel.Equipments = this.equipmentService.GetAllEquipments();

            return(this.View(viewModel));
        }
예제 #3
0
        public void GetAllSearchedShouldReturnAllSearchedExercises()
        {
            var exercises = new List <Exercise>()
            {
                new Exercise
                {
                    Id           = 1,
                    Name         = "Squat",
                    EquipmentId  = 1,
                    Benefits     = "some test",
                    BodyPart     = BodyPart.Quadriceps,
                    Description  = "the best exercise",
                    Difficulty   = Difficulty.Intermediate,
                    ExerciseType = ExerciseType.Strength,
                    ImageUrl     = "img",
                    Equipment    = new Equipment {
                        Id = 1, Name = "Barbell"
                    },
                },
            };

            var service = new ExercisesService(this.exerciseRepository.Object);

            this.exerciseRepository
            .Setup(x => x.All())
            .Returns(exercises
                     .AsQueryable());

            var inputModel = new SearchExerciseInputModel
            {
                Name         = "Squat",
                EquipmentId  = 1,
                BodyPart     = BodyPart.Quadriceps,
                Difficulty   = Difficulty.Intermediate,
                ExerciseType = ExerciseType.Strength,
            };

            AutoMapperConfig.RegisterMappings(typeof(TestExerciseModel).Assembly);

            var result = service.GetAllSearched <TestExerciseModel>(inputModel, 1);

            Assert.Equal(1, result.Count);
            Assert.Equal("Squat", result.Exercises.FirstOrDefault().Name);
            Assert.Equal(1, result.Exercises.FirstOrDefault().EquipmentId);
            Assert.Equal(BodyPart.Quadriceps, result.Exercises.FirstOrDefault().BodyPart);
            Assert.Equal(Difficulty.Intermediate, result.Exercises.FirstOrDefault().Difficulty);
            Assert.Equal(ExerciseType.Strength, result.Exercises.FirstOrDefault().ExerciseType);
        }