public void Verify_Add_Should_AddTheEntityToTheContext()
 {
     // Arrange
     Mock<IDbSet<MovieLocation>> mockSetMovieLocations;
     var mockContext = MovieLocationsMockingSetup.DoMockingSetupForContext(false, out mockSetMovieLocations);
     var repository = new MovieLocationsRepository(mockContext.Object);
     var movieLocations = new MovieLocation { Active = true, CustomKey = "SALVATORE-RAA", };
     // Act
     repository.Add(movieLocations);
     // Assert
     mockSetMovieLocations.Verify(x => x.Add(movieLocations), Times.Once);
 }
        public void Verify_Add_Should_AddTheEntityToTheContext()
        {
            // Arrange
            Mock <IDbSet <MovieLocation> > mockSetMovieLocations;
            var mockContext    = MovieLocationsMockingSetup.DoMockingSetupForContext(false, out mockSetMovieLocations);
            var repository     = new MovieLocationsRepository(mockContext.Object);
            var movieLocations = new MovieLocation {
                Active = true, CustomKey = "SALVATORE-RAA",
            };

            // Act
            repository.Add(movieLocations);
            // Assert
            mockSetMovieLocations.Verify(x => x.Add(movieLocations), Times.Once);
        }
        public void Verify_MapToEntity_WithExistingEntity_AssignsMovieLocationProperties()
        {
            // Arrange
            var mapper = new MovieLocationMapper();
            var model  = MovieLocationsMockingSetup.DoMockingSetupForMovieLocationModel();
            // Act
            IMovieLocation existingEntity = new MovieLocation {
                Id = 1
            };

            mapper.MapToEntity(model.Object, ref existingEntity);
            // Assert
            // <None>
            // Related Objects
            Assert.Equal(model.Object.MovieId, existingEntity.MovieId);
            Assert.Equal(model.Object.LocationId, existingEntity.LocationId);
            // Associated Objects
            // <None>
        }
