public async Task CheckIfEditingMovieProjectionReturnsNullReferenceException() { this.SeedDatabase(); var movieProjectionEditViewModel = new MovieProjectionEditViewModel { Id = 3, Date = DateTime.UtcNow.AddDays(2), HallId = 2, CinemaId = 2, MovieId = 2, }; var exception = await Assert .ThrowsAsync <NullReferenceException>(async() => await this.movieProjectionsService.EditAsync(movieProjectionEditViewModel)); Assert.Equal(string.Format(ExceptionMessages.MovieProjectionNotFound, movieProjectionEditViewModel.Id), exception.Message); }
public async Task EditAsync(MovieProjectionEditViewModel movieProjectionEditViewModel) { var movieProjection = await this.movieProjectionsRepository .All() .FirstOrDefaultAsync(g => g.Id == movieProjectionEditViewModel.Id); if (movieProjection == null) { throw new NullReferenceException( string.Format(ExceptionMessages.MovieProjectionNotFound, movieProjectionEditViewModel.Id)); } movieProjection.Date = movieProjectionEditViewModel.Date; movieProjection.MovieId = movieProjectionEditViewModel.MovieId; movieProjection.HallId = movieProjectionEditViewModel.HallId; movieProjection.CinemaId = movieProjectionEditViewModel.CinemaId; movieProjection.ModifiedOn = DateTime.UtcNow; this.movieProjectionsRepository.Update(movieProjection); await this.movieProjectionsRepository.SaveChangesAsync(); }
public async Task <IActionResult> Edit(MovieProjectionEditViewModel movieProjectionEditViewModel) { if (!this.ModelState.IsValid) { var movies = await this.moviesService .GetAllMoviesAsync <MovieDetailsViewModel>(); var halls = await this.hallsService .GetAllHallsAsync <HallDetailsViewModel>(); var cinemas = await this.cinemasService .GetAllCinemasAsync <CinemaDetailsViewModel>(); movieProjectionEditViewModel.Movies = movies; movieProjectionEditViewModel.Halls = halls; movieProjectionEditViewModel.Cinemas = cinemas; return(this.View(movieProjectionEditViewModel)); } await this.movieProjectionsService.EditAsync(movieProjectionEditViewModel); return(this.RedirectToAction("GetAll", "MovieProjections", new { area = "Administration" })); }
public async Task CheckIfEditingMovieProjectionWorksCorrectly() { this.SeedDatabase(); await this.SeedMovieProjections(); var secondHall = new Hall { Category = HallCategory.Medium, Capacity = 50, }; await this.hallsRepository.AddAsync(secondHall); await this.hallsRepository.SaveChangesAsync(); var secondCinema = new Cinema { Name = "Paradise Center", Address = "Sofia", }; await this.cinemasRepository.AddAsync(secondCinema); await this.cinemasRepository.SaveChangesAsync(); var secondMovie = new Movie { Name = "Titanic 2", DateOfRelease = DateTime.UtcNow, Resolution = "HD", Rating = 7.80m, Description = "Test description here", Language = "English", CinemaCategory = CinemaCategory.B, TrailerPath = "test trailer path", CoverPath = "test cover path", WallpaperPath = "test wallpaper path", IMDBLink = "test imdb link", Length = 120, DirectorId = 1, }; await this.moviesRepository.AddAsync(secondMovie); await this.moviesRepository.SaveChangesAsync(); var movieProjectionEditViewModel = new MovieProjectionEditViewModel { Id = this.firstMovieProjection.Id, Date = DateTime.UtcNow.AddDays(2), HallId = 2, CinemaId = 2, MovieId = 2, }; await this.movieProjectionsService.EditAsync(movieProjectionEditViewModel); Assert.Equal(movieProjectionEditViewModel.Date, this.firstMovieProjection.Date); Assert.Equal(movieProjectionEditViewModel.HallId, this.firstMovieProjection.HallId); Assert.Equal(movieProjectionEditViewModel.CinemaId, this.firstMovieProjection.CinemaId); Assert.Equal(movieProjectionEditViewModel.MovieId, this.firstMovieProjection.MovieId); }