Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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());
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public async Task GetIdByNameShouldReturnTheCorrectId()
        {
            var repository = new EfDeletableEntityRepository <Movie>(new ApplicationDbContext(this.options.Options));
            var service    = new MoviesService(repository);

            await service.AddAsync(this.movie);

            Assert.Equal(1, service.GetIdByName("Taxi"));
        }
Exemplo n.º 7
0
        public async Task AddMovieShouldAddCorrectCount()
        {
            var repository = new EfDeletableEntityRepository <Movie>(new ApplicationDbContext(this.options.Options));
            var service    = new MoviesService(repository);

            await service.AddAsync(this.movie);

            Assert.Equal(1, repository.All().Count());
        }
Exemplo n.º 8
0
        public async Task DeleteMovieShouldThrowWithIncorrectId()
        {
            var repository = new EfDeletableEntityRepository <Movie>(new ApplicationDbContext(this.options.Options));
            var service    = new MoviesService(repository);

            await service.AddAsync(this.movie);

            Assert.Throws <ArgumentNullException>(() => service.DeleteAsync(2).GetAwaiter().GetResult());
        }
Exemplo n.º 9
0
        public async Task AddMovieShouldAddCorrectData()
        {
            var repository = new EfDeletableEntityRepository <Movie>(new ApplicationDbContext(this.options.Options));
            var service    = new MoviesService(repository);

            await service.AddAsync(this.movie);

            var dbMovie = repository.All().Where(m => m.Name == "Taxi").FirstOrDefault();

            Assert.Equal("Taxi", dbMovie.Name);
            Assert.Equal(1998, dbMovie.Year);
            Assert.Equal(7.1, dbMovie.Rating);
        }
Exemplo n.º 10
0
        public async Task DeleteMovieShouldWorkCorrectly()
        {
            var repository = new EfDeletableEntityRepository <Movie>(new ApplicationDbContext(this.options.Options));
            var service    = new MoviesService(repository);

            await service.AddAsync(this.movie);

            await service.DeleteAsync(1);

            var movie = await repository.GetByIdWithDeletedAsync(1);

            Assert.True(movie.IsDeleted);
        }
Exemplo n.º 11
0
        public async Task GetByIdShouldReturnTheCorrectData()
        {
            var repository = new EfDeletableEntityRepository <Movie>(new ApplicationDbContext(this.options.Options));
            var service    = new MoviesService(repository);

            await service.AddAsync(this.movie);

            AutoMapperConfig.RegisterMappings(typeof(TestMovieViewModel).Assembly);
            var result = service.GetById <TestMovieViewModel>(1);

            Assert.Equal("Taxi", result.Name);
            Assert.Equal(7.1, result.Rating);
            Assert.Equal(1998, result.Year);
        }