Exemple #1
0
        public MoviePoco Map(MovieTmdb movieTmdb, MovieOmdb movieOmdb)
        {
            var movieGenres = new List <MovieGenre>();

            foreach (var genre in movieTmdb.Genres)
            {
                var movieGenre = new MovieGenre
                {
                    Title    = movieOmdb.Title,
                    Released = movieOmdb.Released,
                    GenreId  = genre.Id
                };

                movieGenres.Add(movieGenre);
            }

            var movie = new MoviePoco
            {
                Title       = movieOmdb.Title,
                Released    = movieOmdb.Released,
                ImdbRating  = movieOmdb.ImdbRating,
                Metascore   = movieOmdb.Metascore,
                TomatoMeter = movieOmdb.TomatoMeter,
                ImdbVotes   = movieOmdb.ImdbVotes,
                Runtime     = movieOmdb.Runtime,
                Plot        = movieOmdb.Plot,
                Director    = movieOmdb.Director,
                Awards      = movieOmdb.Awards,
                MovieGenres = movieGenres
            };

            return(movie);
        }
        public void ItReturns_CorrectPoco_FromTmdbOmdbDtos(MovieOmdb omdb, MovieTmdb tmdb)
        {
            var moviesMapper = new MoviesMapper();

            var moviesPoco = moviesMapper.Map(tmdb, omdb);

            bool movieGenresMappedCorrectly = true;

            for (var i = 0; i < tmdb.Genres.Length; i++)
            {
                var movieGenre = moviesPoco.MovieGenres.ElementAt(i);

                if (movieGenre.GenreId != tmdb.Genres[i].Id ||
                    movieGenre.Title != omdb.Title ||
                    movieGenre.Released != omdb.Released)
                {
                    movieGenresMappedCorrectly = false;
                }
            }


            Assert.True(movieGenresMappedCorrectly);
            Assert.Equal(omdb.ImdbVotes, moviesPoco.ImdbVotes);
            Assert.Equal(omdb.Awards, moviesPoco.Awards);
            Assert.Equal(omdb.Director, moviesPoco.Director);
            Assert.Equal(omdb.ImdbRating, moviesPoco.ImdbRating);
            Assert.Equal(omdb.Metascore, moviesPoco.Metascore);
            Assert.Equal(omdb.Plot, moviesPoco.Plot);
            Assert.Equal(omdb.Released, moviesPoco.Released);
            Assert.Equal(omdb.Runtime, moviesPoco.Runtime);
            Assert.Equal(omdb.Title, moviesPoco.Title);
            Assert.Equal(omdb.TomatoMeter, moviesPoco.TomatoMeter);
        }
Exemple #3
0
        protected async Task <MovieTmdb> GetMovieById(int id)
        {
            var path = FormatPath(id);

            MovieTmdb movie = null;

            HttpResponseMessage response;

            do
            {
                response = await _client.GetAsync(path);

                if (response.IsSuccessStatusCode && response.Content != null)
                {
                    var requestContent = await response.Content.ReadAsStringAsync();

                    movie = JsonConvert.DeserializeObject <MovieTmdb>(requestContent);
                }

                if (response.StatusCode == (HttpStatusCode)429)
                {
                    await Task.Delay(3000);
                }
            } while (movie == null && response.StatusCode != HttpStatusCode.NotFound);

            return(movie);
        }
Exemple #4
0
        protected async Task UpdateMoviesByImdbId(MovieTmdb movieTmdb)
        {
            var movieOmdb = await _omdbClient.GetMovieByImdbId(movieTmdb.ImdbId);

            if (movieOmdb != null)
            {
                var movie = _moviesMapper.Map(movieTmdb, movieOmdb);

                RemoveUnkownGenres(movie);

                await _moviesRepository.AddMovie(movie);
            }
        }
Exemple #5
0
        public MovieTmdb Map(MovieByGenreTmdb movieByGenre)
        {
            var genres = new List <Genre>();

            foreach (var genre in movieByGenre.GenreIds)
            {
                var movieGenre = new Genre
                {
                    Id = genre
                };

                genres.Add(movieGenre);
            }

            var movie = new MovieTmdb
            {
                Genres = genres.ToArray()
            };

            return(movie);
        }