コード例 #1
0
        public void Genre_in_movie_is_updated_after_update()
        {
            Movie movie = facade.GetMovieRepository().ReadAll().First();
            movie.Genres = new List<Genre>();
            Movie movieUpdated = facade.GetMovieRepository().Update(movie);
            Assert.IsFalse(movieUpdated.Genres.Any());
            Movie movieFromDB = facade.GetMovieRepository().ReadAll().First();
            Assert.IsFalse(movieFromDB.Genres.Any());

            //Test what happens if we add 1 genre!
            List<Genre> genres = new List<Genre>();
            Genre genre = facade.GetGenresRepository().ReadAll().First();
            genres.Add(genre);
            movie.Genres = genres;
            Movie movieUpdated2 = facade.GetMovieRepository().Update(movie);
            Assert.IsTrue(movieUpdated2.Genres.Any());
            Movie movieFromDB2 = facade.GetMovieRepository().ReadAll().First();
            Assert.IsTrue(movieFromDB2.Genres.Any());

            //Test what happens if we add 1 genre again!
            List<Genre> genres2 = new List<Genre>();
            Genre genre2 = facade.GetGenresRepository().ReadAll().First();
            genres2.Add(genre2);
            movie.Genres = genres2;
            Movie movieUpdated3 = facade.GetMovieRepository().Update(movie);
            Assert.IsTrue(movieUpdated3.Genres.Any());
            Movie movieFromDB3 = facade.GetMovieRepository().ReadAll().First();
            Assert.IsTrue(movieFromDB3.Genres.Count == 1);

            facade = new Facade(new MovieShopContextTest());

            //Test what happens if we add 1 genre again!
            Movie rePulledMovie = facade.GetMovieRepository().Read(movie.Id);
            List<Genre> genres3 = new List<Genre>();
            Genre genre3 = facade.GetGenresRepository().ReadAll().Last();
            Genre genre4 = facade.GetGenresRepository().ReadAll()[1];
            genres3.Add(genre3);
            genres3.Add(genre4);
            rePulledMovie.Genres = genres3;
            Movie movieUpdated4 = facade.GetMovieRepository().Update(rePulledMovie);
            Assert.IsTrue(movieUpdated4.Genres.Any());
            Movie movieFromDB4 = facade.GetMovieRepository().Read(rePulledMovie.Id);
            Assert.IsTrue(movieFromDB4.Genres.Count == 2);
            Assert.IsTrue(movieFromDB4.Genres.Contains(genre3), "did not contain genre3");
            Assert.IsTrue(movieFromDB4.Genres.Contains(genre4), "did not contain genre4");

            //Add new Genre
            rePulledMovie.Genres.Add(new Genre() { Name = "Namnam"});
            Movie movieUpdated5 = facade.GetMovieRepository().Update(rePulledMovie);
            Assert.IsTrue(movieUpdated5.Genres.Count == 3);
            Assert.IsTrue(facade.GetGenresRepository().ReadAll().Count == 4);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: aceymer/MovieShop-MVC-
 static void Main(string[] args)
 {
     Movie movie = new Movie() { Id = 2, Price = 200d, Title = "Lego movie 2", Year = DateTime.Now.AddYears(-1) };
     Facade facade = new Facade();
     facade.GetMovieRepository().Add(movie);
 }
コード例 #3
0
 public void TearDown()
 {
     facade = null;
 }
コード例 #4
0
 public void SetUp()
 {
     facade = new Facade(new MovieShopContextTest());
 }