Esempio n. 1
0
        public void GetWatchedMovies(List <ITraktWatchedMovie> onlineWatchedMovies, ITraktSyncLastActivities onlineLastSyncActivities, int expectedWatchedMoviesCount)
        {
            // Arrange
            ITraktClient traktClient = Substitute.For <ITraktClient>();

            traktClient.GetWatchedMovies().Returns(onlineWatchedMovies);
            traktClient.GetLastActivities().Returns(onlineLastSyncActivities);

            IFileOperations fileOperations = Substitute.For <IFileOperations>();

            SetFileOperationsForFile(fileOperations, DataPath, FileName.LastActivity.Value);
            SetFileOperationsForFile(fileOperations, DataPath, FileName.WatchedMovies.Value);
            SetFileOperationsForFile(fileOperations, DataPath, FileName.CollectedMovies.Value);

            IMediaPortalServices mediaPortalServices = Substitute.For <IMediaPortalServices>();

            mediaPortalServices.GetTraktUserHomePath().Returns(DataPath);

            // Act
            ITraktCache traktCache  = new TraktCache(mediaPortalServices, traktClient, fileOperations);
            TraktMovies traktMovies = traktCache.RefreshMoviesCache();

            // Assert
            int actualWatchedMoviesCount = traktMovies.Watched.Count();

            Assert.Equal(expectedWatchedMoviesCount, actualWatchedMoviesCount);
        }
Esempio n. 2
0
        private IList <Movie> RefreshUnWatchedMovies()
        {
            IEnumerable <MovieWatched>       previouslyWatched = CachedWatchedMovies();
            IEnumerable <ITraktWatchedMovie> currentWatched    = _traktClient.GetWatchedMovies();
            IEnumerable <Movie> unWatchedMovies = new List <Movie>();

            // anything not in the current watched that is previously watched
            // must be unwatched now.
            if (previouslyWatched != null)
            {
                unWatchedMovies = from pw in previouslyWatched
                                  where !currentWatched.Any(m => (m.Movie.Ids.Trakt == pw.TraktId || m.Movie.Ids.Imdb == pw.Imdb))
                                  select new Movie
                {
                    Imdb    = pw.Imdb,
                    TraktId = pw.TraktId,
                    Tmdb    = pw.Tmdb,
                    Title   = pw.Title,
                    Year    = pw.Year
                };
            }
            return(unWatchedMovies.ToList());
        }