public async Task FilterOrderByTitleDescending()
        {
            var databaseName = CreateTestData();
            var mapper       = BuildMap();
            var context      = BuildContext(databaseName);

            var controller = new MoviesController(context, mapper, null, null);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var filterDTO = new FilterMoviesDTO()
            {
                OrderingField  = "title",
                AscendingOrder = false,
                RecordsPerPage = 10
            };

            var response = await controller.Filter(filterDTO);

            var movies = response.Value;

            var context2     = BuildContext(databaseName);
            var moviesFromDb = context2.Movies.OrderByDescending(x => x.Title).ToList();

            Assert.AreEqual(moviesFromDb.Count, movies.Count);
            for (int i = 0; i < moviesFromDb.Count; i++)
            {
                var movieFromController = movies[i];
                var movieFromDb         = moviesFromDb[i];

                Assert.AreEqual(movieFromDb.Id, movieFromController.Id);
            }
        }
        public async Task FilterOrderByWrongFieldStillReturnsMovies()
        {
            var databaseName = CreateTestData();
            var mapper       = BuildMap();
            var context      = BuildContext(databaseName);

            var mock       = new Mock <ILogger <MoviesController> >();
            var controller = new MoviesController(context, mapper, null, mock.Object);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var filterDTO = new FilterMoviesDTO()
            {
                OrderingField  = "abcd",
                AscendingOrder = false,
                RecordsPerPage = 10
            };

            var response = await controller.Filter(filterDTO);

            var movies = response.Value;

            var context2     = BuildContext(databaseName);
            var moviesFromDb = context2.Movies.ToList();

            Assert.AreEqual(moviesFromDb.Count, movies.Count);
            Assert.AreEqual(1, mock.Invocations.Count);
        }
Example #3
0
        public async Task FilterByInTheaters()
        {
            //Preparation
            var databaseName = CreateTestsData();
            var context      = BuildContext(databaseName);
            var mapper       = BuildMap();

            var filterMovieDto = new FilterMoviesDto()
            {
                InTheaters     = true,
                RecordsPerPage = 10
            };

            //Testing
            var controller = new MoviesController(context, mapper, null, null);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();
            var response = await controller.Filter(filterMovieDto);

            //Verification
            var result = response.Value;

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual("In theater movie", result[0].Title);
        }
        public async Task FilterByGenre()
        {
            var databaseName = CreateTestData();
            var mapper       = BuildMap();
            var context      = BuildContext(databaseName);

            var genreId = context.Genres.Select(x => x.Id).First();

            var context2 = BuildContext(databaseName);

            var controller = new MoviesController(context2, mapper, null, null);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var filterDTO = new FilterMoviesDTO()
            {
                GenreId        = genreId,
                RecordsPerPage = 10
            };

            var response = await controller.Filter(filterDTO);

            var movies = response.Value;

            Assert.AreEqual(1, movies.Count);
            Assert.AreEqual("Movie With Genre", movies[0].Title);
        }
Example #5
0
        public async Task FiltrarPorTitulo()
        {
            var nameDb  = CreateDataTest();
            var context = BuildContext(nameDb);
            var mapper  = ConfigurationAutoMapper();

            var controller = new MoviesController(context, mapper, null);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var titleMovie = "Movie 1";

            var filterDTO = new MovieFilterDTO()
            {
                Title          = titleMovie,
                RecordsPerPage = 10
            };

            var response = await controller.Filter(filterDTO);

            var movies = response.Value;

            Assert.AreEqual(1, movies.Count);
            Assert.AreEqual(titleMovie, movies[0].Title);
        }
Example #6
0
        public async Task FilterWrongOrderingFieldStillReturnsMovies()
        {
            //Preparation
            var databaseName = CreateTestsData();
            var mapper       = BuildMap();
            var context      = BuildContext(databaseName);

            var context2 = BuildContext(databaseName);

            var mock = new Mock <ILogger <MoviesController> >();

            var filterMovieDto = new FilterMoviesDto()
            {
                OrderingField  = "invalid field",
                AscendingOrder = false,
                RecordsPerPage = 10
            };

            //Testing
            var controller = new MoviesController(context, mapper, null, mock.Object);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();
            var response = await controller.Filter(filterMovieDto);

            //Verification
            var result       = response.Value;
            var moviesFromDb = context2.Movies.ToList();

            Assert.AreEqual(moviesFromDb.Count, result.Count);
            Assert.AreEqual(1, mock.Invocations.Count);
        }
Example #7
0
        public async Task FilterByGenre()
        {
            //Preparation
            var databaseName = CreateTestsData();
            var context      = BuildContext(databaseName);
            var mapper       = BuildMap();

            var genreId = context.Genres.Select(x => x.Id).First();

            var filterMovieDto = new FilterMoviesDto()
            {
                GenreId        = genreId,
                RecordsPerPage = 10
            };

            //Testing
            var controller = new MoviesController(context, mapper, null, null);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();
            var response = await controller.Filter(filterMovieDto);

            //Verification
            var result = response.Value;

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual("Movie with Genre", result[0].Title);
        }
