예제 #1
0
        private IList <EpisodeCollected> GetCollectedEpisodesFromCache()
        {
            IEnumerable <ITraktCollectionShow> traktCollectionShows = new List <ITraktCollectionShow>();

            string collectedEpisodesPath = Path.Combine(_mediaPortalServices.GetTraktUserHomePath(), FileName.CollectedEpisodes.Value);

            if (_fileOperations.FileExists(collectedEpisodesPath))
            {
                string collectedEpisodesJson = _fileOperations.FileReadAllText(collectedEpisodesPath);
                traktCollectionShows = TraktSerializationService.DeserializeCollectionAsync <ITraktCollectionShow>(collectedEpisodesJson).Result;
            }

            return(ConvertCollectionShowsToCollectedEpisodes(traktCollectionShows));
        }
예제 #2
0
 private void SetFileOperationsForFile(IFileOperations fileOperations, string path, string fileName)
 {
     fileOperations.FileExists(Arg.Is <string>(x => x.Equals(Path.Combine(path, fileName))))
     .Returns(true);
     fileOperations.FileReadAllText(Arg.Is <string>(x => x.Equals(Path.Combine(path, fileName))))
     .Returns(File.ReadAllText(TestUtility.GetTestDataPath(Path.Combine(@"Cache\", fileName)), Encoding.UTF8));
 }
예제 #3
0
        public void EnterModelContext(NavigationContext oldContext, NavigationContext newContext)
        {
            // clear the PIN code text box, necessary when entering the plugin
            PinCode = string.Empty;

            string authFilePath        = Path.Combine(_mediaPortalServices.GetTraktUserHomePath(), FileName.Authorization.Value);
            bool   savedAuthFileExists = _fileOperations.FileExists(authFilePath);

            if (!savedAuthFileExists)
            {
                TestStatus       = "[Trakt.NotAuthorized]";
                IsUserAuthorized = false;
            }
            else
            {
                string savedAuthorization         = _fileOperations.FileReadAllText(authFilePath);
                ITraktAuthorization savedAuthFile = TraktSerializationService.DeserializeAsync <ITraktAuthorization>(savedAuthorization).Result;
                if (savedAuthFile.IsRefreshPossible)
                {
                    TestStatus       = "[Trakt.AlreadyAuthorized]";
                    IsUserAuthorized = true;
                }
                else
                {
                    TestStatus       = "[Trakt.SavedAuthIsNotValid]";
                    IsUserAuthorized = false;
                }
            }
        }
예제 #4
0
        private IList <MediaLibraryEpisode> ReadSavedWatchedEpisodes(string path)
        {
            IList <MediaLibraryEpisode> watchedEpisodes;

            string watchedEpisodesPath = Path.Combine(path, FileName.WatchedEpisodes.Value);

            if (_fileOperations.FileExists(watchedEpisodesPath))
            {
                string watchedEpisodesJson = _fileOperations.FileReadAllText(watchedEpisodesPath);
                watchedEpisodes = JsonConvert.DeserializeObject <List <MediaLibraryEpisode> >(watchedEpisodesJson);
            }
            else
            {
                throw new PathNotFoundException("Watched series path not found.");
            }

            return(watchedEpisodes);
        }
예제 #5
0
        public void Should_MarkFourEpisodesAsWatched_When_FourEpisodesRestored()
        {
            // Arrange
            IMediaPortalServices mediaPortalServices = Substitute.For <IMediaPortalServices>();
            IContentDirectory    contentDirectory    = Substitute.For <IContentDirectory>();
            IList <MediaItem>    databaseMediaItems  = new List <MediaItem>
            {
                new MockedDatabaseEpisode("272127", 1, new List <int> {
                    7, 8
                }, 0).Episode,
                new MockedDatabaseEpisode("317653", 1, new List <int> {
                    1
                }, 0).Episode,
                new MockedDatabaseEpisode("317653", 1, new List <int> {
                    2
                }, 0).Episode,
                new MockedDatabaseEpisode("275271", 2, new List <int> {
                    11, 12
                }, 0).Episode
            };

            contentDirectory.SearchAsync(Arg.Any <MediaItemQuery>(), true, null, false).Returns(databaseMediaItems);
            mediaPortalServices.GetServerConnectionManager().ContentDirectory.Returns(contentDirectory);
            mediaPortalServices.MarkAsWatched(Arg.Any <MediaItem>()).Returns(true);

            string          savedEpisodesPath = Path.Combine(FakePath, FileName.WatchedEpisodes.Value);
            IFileOperations fileOperations    = Substitute.For <IFileOperations>();

            fileOperations.FileExists(savedEpisodesPath).Returns(true);
            string watchedEpisodesJson =
                "[{\"show_imdb\":\"tt6682754\",\"show_tvdb\":317653,\"show_title\":\"Je-an-Claude Van Johnson\",\"season\":1,\"number\":1}," +
                "{\"show_imdb\":\"tt3155320\",\"show_tvdb\":272127,\"show_title\":\"Extant\",\"season\":1,\"number\":7}," +
                "{\"show_imdb\":\"tt3155320\",\"show_tvdb\":272127,\"show_title\":\"Extant\",\"season\":1,\"number\":8}," +
                "{\"show_imdb\":\"tt6682754\",\"show_tvdb\":317653,\"show_title\":\"Jean-Claude Van Johnson\",\"season\":1,\"number\":2}]";

            fileOperations.FileReadAllText(savedEpisodesPath).Returns(watchedEpisodesJson);

            IMoverOperations operations = new MoverOperations(mediaPortalServices, fileOperations);

            // Act
            RestoreResult result = operations.RestoreWatchedSeries(FakePath);

            // Assert
            Assert.Equal(4, result.MarkedWatchedCount);
            Assert.Equal(4, result.SavedWatchedCount);
        }
예제 #6
0
        private void ValidateAuthorization(ITraktClient _traktClient, IFileOperations _fileOperations)
        {
            if (!_traktClient.TraktAuthorization.IsValid)
            {
                string authFilePath           = Path.Combine(HomeUserPath, FileName.Authorization.Value);
                string savedAuthorization     = _fileOperations.FileReadAllText(authFilePath);
                ITraktAuthorization savedAuth = TraktSerializationService.DeserializeAsync <ITraktAuthorization>(savedAuthorization).Result;

                if (!savedAuth.IsRefreshPossible)
                {
                    throw new Exception("Saved authorization is not valid.");
                }

                ITraktAuthorization refreshedAuth = _traktClient.RefreshAuthorization(savedAuth.RefreshToken);
                string serializedAuth             = TraktSerializationService.SerializeAsync(refreshedAuth).Result;
                _fileOperations.FileWriteAllText(authFilePath, serializedAuth, Encoding.UTF8);
            }
        }
예제 #7
0
        public void Should_MarkOneMovieAsWatched_When_OneMovieRestored()
        {
            // Arrange
            IMediaPortalServices mediaPortalServices = Substitute.For <IMediaPortalServices>();
            IContentDirectory    contentDirectory    = Substitute.For <IContentDirectory>();
            IList <MediaItem>    databaseMediaItems  = new List <MediaItem>
            {
                new MockedDatabaseMovie(new MediaLibraryMovie {
                    Imdb = "tt0268380", Title = "Ice Age", Tmdb = null, Year = 2002
                }, 0).Movie,
                new MockedDatabaseMovie(new MediaLibraryMovie {
                    Imdb = "tt0457939", Title = "Title_2", Tmdb = null, Year = 2016
                }, 0).Movie,
                new MockedDatabaseMovie(new MediaLibraryMovie {
                    Imdb = "tt1355630", Title = "Title_3", Tmdb = null, Year = 2013
                }, 0).Movie
            };

            contentDirectory.SearchAsync(Arg.Any <MediaItemQuery>(), true, null, false).Returns(databaseMediaItems);
            mediaPortalServices.GetServerConnectionManager().ContentDirectory.Returns(contentDirectory);
            mediaPortalServices.MarkAsWatched(Arg.Any <MediaItem>()).Returns(true);

            string          savedMoviesPath = Path.Combine(FakePath, FileName.WatchedMovies.Value);
            IFileOperations fileOperations  = Substitute.For <IFileOperations>();

            fileOperations.FileExists(savedMoviesPath).Returns(true);
            string watchedMoviesJson =
                "[{\"imdb\":\"tt0268380\",\"tmdb\":null,\"title\":\"Ice Age\",\"year\":2002}]";

            fileOperations.FileReadAllText(savedMoviesPath).Returns(watchedMoviesJson);

            IMoverOperations operations = new MoverOperations(mediaPortalServices, fileOperations);

            // Act
            RestoreResult result = operations.RestoreWatchedMovies(FakePath);

            // Assert
            Assert.Equal(1, result.MarkedWatchedCount);
            Assert.Equal(1, result.SavedWatchedCount);
        }