Ejemplo n.º 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);
        }
Ejemplo n.º 2
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);
        }