public async Task DeleteWorkoutShouldWorkCorrectly() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; var dbContext = new ApplicationDbContext(options); var position = new Position { Name = PositionName.PowerForward, Description = "Power Forward position", Playstyle = "You play like a PF", }; var workout = new Workout { Name = "Workout Five", Description = "Some kind of randommm description again", PositionId = position.Id, VideoUrl = "test youtube link 5", ImageUrl = "5testimg", }; var workoutsRepository = new EfDeletableEntityRepository <Workout>(dbContext); var positionsRepository = new EfDeletableEntityRepository <Position>(dbContext); var positionsService = new PositionsService(positionsRepository); var moqCloudinaryService = new Mock <ICloudinaryService>(); var coachRepository = new EfDeletableEntityRepository <Coach>(dbContext); var coachesService = new CoachesService(coachRepository, moqCloudinaryService.Object); var service = new WorkoutsService(moqCloudinaryService.Object, workoutsRepository, positionsService, coachesService); var workoutId = workout.Id; await dbContext.Positions.AddAsync(position); await dbContext.Workouts.AddAsync(workout); await dbContext.SaveChangesAsync(); await service.DeleteAsync(workoutId); var workoutxd = service.GetWorkoutById(workoutId); Assert.Null(workoutxd); }
private bool SetStarState(int Id, bool newState) { var userId = Guid.Parse(User.Identity.GetUserId()); var service = new WorkoutsService(userId); var detail = service.GetWorkoutById(Id); var updateWorkout = new WorkoutsEdit { Id = detail.Id, Name = detail.Name, //Ratings = detail.Ratings, IsStarred = newState }; return(service.UpdateWorkout(updateWorkout)); }
public void GetWorkoutByIdShouldReturnNullIfWorkoutDoesntExist() { var workouts = new List <Workout> { new Workout { Id = "workoutId123", Name = "Workout One", Description = "Some kind of workout description", Position = new Position { Name = PositionName.ShootingGuard, Description = "Shooting guard position", Playstyle = "You play like a shooting guard", }, VideoUrl = "test youtube link", }, new Workout { Id = "workoutId456", Name = "Workout Two", Description = "Some kind of random description", Position = new Position { Name = PositionName.PointGuard, Description = "Point guard position", Playstyle = "You play like a point guard", }, VideoUrl = "test youtube link 2", }, }; var positionsService = new PositionsService(this.positionsRepository.Object); var coachesService = new CoachesService(this.coachRepository.Object, this.moqCloudinaryService.Object); this.workoutsRepository.Setup(r => r.AllAsNoTracking()).Returns(() => workouts.AsQueryable()); var service = new WorkoutsService(this.moqCloudinaryService.Object, this.workoutsRepository.Object, positionsService, coachesService); var workout = service.GetWorkoutById("notexistingworkout"); Assert.Null(workout); this.workoutsRepository.Verify(x => x.AllAsNoTracking(), Times.Once); }
public async Task EditWorkoutShouldUpdateCorrectly() { var workouts = new List <Workout> { new Workout { Id = "workoutId2312312312312", Name = "Workout Five", Description = "Some kind of randommm description again", Position = new Position { Id = "PositionFive", Name = PositionName.PowerForward, Description = "Power Forward position", Playstyle = "You play like a PF", }, PositionId = "PositionFive", VideoUrl = "test youtube link 5", Picture = new Picture { Id = "5pic", Url = "test 5url" }, PictureId = "5pic", ImageUrl = "5testimg", AddedByCoach = new Coach { Id = "c5", Name = "Coach5", Description = "desc5", Experience = 9, Phone = "34435212", Email = "*****@*****.**", User = new ApplicationUser { Id = "coachuser5" }, UserId = "coachuser5", Picture = new Picture { Id = "cpic5", Url = "test xurl5" }, PictureId = "cpic5", }, CoachId = "c5", }, }; this.positionsRepository.Setup(r => r.AllAsNoTracking()).Returns(() => new List <Position> { new Position { Id = "PositionFive", Name = PositionName.PowerForward, Description = "Power Forward position", Playstyle = "You play like a PF", }, }.AsQueryable()); var positionsService = new PositionsService(this.positionsRepository.Object); var coachesService = new CoachesService(this.coachRepository.Object, this.moqCloudinaryService.Object); this.workoutsRepository.Setup(r => r.AllAsNoTracking()).Returns(() => workouts.AsQueryable()); var service = new WorkoutsService(this.moqCloudinaryService.Object, this.workoutsRepository.Object, positionsService, coachesService); var model = new EditWorkoutViewModel { Id = "workoutId2312312312312", Name = "Changed name", Description = "Some kind of randommm description again", PositionName = PositionName.PowerForward, VideoUrl = "test youtube link CHANGED", CoachId = "c5", }; await service.EditAsync(model); var workout = service.GetWorkoutById("workoutId2312312312312"); Assert.Equal("Changed name", workout.Name); Assert.Equal("test youtube link CHANGED", workout.VideoUrl); this.workoutsRepository.Verify(x => x.AllAsNoTracking(), Times.AtMost(2)); }