Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 2
0
        public async Task Create_ShouldReturnBadRequest()
        {
            var controller = new RatingsController(Mock.Of <IMovieRepository>(),
                                                   Mock.Of <IUserRepository>(),
                                                   Mock.Of <IMovieRatingRepository>());

            controller.ModelState.AddModelError("Rating", "The Rating field must ben between 0 and 5.");

            var result = await controller.CreateAsync(1, new CreateMovieRatingModel()) as BadRequestObjectResult;

            Assert.NotNull(result);
        }
Ejemplo n.º 3
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);
                }
            }
        }