示例#1
0
        public async Task Update_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 UpdateMovieRatingModel
                    {
                        UserName = "******",
                        Rating   = 3.5
                    };

                    var movieRating = await ratingRepository.FirstAsyc();

                    var actionResult = await controller.UpdateAsync(movieRating.MovieId, movieRating.Id, model) as OkObjectResult;

                    var rating = actionResult.Value as UpdateMovieRatingResult;

                    Assert.NotNull(actionResult);
                    Assert.Equal(movieRating.MovieId, rating.MovieId);
                    Assert.Equal(movieRating.Id, rating.RatingId);
                    Assert.Equal(model.Rating, rating.Rating);
                }
            }
        }
示例#2
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);
                }
            }
        }
示例#3
0
        public async Task Update_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 UpdateMovieRatingModel
                    {
                        UserName = "******",
                        Rating   = 5
                    };
                    var result = await controller.UpdateAsync(-1, -1, model) as NotFoundObjectResult;

                    Assert.NotNull(result);
                }
            }
        }