コード例 #1
0
        public void ShouldFailToAuthorizeUserWhenTraktAuthorizationThrowsException()
        {
            // Arrange
            IMediaPortalServices mediaPortalServices = Substitute.For <IMediaPortalServices>();

            mediaPortalServices.GetTraktUserHomePath().Returns(DataPath);
            ITraktClient traktClient = Substitute.For <ITraktClient>();

            traktClient.GetAuthorization(Arg.Any <string>()).Throws(new TraktException("Pin code is not valid"));
            ILibrarySynchronization librarySynchronization = Substitute.For <ILibrarySynchronization>();
            IFileOperations         fileOperations         = Substitute.For <IFileOperations>();

            fileOperations.DirectoryExists(DataPath).Returns(true);
            string expectedStatus = "[Trakt.AuthorizationFailed]";

            TraktSetupModel setupModel = new TraktSetupModel(mediaPortalServices, traktClient, librarySynchronization, fileOperations);

            // Act
            setupModel.AuthorizeUser();
            string actualStatus = setupModel.TestStatus;

            // Assert
            Assert.Equal(expectedStatus, actualStatus);
            Assert.False(setupModel.IsUserAuthorized);
        }
コード例 #2
0
        public void AuthorizeUser()
        {
            try
            {
                ITraktAuthorization      authorization           = _traktClient.GetAuthorization(PinCode);
                ITraktUserSettings       traktUserSettings       = _traktClient.GetTraktUserSettings();
                ITraktSyncLastActivities traktSyncLastActivities = _traktClient.GetLastActivities();

                string traktUserHomePath = _mediaPortalServices.GetTraktUserHomePath();
                if (!_fileOperations.DirectoryExists(traktUserHomePath))
                {
                    _fileOperations.CreateDirectory(traktUserHomePath);
                }

                SaveTraktAuthorization(authorization, traktUserHomePath);
                SaveTraktUserSettings(traktUserSettings, traktUserHomePath);
                SaveLastSyncActivities(traktSyncLastActivities, traktUserHomePath);

                TestStatus       = "[Trakt.AuthorizationSucceed]";
                IsUserAuthorized = true;
            }
            catch (Exception ex)
            {
                TestStatus = "[Trakt.AuthorizationFailed]";
                _mediaPortalServices.GetLogger().Error(ex);
                IsUserAuthorized = false;
            }
        }
コード例 #3
0
        public void ShouldAuthorizeUserForValidData()
        {
            // Arrange
            IMediaPortalServices mediaPortalServices = Substitute.For <IMediaPortalServices>();

            mediaPortalServices.GetTraktUserHomePath().Returns(DataPath);
            ITraktClient            traktClient            = Substitute.For <ITraktClient>();
            ILibrarySynchronization librarySynchronization = Substitute.For <ILibrarySynchronization>();
            IFileOperations         fileOperations         = Substitute.For <IFileOperations>();

            fileOperations.DirectoryExists(DataPath).Returns(true);
            string expectedStatus = "[Trakt.AuthorizationSucceed]";

            TraktSetupModel setupModel = new TraktSetupModel(mediaPortalServices, traktClient, librarySynchronization, fileOperations);

            // Act
            setupModel.AuthorizeUser();
            string actualStatus = setupModel.TestStatus;

            // Assert
            Assert.Equal(expectedStatus, actualStatus);
            Assert.True(setupModel.IsUserAuthorized);
        }
コード例 #4
0
        public string[] GetPuzzleFilePathsFromPuzzleDirectory(string puzzleDirectory, int maximumNumberOfFiles)
        {
            string puzzleDirectoryPath = $"{_fileOperations.ApplicationBasePath("WordSearch")}{Path.DirectorySeparatorChar}{puzzleDirectory}";

            if (!_fileOperations.DirectoryExists(puzzleDirectoryPath))
            {
                throw new ArgumentException($"directory does not exist: {puzzleDirectoryPath}");
            }

            string[] puzzleFilePaths = _fileOperations.GetSortedDirectoryContents(puzzleDirectoryPath);

            if (puzzleFilePaths.Length == 0)
            {
                throw new ArgumentException($"puzzle directory contains no files: {puzzleDirectoryPath}");
            }

            if (puzzleFilePaths.Length > maximumNumberOfFiles)
            {
                Array.Resize(ref puzzleFilePaths, maximumNumberOfFiles);
            }

            return(puzzleFilePaths);
        }