Ejemplo n.º 1
0
        public void AddRating_WithValidMovieId_CallsSaveOnMovieRepository()
        {
            IMembershipService membershipService = new FakeMembershipService(Enumerable.Empty <MembershipUser>());

            var       movies  = new List <Movie>();
            const int movieId = 42;
            var       movie   = new Movie
            {
                Id        = movieId,
                Directors = "Directors",
                GenreId   = 1,
                Name      = "Name",
                Rating    = 3,
                Stars     = "Stars",
                Writers   = "Writers"
            };

            movies.Add(movie);

            bool   wasCalled  = false;
            Action saveAction = () => wasCalled = true;

            IRepository <Movie> movieRepository = new FakeMovieRepository(movies, saveCallback: saveAction);
            IRepository <Genre> genreRepository = new FakeGenreRepository();
            var movieController = new MovieController(movieRepository, genreRepository, membershipService)
            {
                ControllerContext = new FakeControllerContext()
            };


            movieController.AddRating(movieId, 5);

            Assert.IsTrue(wasCalled);
        }
Ejemplo n.º 2
0
        public void AddRating_WithValidMovieId_AdjustsMovieRating()
        {
            IMembershipService membershipService = new FakeMembershipService(Enumerable.Empty <MembershipUser>());

            var       movies  = new List <Movie>();
            const int movieId = 42;
            var       movie   = new Movie
            {
                Id        = movieId,
                Directors = "Directors",
                GenreId   = 1,
                Name      = "Name",
                Rating    = 3,
                Stars     = "Stars",
                Writers   = "Writers"
            };

            movies.Add(movie);


            IRepository <Movie> movieRepository = new FakeMovieRepository(movies);
            IRepository <Genre> genreRepository = new FakeGenreRepository();
            var movieController = new MovieController(movieRepository, genreRepository, membershipService)
            {
                ControllerContext = new FakeControllerContext()
            };


            const short newRating = 5;

            movieController.AddRating(movieId, newRating);

            Assert.IsTrue(movie.Rating == newRating);
        }