Beispiel #1
0
        public void DeleteShouldRemoveAndReturnFilm()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(DeleteShouldRemoveAndReturnFilm))
                          .EnableSensitiveDataLogging()
                          .Options;

            using (var context = new MoviesDbContext(options))
            {
                var filmService = new MoviesService(context);
                var toAdd       = filmService.Create(new ExamenNet.ViewModels.MoviePostModel
                {
                    Title       = "DeSters",
                    Director    = "dir1",
                    DateAdded   = new DateTime(),
                    Duration    = 100,
                    Description = "asdvadfbdbsb",
                    Genre       = "Comedy",
                    ReleaseYear = 2000,
                    Rating      = 3,
                    Watched     = 0
                }, null);

                Assert.IsNotNull(toAdd);
                Assert.AreEqual(1, filmService.GetAll(new DateTime(), new DateTime(), 1).Entries.Count);

                var deletedFilm = filmService.Delete(1);

                Assert.IsNotNull(deletedFilm);
                Assert.AreEqual(0, filmService.GetAll(new DateTime(), new DateTime(), 1).Entries.Count);
            }
        }
Beispiel #2
0
        public async Task CreateMovieShouldAddMovieToRepository()
        {
            AutoMapperConfig.RegisterMappings(typeof(MovieTestModel).Assembly);

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var repository = new EfDeletableEntityRepository <Movie>(new ApplicationDbContext(options.Options));

            await repository.AddAsync(new Movie { Id = 1, Name = "Movie1" });

            await repository.AddAsync(new Movie { Id = 2, Name = "Movie2" });

            await repository.SaveChangesAsync();

            var service = new MoviesService(repository, null, null, null);

            var movie = new CreateMovieServiceInputModel
            {
                Name      = "TestMovie",
                Length    = 50,
                Directors = new[] { "Test" },
                Genres    = new[] { "1" },
                Actors    = new[] { "Test" },
            };

            await service.CreaterMovieAsync(movie);

            var genresCount = service.GetAll <MovieTestModel>().Count;

            Assert.Equal(3, genresCount);
        }
        public async Task GetAllCountShouldReturnCorrectNumberOfMovies()
        {
            var options = new DbContextOptionsBuilder <NetPhlixDbContext>()
                          .UseInMemoryDatabase("Test")
                          .Options;
            var dbContext = new NetPhlixDbContext(options);

            await dbContext.Movies.AddRangeAsync(
                new Movie(),
                new Movie(),
                new Movie()
                );

            await dbContext.SaveChangesAsync();

            var mappingConfig = new MapperConfiguration(
                mc =>
            {
                mc.AddProfiles(
                    typeof(MoviesProfile),
                    typeof(UsersProfile),
                    typeof(CompaniesProfile),
                    typeof(ReviewsProfile),
                    typeof(PeopleProfile),
                    typeof(EventsProfile),
                    typeof(AdminProfile)
                    );
            });
            IMapper mapper = mappingConfig.CreateMapper();

            var service   = new MoviesService(mapper, dbContext);
            var allMovies = await service.GetAll();

            Assert.Equal(3, allMovies.Count());
        }
Beispiel #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);
        }
Beispiel #5
0
        public async Task GetAll_WithValidInput_ShouldReturnValidResult()
        {
            var dbContext = ApplicationDbContextCreatorInMemory.InitializeContext();

            await this.SeedData(dbContext);

            var moviesRepository = new EfDeletableEntityRepository <Movie>(dbContext);
            var genresRepository = new EfDeletableEntityRepository <Genre>(dbContext);
            var service          = new MoviesService(moviesRepository, genresRepository);

            var result = service.GetAll <MovieViewModel>().ToList();

            Assert.Equal(2, result.Count());
        }
Beispiel #6
0
        public async Task GetAllShouldReturnOneModelWithTakeParameterBeeing1()
        {
            var repository = new EfDeletableEntityRepository <Movie>(new ApplicationDbContext(this.options.Options));
            var service    = new MoviesService(repository);

            await service.AddAsync(this.movie);

            await service.AddAsync(this.movie);

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

            Assert.Single(result);
            Assert.Equal("Taxi", result.FirstOrDefault().Name);
        }
Beispiel #7
0
        public async Task GetAllShouldReturnCorrectData()
        {
            var repository = new EfDeletableEntityRepository <Movie>(new ApplicationDbContext(this.options.Options));
            var service    = new MoviesService(repository);

            await service.AddAsync(this.movie);

            await service.AddAsync(this.movie);

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

            Assert.Equal(2, result.Count());
            Assert.Equal("Taxi", result.FirstOrDefault().Name);
        }
Beispiel #8
0
        public void GetAllShouldReturnCorrectNumberOfPagesForMovies()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetAllShouldReturnCorrectNumberOfPagesForMovies))
                          .Options;

            using (var context = new MoviesDbContext(options))
            {
                var movieService = new MoviesService(context);
                var addedFilm    = movieService.Create(new ExamenNet.ViewModels.MoviePostModel
                {
                    Title       = "film de test 1",
                    Director    = "dir1",
                    DateAdded   = DateTime.Parse("2019-06-11T00:00:00"),
                    Duration    = 100,
                    Description = "asdvadfbdbsb",
                    Genre       = "Comedy",
                    ReleaseYear = 2000,
                    Rating      = 3,
                    Watched     = 0,
                    Comments    = new List <Comment>()
                    {
                        new Comment
                        {
                            Important = true,
                            Text      = "asd",
                            AddedBy   = null
                        }
                    },
                }, null);

                DateTime from = DateTime.Parse("2019-06-10T00:00:00");
                DateTime to   = DateTime.Parse("2019-06-12T00:00:00");

                var allMovies = movieService.GetAll(from, to, 1);
                Assert.AreEqual(1, allMovies.Entries.Count);
            }
        }