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); } } }
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); } } }
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); } } }
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); } } }
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); } } }
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); } } }
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); } } }