Example #8
0
        public async Task FiltrarPorCampoIncorrectoDevuelvePeliculas()
        {
            var nameDb  = CreateDataTest();
            var mapper  = ConfigurationAutoMapper();
            var context = BuildContext(nameDb);

            //var mock = new Mock<ILogger<PeliculasController>>();

            var controller = new MoviesController(context, mapper, null);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var filterDTO = new MovieFilterDTO()
            {
                FieldToSort    = "abc",
                AscendingOrder = false
            };

            var response = await controller.Filter(filterDTO);

            var movies = response.Value;

            var contexto2 = BuildContext(nameDb);
            var moviesDb  = contexto2.Movies.ToList();

            Assert.AreEqual(moviesDb.Count, movies.Count);
            // Assert.AreEqual(1, Mock.Invocations.Count);
        }
Example #9
0
        public async Task FiltrarTituloDescendente()
        {
            var nameDb  = CreateDataTest();
            var mapper  = ConfigurationAutoMapper();
            var context = BuildContext(nameDb);

            var controller = new MoviesController(context, mapper, null);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var filterDTO = new MovieFilterDTO()
            {
                FieldToSort    = "title",
                AscendingOrder = true
            };

            var response = await controller.Filter(filterDTO);

            var movies = response.Value;

            var contexto2 = BuildContext(nameDb);
            var moviesDb  = contexto2.Movies.OrderByDescending(x => x.Title).ToList();

            Assert.AreEqual(moviesDb.Count, movies.Count);

            for (int i = 0; i < moviesDb.Count; i++)
            {
                var movieOfController = movies[i];
                var movieDb           = moviesDb[i];

                Assert.AreEqual(movieDb.Id, movieOfController.Id);
            }
        }
Example #10
0
        public async Task FilterInCinemas()
        {
            var nameDb  = CreateDataTest();
            var context = BuildContext(nameDb);
            var mapper  = ConfigurationAutoMapper();

            var controller = new MoviesController(context, mapper, null);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var filterDTO = new MovieFilterDTO()
            {
                InTheaters = true
            };

            var response = await controller.Filter(filterDTO);

            var movies = response.Value;

            Assert.AreEqual(1, movies.Count);
            Assert.AreEqual("Movie in theaters", movies[0].Title);
        }
Example #11
0
        public async Task FilterByInTheaters()
        {
            var databaseName = CreateTestData();
            var mapper       = BuildMap();
            var context      = BuildContext(databaseName);

            var controller = new MoviesController(context, mapper, null, null);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var filterDTO = new FilterMoviesDTO()
            {
                InTheaters     = true,
                RecordsPerPage = 10
            };

            var response = await controller.Filter(filterDTO);

            var movies = response.Value;

            Assert.AreEqual(1, movies.Count);
            Assert.AreEqual("In Theaters Movie", movies[0].Title);
        }
Example #12
0
        public async Task FilterOrderByTitleAscending()
        {
            //Preparation
            var databaseName = CreateTestsData();
            var context      = BuildContext(databaseName);
            var mapper       = BuildMap();

            var context2 = BuildContext(databaseName);

            var filterMovieDto = new FilterMoviesDto()
            {
                OrderingField  = "title",
                AscendingOrder = true,
                RecordsPerPage = 10
            };

            //Testing
            var controller = new MoviesController(context, mapper, null, null);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();
            var response = await controller.Filter(filterMovieDto);

            var moviesFromDb = context2.Movies.OrderBy(x => x.Title).ToList();

            //Verification
            var result = response.Value;

            Assert.AreEqual(moviesFromDb.Count, result.Count);

            for (int i = 0; i < moviesFromDb.Count; i++)
            {
                var movieFromController = result[i];
                var movieFromDb         = moviesFromDb[i];

                Assert.AreEqual(movieFromDb.Id, movieFromController.Id);
            }
        }
        public async Task FilterByTitle()
        {
            var databaseName = CreateTestData();
            var mapper       = BuildMap();
            var context      = BuildContext(databaseName);

            var controller = new MoviesController(context, mapper, null, null);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var filterDTO = new FilterMoviesDto()
            {
                Title          = "Movie 1",
                RecordsPerPage = 10
            };

            var response = await controller.Filter(filterDTO);

            var result = response.Result as OkObjectResult;
            var movies = result.Value as List <MovieDto>;

            Assert.AreEqual(1, movies.Count);
            Assert.AreEqual("Movie 1", movies[0].Title);
        }
Example #14
0
        public async Task FilterByGender()
        {
            var nameDb  = CreateDataTest();
            var mapper  = ConfigurationAutoMapper();
            var context = BuildContext(nameDb);

            var controller = new MoviesController(context, mapper, null);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var genderId = context.Genders.Select(x => x.Id).First();

            var filterDTO = new MovieFilterDTO()
            {
                GenderId = genderId
            };

            var response = await controller.Filter(filterDTO);

            var movies = response.Value;

            Assert.AreEqual(1, movies.Count);
            Assert.AreEqual("Movie with Gender", movies[0].Title);
        }