Esempio n. 1
0
        public void TestPrepareForRetry()
        {
            LoginUtil.Cache.AddToken(USER_NAME, USER_TOKEN);
            (user.Config as DfaAppConfig).DfaAuthToken = PASSWORD;
            adRemoteService.Token  = USER_TOKEN;
            user.Config.RetryCount = 1;

            // PrepareForRetry should reset all relevant values when presented with
            // correct values.
            DfaErrorHandler errorHandler = new DfaErrorHandler(adRemoteService);

            errorHandler.PrepareForRetry(new DfaCredentialsExpiredException(USER_TOKEN));
            Assert.IsNull(LoginUtil.Cache.GetToken(USER_NAME));
            Assert.IsNull(adRemoteService.Token);
            Assert.IsNull((user.Config as DfaAppConfig).DfaAuthToken);

            // Indirectly test retryCount. This should become 1 after
            // PrepareForRetry() and another attempt to retry should fail.
            Assert.IsFalse(errorHandler.ShouldRetry(new DfaCredentialsExpiredException(USER_TOKEN)));

            // PrepareRetry should rethrow any exception that is not
            // DfaCredentialsExpiredException
            errorHandler = new DfaErrorHandler(adRemoteService);

            Exception ex = new Exception();

            try {
                errorHandler.PrepareForRetry(ex);
                Assert.Fail("Should not prepare for retry if exception is not " +
                            "DfaCredentialsExpiredException.");
            } catch (Exception e) {
                Assert.AreSame(ex, e);
            }
        }
Esempio n. 2
0
        public void TestIsTokenExpiredError()
        {
            DfaException exception = null;

            exception = new DfaApiException(TOKEN_EXPIRED_CODE, TOKEN_EXPIRED_MESSAGE);
            Assert.IsTrue(DfaErrorHandler.IsTokenExpiredError(exception));

            exception = new DfaApiException(TOKEN_EXPIRED_CODE, RANDOM_ERROR_MESSAGE);
            Assert.IsFalse(DfaErrorHandler.IsTokenExpiredError(exception));

            exception = new DfaApiException(RANDOM_ERROR_CODE, TOKEN_EXPIRED_MESSAGE);
            Assert.IsFalse(DfaErrorHandler.IsTokenExpiredError(exception));
        }
Esempio n. 3
0
        public void TestShouldRetry()
        {
            DfaErrorHandler errorHandler = null;

            // Should not retry if RetryCount == 0
            errorHandler           = new DfaErrorHandler(adRemoteService);
            user.Config.RetryCount = 0;
            Assert.IsFalse(errorHandler.ShouldRetry(new DfaCredentialsExpiredException(USER_TOKEN)));

            // Should not retry if exception is not DfaCredentialsExpiredException.
            errorHandler           = new DfaErrorHandler(adRemoteService);
            user.Config.RetryCount = 1;
            Assert.IsFalse(errorHandler.ShouldRetry(new ArgumentNullException()));

            // Should retry if exception is DfaCredentialsExpiredException and
            // RetryCount > 0
            errorHandler           = new DfaErrorHandler(adRemoteService);
            user.Config.RetryCount = 1;
            Assert.IsTrue(errorHandler.ShouldRetry(new DfaCredentialsExpiredException(USER_TOKEN)));
        }