示例#1
0
        public async Task EditMovieShouldThrowIfIdIsNotFound()
        {
            var repository = new EfDeletableEntityRepository <Movie>(new ApplicationDbContext(this.options.Options));
            var service    = new MoviesService(repository);

            var diffMovie = new AddMovieInputModel
            {
                Id              = 5,
                Name            = "Taxi 2",
                Year            = 2000,
                Actors          = "Samy Naceri, Frédéric Diefenthal, Marion Cotillard",
                AgeRestriction  = 0,
                Description     = "funny",
                Director        = "Gérard Pirès",
                Duration        = 86,
                Rating          = 7.5,
                Price           = 8,
                Genre           = "Action, Comedy, Crime",
                TrailerUrl      = "url",
                TrailerVideoUrl = "url",
            };

            await service.AddAsync(this.movie);

            Assert.Throws <ArgumentNullException>(() => service.EditAsync(diffMovie).GetAwaiter().GetResult());
        }
示例#2
0
        public async Task EditAsync(AddMovieInputModel inputModel)
        {
            var movie = await this.moviesRepository.GetByIdWithDeletedAsync(inputModel.Id);

            if (movie == null)
            {
                throw new ArgumentNullException(InvalidIdExceptionMessage);
            }

            movie.Name            = inputModel.Name;
            movie.Year            = inputModel.Year;
            movie.Actors          = inputModel.Actors;
            movie.AgeRestriction  = inputModel.AgeRestriction;
            movie.Description     = inputModel.Description;
            movie.Director        = inputModel.Director;
            movie.Duration        = inputModel.Duration;
            movie.Rating          = inputModel.Rating;
            movie.Price           = inputModel.Price;
            movie.Genre           = inputModel.Genre;
            movie.TrailerUrl      = inputModel.TrailerUrl;
            movie.TrailerVideoUrl = inputModel.TrailerVideoUrl;

            this.moviesRepository.Update(movie);
            await this.moviesRepository.SaveChangesAsync();
        }
示例#3
0
        public async Task EditMovieShouldWorkCorrectly()
        {
            var repository = new EfDeletableEntityRepository <Movie>(new ApplicationDbContext(this.options.Options));
            var service    = new MoviesService(repository);

            var diffMovie = new AddMovieInputModel
            {
                Id              = 1,
                Name            = "Taxi 2",
                Year            = 2000,
                Actors          = "Samy Naceri, Frédéric Diefenthal, Marion Cotillard",
                AgeRestriction  = 0,
                Description     = "funny",
                Director        = "Gérard Pirès",
                Duration        = 86,
                Rating          = 7.5,
                Price           = 8,
                Genre           = "Action, Comedy, Crime",
                TrailerUrl      = "url",
                TrailerVideoUrl = "url",
            };

            await service.AddAsync(this.movie);

            await service.EditAsync(diffMovie);

            Assert.Equal("Taxi 2", repository.All().FirstOrDefault().Name);
            Assert.Equal(2000, repository.All().FirstOrDefault().Year);
            Assert.Equal(7.5, repository.All().FirstOrDefault().Rating);
        }
示例#4
0
        public async Task GetAllShouldWorkCorrectlyWithAllParametersFilled()
        {
            var repository = new EfDeletableEntityRepository <Movie>(new ApplicationDbContext(this.options.Options));
            var service    = new MoviesService(repository);

            var diffMovie = new AddMovieInputModel
            {
                Name            = "Taxi 2",
                Year            = 1998,
                Actors          = "Samy Naceri, Frédéric Diefenthal, Marion Cotillard",
                AgeRestriction  = 0,
                Description     = "funny",
                Director        = "Gérard Pirès",
                Duration        = 86,
                Rating          = 7.1,
                Price           = 8,
                Genre           = "Action, Comedy, Crime",
                TrailerUrl      = "url",
                TrailerVideoUrl = "url",
            };

            await service.AddAsync(this.movie);

            await service.AddAsync(diffMovie);

            await service.AddAsync(this.movie);

            var result = service.GetAll <TestMovieViewModel>(1, 1);

            Assert.Single(result);
            Assert.Equal("Taxi 2", result.FirstOrDefault().Name);
        }
        public IHttpActionResult PostMovie(AddMovieInputModel movieModel)
        {
            if (movieModel == null)
            {
                return this.BadRequest("Model cannot be null");
            }
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            if (!this.MoviesGalleryData.Genres.All().Any(g => g.Id == movieModel.GenreId))
            {
                return this.BadRequest("Genre with such id does not exists");
            }

            if (movieModel.Ration > 10 || movieModel.Ration < 1)
            {
                return this.BadRequest("Ration must be in range [1..10]");
            }

            var movie = new Movie()
                        {
                            Title = movieModel.Title,
                            Length = movieModel.Length,
                            Ration = movieModel.Ration,
                            Country = movieModel.Country,
                            GenreId = movieModel.GenreId
                        };

            this.MoviesGalleryData.Movies.Add(movie);
            this.MoviesGalleryData.SaveChanges();
            var result = new { movie.Id, movie.Title };
            return this.CreatedAtRoute("DefaultApi", new { id = movie.Id }, result);
        }
示例#6
0
        public async Task <IActionResult> Add(AddMovieInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(inputModel));
            }

            await this.moviesService.AddAsync(inputModel);

            return(this.Redirect("/"));
        }
示例#7
0
 public MoviesServiceTests()
 {
     this.movie = new AddMovieInputModel
     {
         Name            = "Taxi",
         Year            = 1998,
         Actors          = "Samy Naceri, Frédéric Diefenthal, Marion Cotillard",
         AgeRestriction  = 0,
         Description     = "funny",
         Director        = "Gérard Pirès",
         Duration        = 86,
         Rating          = 7.1,
         Price           = 8,
         Genre           = "Action, Comedy, Crime",
         TrailerUrl      = "url",
         TrailerVideoUrl = "url",
     };
     AutoMapperConfig.RegisterMappings(typeof(TestMovieViewModel).Assembly);
     this.options = new DbContextOptionsBuilder <ApplicationDbContext>()
                    .UseInMemoryDatabase(Guid.NewGuid().ToString());
 }
示例#8
0
        public async Task AddAsync(AddMovieInputModel model)
        {
            var movie = new Movie
            {
                Name            = model.Name,
                Year            = model.Year,
                Actors          = model.Actors,
                AgeRestriction  = model.AgeRestriction,
                Description     = model.Description,
                Director        = model.Director,
                Duration        = model.Duration,
                Rating          = model.Rating,
                Price           = model.Price,
                Genre           = model.Genre,
                TrailerUrl      = model.TrailerUrl,
                TrailerVideoUrl = model.TrailerVideoUrl,
                Halls           = null,
            };

            await this.moviesRepository.AddAsync(movie);

            await this.moviesRepository.SaveChangesAsync();
        }
        public async Task <IActionResult> EditMovie(AddMovieInputModel inputModel)
        {
            await this.moviesService.EditAsync(inputModel);

            return(this.Redirect($"/Movies/Details?filmId={inputModel.Id}"));
        }