Example #1
0
        public async Task Create_ShouldReturnOK()
        {
            using (var context = InMemomryDbContext.Create())
            {
                var movieRepository  = new MovieRepository(context);
                var userRepository   = new UserRepository(context);
                var ratingRepository = new MovieRatingRepository(context);

                using (var controller = new RatingsController(movieRepository, userRepository, ratingRepository))
                {
                    var model = new CreateMovieRatingModel
                    {
                        UserName = "******",
                        Rating   = 3.5
                    };

                    var movieId      = (await movieRepository.FirstAsyc()).Id;
                    var actionResult = await controller.CreateAsync(movieId, model) as OkObjectResult;

                    var rating = actionResult.Value as CreateMovieRatingResult;

                    Assert.NotNull(actionResult);
                    Assert.Equal(movieId, rating.MovieId);
                    Assert.Equal(model.Rating, rating.Rating);
                }
            }
        }
Example #2
0
        public async Task GetMovies_ShouldReturnNotFound()
        {
            using (var context = InMemomryDbContext.Create())
            {
                var movieReposioty = new MovieRepository(context);
                using (var controller = new MoviesController(movieReposioty))
                {
                    var result = await controller.GetMoviesAsync("RedSky") as NotFoundResult;

                    Assert.NotNull(result);
                }
            }
        }
Example #3
0
        public async Task Update_ShouldReturnBadRequest()
        {
            using (var context = InMemomryDbContext.Create())
            {
                var movieRepository  = new MovieRepository(context);
                var userRepository   = new UserRepository(context);
                var ratingRepository = new MovieRatingRepository(context);

                using (var controller = new RatingsController(movieRepository, userRepository, ratingRepository))
                {
                    controller.ModelState.AddModelError("Rating", "The Rating field must be between 0 and 5.");

                    var result = await controller.UpdateAsync(1, 1, new UpdateMovieRatingModel()) as BadRequestObjectResult;

                    Assert.NotNull(result);
                }
            }
        }
Example #4
0
        public async Task GetTopFiveMovies_ShouldReturnAll()
        {
            using (var context = InMemomryDbContext.Create())
            {
                var movieReposioty = new MovieRepository(context);
                using (var controller = new MoviesController(movieReposioty))
                {
                    var result = await controller.GetTopFiveMoviesAsyn() as OkObjectResult;

                    var movies = result.Value as IEnumerable <MovieSearchResult>;

                    Assert.NotNull(result);
                    Assert.Equal(5, movies.Count());
                    Assert.Equal("Avengers: Infinity War", movies.First().Title);
                    Assert.Equal("Gone Girl", movies.Last().Title);
                }
            }
        }
Example #5
0
        public async Task GetMovies_ShouldReturnSingle()
        {
            const string MovieTitle = "infinity";

            using (var context = InMemomryDbContext.Create())
            {
                var movieReposioty = new MovieRepository(context);
                using (var controller = new MoviesController(movieReposioty))
                {
                    var result = await controller.GetMoviesAsync(MovieTitle) as OkObjectResult;

                    var colelction = result.Value as IEnumerable <MovieSearchResult>;

                    Assert.NotNull(result);
                    Assert.Single(colelction);
                    Assert.Contains(MovieTitle, colelction.Single().Title, StringComparison.InvariantCultureIgnoreCase);
                }
            }
        }
Example #6
0
        public async Task GetMovies_ShouldReturnTwo()
        {
            const string genre = "Mystery";

            using (var context = InMemomryDbContext.Create())
            {
                var movieReposioty = new MovieRepository(context);
                using (var controller = new MoviesController(movieReposioty))
                {
                    var result = await controller.GetMoviesAsync(genre : genre) as OkObjectResult;

                    var movies = result.Value as IEnumerable <MovieSearchResult>;

                    Assert.NotNull(result);
                    Assert.Equal(2, movies.Count());
                    Assert.Equal("Gone Girl", movies.First().Title);
                    Assert.Equal("Sherlock Holmes", movies.Last().Title);
                }
            }
        }
Example #7
0
        public async Task Create_ShouldReturnNotFound()
        {
            using (var context = InMemomryDbContext.Create())
            {
                var movieRepository  = new MovieRepository(context);
                var userRepository   = new UserRepository(context);
                var ratingRepository = new MovieRatingRepository(context);

                using (var controller = new RatingsController(movieRepository, userRepository, ratingRepository))
                {
                    var model = new CreateMovieRatingModel
                    {
                        UserName = "******",
                        Rating   = 5
                    };
                    var result = await controller.CreateAsync(-1, model) as NotFoundObjectResult;

                    Assert.NotNull(result);
                }
            }
        }