public void CreatingAMovieStoresItInTheDb()
        {
            var movie = new Movie { Title = "The Movie" };

              var savedMovie = moviesDBContext.CreateMovie(movie);

              Assert.AreNotEqual(0, savedMovie.Id);
        }
        public void SearchReturnsCorrectResults()
        {
            var movie = new Movie { Title = "Movie A" };
              var id = moviesDBContext.CreateMovie(movie).Id;

              var results = moviesDBContext.Search(movie.Title);

              Assert.AreEqual(1, results.Count);
              Assert.AreEqual(id, results[0].Id);
        }
        public void SearchReturnsPartialMatches()
        {
            var movie = new Movie { Title = "The Other Movie" };
              var context = new MoviesDBContext();
              context.CreateMovie(movie);

              var results = context.Search("Other");

              Assert.AreEqual(1, results.Count);
              Assert.AreEqual(movie.Title, results[0].Title);
        }
        public void SearchIsCaseInsensitive()
        {
            var movie = new Movie { Title = "The Movie" };
              var context = new MoviesDBContext();
              context.CreateMovie(movie);

              var results = context.Search("tHe mOVIE");

              Assert.AreEqual(1, results.Count);
              Assert.AreEqual(movie.Title, results[0].Title);
        }
        public void CanCreateAMovie()
        {
            var mockContext = new Mock<MoviesDBContext>();
              var movie = new Movie {Title = "The Shining"};
              mockContext.Setup(context => context.CreateMovie(movie));
              var movieController = new MoviesController(mockContext.Object);

              movieController.Create(movie);

              mockContext.Verify(context => context.CreateMovie(movie), Times.Once());
        }
        public void CreatingAMovieSaysThanks()
        {
            var mockContext = new Mock<MoviesDBContext>();
              var movie = new Movie { Title = "The Shining" };
              mockContext.Setup(context => context.CreateMovie(movie));
              var movieController = new MoviesController(mockContext.Object);

              var result = movieController.Create(movie);

              Assert.IsInstanceOfType(result, typeof(ViewResult));
              Assert.AreEqual("Thank you", movieController.ViewBag.Message);
        }
        public void CanSearchByTitle()
        {
            var testMovie = new Movie {Title = "test movie"};
              var mockContext = new Mock<MoviesDBContext>();
              mockContext.Setup(context => context.Search(testMovie.Title,10)).Returns(new List<Movie> {testMovie});
              var moviesController = new MoviesController(mockContext.Object);

              var result =  moviesController.Search(new SearchRequest{SearchTerm = testMovie.Title, NumRows = 10});
              var movies = (List<Movie>) result.Model;

              Assert.AreEqual("Found", moviesController.ViewBag.Message);
              Assert.AreEqual(1, movies.Count);
              Assert.AreEqual(testMovie.Title, movies[0].Title);
        }
 public virtual Movie CreateMovie(Movie movie)
 {
     var added = Movies.Add(movie);
       SaveChanges();
       return added;
 }
        public void CreatingAMovieStoresIt()
        {
            var mockDbSet = new Mock<IDbSet<Movie>>();
              var context = new MoviesDBContext(mockDbSet.Object);
              var movie = new Movie{Title = "The Movie"};

              context.CreateMovie(movie);

              mockDbSet.Verify(set => set.Add(movie), Times.Once());
        }
 public ViewResult Create(Movie movie)
 {
     moviesDBContext.CreateMovie(movie);
     ViewBag.Message = "Thank you";
     return View();
 }