public async Task CheckAddingMovieProjectionWithMissingMovie() { this.SeedDatabase(); var movieProjection = new MovieProjectionCreateInputModel { Date = DateTime.UtcNow, MovieId = 3, HallId = this.firstHall.Id, CinemaId = this.firstCinema.Id, }; var exception = await Assert .ThrowsAsync <NullReferenceException>(async() => await this.movieProjectionsService.CreateAsync(movieProjection)); Assert.Equal(string.Format(ExceptionMessages.MovieNotFound, movieProjection.MovieId), exception.Message); }
public async Task CheckIfAddingMovieProjectionWorksCorrectly() { this.SeedDatabase(); var model = new MovieProjectionCreateInputModel { Date = DateTime.UtcNow, MovieId = this.firstMovie.Id, HallId = this.firstHall.Id, CinemaId = this.firstCinema.Id, }; await this.movieProjectionsService.CreateAsync(model); var count = await this.movieProjectionsRepository.All().CountAsync(); Assert.Equal(1, count); }
public async Task CheckAddingAlreadyExistingMovieProjection() { this.SeedDatabase(); await this.SeedMovieProjections(); var movieProjection = new MovieProjectionCreateInputModel { Date = this.firstMovieProjection.Date, MovieId = this.firstMovieProjection.MovieId, HallId = this.firstMovieProjection.HallId, CinemaId = this.firstMovieProjection.CinemaId, }; var exception = await Assert .ThrowsAsync <ArgumentException>(async() => await this.movieProjectionsService.CreateAsync(movieProjection)); Assert.Equal(string.Format(ExceptionMessages.MovieProjectionAlreadyExists, movieProjection.MovieId, movieProjection.HallId), exception.Message); }
public async Task CheckIfCreatingMovieProjectionReturnsViewModel() { this.SeedDatabase(); var movieProjection = new MovieProjectionCreateInputModel { MovieId = 1, HallId = 1, CinemaId = 1, }; var viewModel = await this.movieProjectionsService.CreateAsync(movieProjection); var dbEntry = await this.movieProjectionsRepository.All().FirstOrDefaultAsync(); Assert.Equal(dbEntry.MovieId, viewModel.Movie.Id); Assert.Equal(dbEntry.HallId, viewModel.Hall.Id); Assert.Equal(dbEntry.CinemaId, viewModel.Cinema.Id); }
public async Task CheckSettingsOfMovieProjectionProperties() { this.SeedDatabase(); var model = new MovieProjectionCreateInputModel { Date = DateTime.UtcNow, MovieId = this.firstMovie.Id, HallId = this.firstHall.Id, CinemaId = this.firstCinema.Id, }; await this.movieProjectionsService.CreateAsync(model); var movieProjection = await this.movieProjectionsRepository.All().FirstOrDefaultAsync(); Assert.Equal(this.firstMovie.Id, movieProjection.MovieId); Assert.Equal(this.firstHall.Id, movieProjection.HallId); Assert.Equal(this.firstCinema.Id, movieProjection.CinemaId); }
public async Task <IActionResult> Create() { var movies = await this.moviesService .GetAllMoviesAsync <MovieDetailsViewModel>(); var halls = await this.hallsService .GetAllHallsAsync <HallDetailsViewModel>(); var cinemas = await this.cinemasService .GetAllCinemasAsync <CinemaDetailsViewModel>(); var viewModel = new MovieProjectionCreateInputModel { Movies = movies, Halls = halls, Cinemas = cinemas, }; return(this.View(viewModel)); }
public async Task <IActionResult> Create(MovieProjectionCreateInputModel model) { 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>(); model.Movies = movies; model.Halls = halls; model.Cinemas = cinemas; return(this.View(model)); } await this.movieProjectionsService.CreateAsync(model); return(this.RedirectToAction("GetAll", "MovieProjections", new { area = "Administration" })); }
public async Task <MovieProjectionDetailsViewModel> CreateAsync(MovieProjectionCreateInputModel model) { var movie = await this.moviesRepository .All() .FirstOrDefaultAsync(m => m.Id == model.MovieId); if (movie == null) { throw new NullReferenceException( string.Format(ExceptionMessages.MovieNotFound, model.MovieId)); } var hall = await this.hallsRepository .All() .FirstOrDefaultAsync(h => h.Id == model.HallId); if (hall == null) { throw new NullReferenceException( string.Format(ExceptionMessages.HallNotFound, model.HallId)); } var cinema = await this.cinemasRepository .All() .FirstOrDefaultAsync(c => c.Id == model.CinemaId); if (cinema == null) { throw new NullReferenceException( string.Format(ExceptionMessages.CinemaNotFound, model.CinemaId)); } var movieProjection = new MovieProjection { Date = model.Date, Movie = movie, MovieId = model.MovieId, Hall = hall, HallId = model.HallId, Cinema = cinema, CinemaId = model.CinemaId, }; bool doesMovieProjectionExist = await this.movieProjectionsRepository .All() .AnyAsync(x => x.MovieId == movieProjection.MovieId && x.HallId == movieProjection.HallId); if (doesMovieProjectionExist) { throw new ArgumentException( string.Format(ExceptionMessages.MovieProjectionAlreadyExists, movieProjection.MovieId, movieProjection.HallId)); } await this.movieProjectionsRepository.AddAsync(movieProjection); await this.movieProjectionsRepository.SaveChangesAsync(); var viewModel = await this.GetViewModelByIdAsync <MovieProjectionDetailsViewModel>(movieProjection.Id); return(viewModel); }