Exemple #4
0
        /// <summary>
        /// Main method to compute DB records to JSON files. All JSON files are stored in a
        /// configurable folder.
        /// </summary>
        public void CompileAllMoviesSchedule()
        {
            if (log.IsDebugEnabled)
            {
                log.Debug("CompileAllMoviesSchedule Starts");
                log.Debug("Core");
            }
            Pelicula             movieDao      = new Pelicula();
            List <MovieFullInfo> movieFullList = movieDao.updateBillboardAndGetMovieFullInfo();

            // Normalize image to conform to URI.
            movieFullList.ForEach(m => {
                if (!m.img.Contains("http"))
                {
                    m.img = imgPathUrl + m.img;
                }
            });

            // Create List of movies
            List <Movie>  movieList         = new List <Movie>();
            Movie         movieInfo         = null;
            MovieLocation movieLocationInfo = null;
            MovieFormat   movieFormatInfo   = null;
            MovieShow     movieShowInfo     = null;

            movieFullList.ForEach(mfInfo => {
                // Let's first find movie existence
                var movieExist = movieList.Where(x => x.id == mfInfo.id).FirstOrDefault <Movie>();
                if (movieExist != null)
                {
                    movieInfo = movieExist;
                }
                else
                {
                    movieInfo = new Movie()
                    {
                        id         = mfInfo.id,
                        name       = mfInfo.name,
                        img        = mfInfo.img,
                        url        = mfInfo.url,
                        active     = mfInfo.active,
                        idGenre    = mfInfo.idGenre,
                        genre      = mfInfo.genre,
                        premiere   = mfInfo.premiere,
                        createDate = mfInfo.createDate,
                        locations  = new List <MovieLocation>()
                    };
                    movieList.Add(movieInfo);
                }

                // Fill remaining data for movieInfo record
                // 1. Fill Location
                var movieLocationExist = movieInfo.locations.Where(x => x.id == mfInfo.idLocation).FirstOrDefault <MovieLocation>();
                if (movieLocationExist != null)
                {
                    movieLocationInfo = movieLocationExist;
                }
                else
                {
                    movieLocationInfo = new MovieLocation()
                    {
                        id         = mfInfo.idLocation,
                        name       = mfInfo.nameLocation,
                        branchName = mfInfo.branchName,
                        nameFull   = mfInfo.nameFullLocation,
                        address    = mfInfo.address,
                        formats    = new List <MovieFormat>()
                    };
                    movieInfo.locations.Add(movieLocationInfo);
                }

                // 2. Fill Format
                var movieFormatExist = movieLocationInfo.formats.Where(x => x.id == mfInfo.idFormat).FirstOrDefault <MovieFormat>();
                if (movieFormatExist != null)
                {
                    movieFormatInfo = movieFormatExist;
                }
                else
                {
                    movieFormatInfo = new MovieFormat()
                    {
                        id    = mfInfo.idFormat,
                        name  = mfInfo.nameFormat,
                        shows = new List <MovieShow>()
                    };
                    movieLocationInfo.formats.Add(movieFormatInfo);
                }

                // 3. Fill Show
                var movieShowExist = movieFormatInfo.shows.Where(x => x.id == mfInfo.idShow).FirstOrDefault <MovieShow>();
                if (movieShowExist != null)
                {
                    movieShowInfo = movieShowExist;
                }
                else
                {
                    movieShowInfo = new MovieShow()
                    {
                        id    = mfInfo.idShow,
                        dt    = mfInfo.dt,
                        hours = movieDao.getMovieShowHoursFor(mfInfo.idShow)
                    };
                    movieFormatInfo.shows.Add(movieShowInfo);
                }
                movieFormatInfo.shows = movieFormatInfo.shows.OrderBy(x => x.dt).ToList <MovieShow>();
            });
            movieList = movieList.OrderByDescending(x => x.premiere).ThenBy(x => x.name).ToList <Movie>();

            // Up to this point we have all movies gathered, now we build the movie Catalog in order
            // to ease search manipulation when required and to speed data processing.
            // The following steps must be fullfilled in order to gather all of the movie Catalog.
            // 1. Load Movie Name list
            // 2. Movie Formats Name list
            // 3. Movie Genre Name list
            // 4. Load all theaters referenced in the schedule.
            // 5. Load All Theater Name List and its associated movies.
            // 6. Load Movie Name List and its associated theaters where each movie is being shown.

            // Let's start.
            MovieCatalog mc = new MovieCatalog();

            mc.theaters = new List <MovieLocationShort>();
            mc.formats  = new List <MovieFormatShort>();
            mc.movies   = new List <MovieShortFormat>();
            mc.genres   = new List <MovieGenreShort>();

            // 1. Load Movie Name list
            movieList.ForEach(movie => {
                MovieShortFormat movieShort = new MovieShortFormat()
                {
                    id       = movie.id,
                    name     = movie.name,
                    premiere = movie.premiere,
                    formats  = new List <MovieFormatShort>()
                };

                // Now load formats
                movie.locations.ForEach(movieLocation =>
                                        movieLocation.formats.ForEach(
                                            movieFormat => {
                    var formatExist = movieShort.formats.Where(x => x.id == movieFormat.id).FirstOrDefault <MovieFormatShort>();
                    if (formatExist == null)
                    {
                        movieShort.formats.Add(new MovieFormatShort()
                        {
                            id = movieFormat.id, name = movieFormat.name
                        });
                    }
                }
                                            ));
                movieShort.formats = movieShort.formats.OrderBy(x => x.name).ToList <MovieFormatShort>();
                mc.movies.Add(movieShort);
            });
            mc.movies = mc.movies.OrderBy(x => x.name).ToList <MovieShortFormat>();
            // End 1.Load Movie Name List

            // 2. Movie Formats Name list and 3. Movie Genre Name list and 4. Load all theaters referenced in the schedule.
            movieFullList.ForEach(movie => {
                var movieFormatExist = mc.formats.Where(x => x.id == movie.idFormat).FirstOrDefault <MovieFormatShort>();
                if (movieFormatExist == null)
                {
                    mc.formats.Add(new MovieFormatShort()
                    {
                        id = movie.idFormat, name = movie.nameFormat
                    });
                }

                var movieGenreExist = mc.genres.Where(x => x.id == movie.idGenre).FirstOrDefault <MovieGenreShort>();
                if (movieGenreExist == null)
                {
                    mc.genres.Add(new MovieGenreShort()
                    {
                        id = movie.idGenre, name = movie.genre
                    });
                }

                var movieTheaterExist = mc.theaters.Where(x => x.id == movie.idLocation).FirstOrDefault <MovieLocationShort>();
                if (movieTheaterExist == null)
                {
                    mc.theaters.Add(new MovieLocationShort()
                    {
                        id = movie.idLocation, name = movie.nameLocation, branchName = movie.branchName, nameFull = movie.nameFullLocation
                    });
                }
            });
            mc.formats  = mc.formats.OrderBy(x => x.name).ToList <MovieFormatShort>();
            mc.genres   = mc.genres.OrderBy(x => x.name).ToList <MovieGenreShort>();
            mc.theaters = mc.theaters.OrderBy(x => x.nameFull).ToList <MovieLocationShort>();
            // End 2. Movie Formats Name list and 3. Movie Genre Name List and 4. Load all theaters referenced in the schedule.

            // 5. Load All Theater Name List and its associated movies.

            // Initialize
            Dictionary <int, List <MovieLocationShort> > movieInTheaters = new Dictionary <int, List <MovieLocationShort> >();

            movieList.ForEach(movie => movieInTheaters.Add(movie.id, new List <MovieLocationShort>()));

            // Now fill locations per movie.
            movieList.ForEach(movie => {
                var movieTheaterSelected = movieInTheaters[movie.id];
                movie.locations.ForEach(loc => movieTheaterSelected.Add(new MovieLocationShort()
                {
                    id = loc.id, name = loc.name, branchName = loc.branchName, nameFull = loc.nameFull
                }));
                movieTheaterSelected = movieTheaterSelected.OrderBy(x => x.nameFull).ToList <MovieLocationShort>();
            });

            // Now store in catalog.
            mc.movieInTheaters = movieInTheaters;
            // End 5. Load All Theater Name List and its associated movies.

            // 6. Load Movie Name List and its associated theaters where each movie is being shown.

            // Initialize theaterMovies for computation.
            // Here we use theaterMoviesDictionary temporary variable so in the process it can be build orderd both
            // its keys and the values it contains.
            Dictionary <string, List <MovieShortFormat> > theaterMoviesDictionary = new Dictionary <string, List <MovieShortFormat> >();

            // Initialize theaterMoviesDictionary with keys ordered by name.
            List <string> theaterNameList = new List <string>();

            mc.theaters.ForEach(t => theaterNameList.Add(t.nameFull));
            theaterNameList = theaterNameList.OrderBy(t => t).ToList <string>();

            // Now that we have a theaterNameList  and ordered, we can now start building the Dictionary values.
            // Initialize theaterMoviesDictionary dictionary for further processing.
            theaterNameList.ForEach(t => theaterMoviesDictionary.Add(t, new List <MovieShortFormat>()));

            // Let's add values to theaterMoviesDictionary
            movieList.ForEach(movie => {
                movie.locations.ForEach(location => {
                    // Retrieve theater item from dictionary
                    var theaterItem = theaterMoviesDictionary[location.nameFull];
                    var existMovie  = theaterItem.Where(x => x.id == movie.id).FirstOrDefault <MovieShortFormat>();
                    if (existMovie == null)
                    {
                        // WARNING!: At this point and supported by mc.movies (which must be already compiled at this point.
                        var movieFormats = mc.movies.Where(x => x.id == movie.id).FirstOrDefault();
                        theaterItem.Add(new MovieShortFormat()
                        {
                            id = movie.id, premiere = movie.premiere, name = movie.name, formats = movieFormats.formats
                        });
                    }
                });
            });

            // Now it is time to copy contents from theaterMoviesDictionary to mc.theaterMovies
            // When traversing its contents the list is sorted as well by name.
            mc.theaterMovies = new Dictionary <string, List <MovieShortFormat> >();
            foreach (var pair in theaterMoviesDictionary)
            {
                mc.theaterMovies.Add(pair.Key, pair.Value.OrderBy(m => m.name).ToList <MovieShortFormat>());
            }

            // End 6. Load Movie Name List and its associated theaters where each movie is being shown.

            // Serialize
            string movieLookupJSON  = JsonConvert.SerializeObject(movieList);
            string movieCatalogJSON = JsonConvert.SerializeObject(mc);

            // Now that we have just  gathered all the information, create static JSON versions
            // Now there are two files to consume the feed

            // Full movie catalog (mapped from origin).
            string fileName = moviesFileName;

            using (StreamWriter writer = new StreamWriter(fileName)) {
                writer.Write(movieLookupJSON);
            }

            fileName = catalogNameFileName;
            using (StreamWriter writer = new StreamWriter(fileName)) {
                writer.Write(movieCatalogJSON);
            }
            if (log.IsDebugEnabled)
            {
                log.Debug("Info compiled");
                log.Debug("movieLookupJSON=[" + movieLookupJSON + "]");
                log.Debug("movieCatalogJSON=[" + movieCatalogJSON + "]");
                log.Debug("CompileAllMoviesSchedule Ends");
            }
        }
 public void Verify_MapToEntity_WithExistingEntity_AssignsMovieLocationProperties()
 {
     // Arrange
     var mapper = new MovieLocationMapper();
     var model = MovieLocationsMockingSetup.DoMockingSetupForMovieLocationModel();
     // Act
     IMovieLocation existingEntity = new MovieLocation { Id = 1 };
     mapper.MapToEntity(model.Object, ref existingEntity);
     // Assert
     // <None>
     // Related Objects
     Assert.Equal(model.Object.MovieId, existingEntity.MovieId);
     Assert.Equal(model.Object.LocationId, existingEntity.LocationId);
     // Associated Objects
     // <None>
 }