Example #1
0
        private IList <Episode> RefreshUnWatchedEpisodes()
        {
            IEnumerable <Episode>           previouslyWatchedEpisodes = GetWatchedEpisodesFromCache();
            IEnumerable <ITraktWatchedShow> currentWatchedShows       = _traktClient.GetWatchedShows();
            IEnumerable <ITraktWatchedShow> currentWatchedShowsList   = currentWatchedShows.ToList();
            IList <EpisodeWatched>          currentEpisodesWatched    = ConvertWatchedShowsToWatchedEpisodes(currentWatchedShowsList);

            // anything not in the current watched that is previously watched
            // must be unwatched now.
            // Note: we can add to internal cache from external events, so we can't always rely on trakt id for comparisons
            ILookup <string, EpisodeWatched> dictCurrWatched = currentEpisodesWatched.ToLookup(cwe => cwe.ShowTvdbId + "_" + cwe.Season + "_" + cwe.Number);

            IEnumerable <Episode> unWatchedEpisodes = from pwe in previouslyWatchedEpisodes
                                                      where !dictCurrWatched[pwe.ShowTvdbId + "_" + pwe.Season + "_" + pwe.Number].Any()
                                                      select new Episode
            {
                ShowId     = pwe.ShowId,
                ShowTvdbId = pwe.ShowTvdbId,
                ShowImdbId = pwe.ShowImdbId,
                ShowTitle  = pwe.ShowTitle,
                ShowYear   = pwe.ShowYear,
                Season     = pwe.Season,
                Number     = pwe.Number
            };

            return(unWatchedEpisodes.ToList());
        }
Example #2
0
        public void GetWatchedEpisodes(List <ITraktWatchedShow> onlineWatchedShows, ITraktSyncLastActivities onlineLastSyncActivities, int expectedWatchedEpisodesCount)
        {
            // Arrange
            ITraktClient traktClient = Substitute.For <ITraktClient>();

            traktClient.GetWatchedShows().Returns(onlineWatchedShows);
            traktClient.GetLastActivities().Returns(onlineLastSyncActivities);

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

            SetFileOperationsForFile(fileOperations, DataPath, FileName.LastActivity.Value);
            SetFileOperationsForFile(fileOperations, DataPath, FileName.WatchedEpisodes.Value);
            SetFileOperationsForFile(fileOperations, DataPath, FileName.CollectedEpisodes.Value);

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

            mediaPortalServices.GetTraktUserHomePath().Returns(DataPath);

            // Act
            ITraktCache   traktCache    = new TraktCache(mediaPortalServices, traktClient, fileOperations);
            TraktEpisodes traktEpisodes = traktCache.RefreshSeriesCache();

            // Assert
            int actualWatchedEpisodesCount = traktEpisodes.Watched.Count();

            Assert.Equal(expectedWatchedEpisodesCount, actualWatchedEpisodesCount);
        }