Exemplo n.º 1
0
        public async Task EditExerciseAsyncShouldThrow(
            string exerciseName,
            string exerciseEditedName)
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;
            var db = new ApplicationDbContext(options);
            var exercisesRepository = new EfDeletableEntityRepository <Exercise>(db);
            var cloudinaryService   = new Mock <ICloudinaryService>();
            var fileMock            = new Mock <IFormFile>();

            var service = new ExercisesService(exercisesRepository, cloudinaryService.Object);

            var inputModel = new AddExerciseInputModel()
            {
                Name       = exerciseName,
                Difficulty = Difficulty.Easy,
                Type       = ExerciseType.Abs,
                VideoFile  = fileMock.Object,
            };

            var exercise = await service.AddExerciseAsync(inputModel);

            var editInputModel = new EditExerciseInputModel()
            {
                Id         = exercise.Id,
                Name       = exerciseEditedName,
                Difficulty = Difficulty.Easy,
                Type       = ExerciseType.Abs,
                VideoUrl   = "some video url",
                VideoFile  = fileMock.Object,
            };

            Assert.DoesNotContain(exerciseEditedName, exercisesRepository.All().Select(x => x.Name));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(EditExerciseInputModel model)
        {
            //TODO: Fix secondaryMuscleGroups binding
            string exerciseId = RouteData.Values["Id"].ToString();

            var result = await this.exercisesService
                         .EditExercise(exerciseId, model);

            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Edit(EditExerciseInputModel inputModel)
        {
            if (!this.ModelState.IsValid || !this.cloudinaryService.IsVideoFileValid(inputModel.VideoFile))
            {
                if (!this.cloudinaryService.IsVideoFileValid(inputModel.VideoFile))
                {
                    this.ModelState.AddModelError("VideoFile", "Please enter a valid video format!");
                }

                return(this.View(inputModel));
            }

            await this.exercisesService.EditExerciseAsync(inputModel);

            return(this.Redirect($"/Trainers/Exercises/Details/{inputModel.Id}"));
        }
Exemplo n.º 4
0
        public async Task <Exercise> EditExerciseAsync(EditExerciseInputModel inputModel)
        {
            var exercise = await this.exercisesRepository
                           .All()
                           .FirstOrDefaultAsync(x => x.Id == inputModel.Id);

            exercise.Name       = inputModel.Name;
            exercise.Type       = inputModel.Type;
            exercise.Difficulty = inputModel.Difficulty;
            exercise.VideoUrl   = inputModel.VideoFile ==
                                  null || !this.cloudinaryService.IsVideoFileValid(inputModel.VideoFile)
                ? exercise.VideoUrl
                : await this.cloudinaryService.UploadVideoAsync(inputModel.VideoFile);

            await this.exercisesRepository.SaveChangesAsync();

            return(exercise);
        }