Exemplo n.º 1
0
        public void TestExecuteWithRetry_OperationFails()
        {
            //Arrange
            const int numberOfRetriesToAttempt   = 3;
            const int numberOfFailuresToSimulate = 3;

            var operationSimulator   = new OperationSimulator(numberOfFailuresToSimulate);
            Func <Task <bool> > func = () => operationSimulator.SimulateOperationWithFailures();

            //Act
            Exception ex = Assert.Throws <AggregateException>(() => RetryOperationHelper.ExecuteWithRetryAsync(func, numberOfRetriesToAttempt).Wait());

            Assert.Equal(ex.InnerException.InnerException.Message, "OperationSimulator: Simulating Operation Failure");
        }
Exemplo n.º 2
0
        public void TestExecuteWithRetry_OperationSucceeds()
        {
            //Arrange
            const int numberOfRetriesToAttempt   = 3;
            const int numberOfFailuresToSimulate = 2;

            var operationSimulator   = new OperationSimulator(numberOfFailuresToSimulate);
            Func <Task <bool> > func = () => operationSimulator.SimulateOperationWithFailures();

            //Act
            var result = RetryOperationHelper.ExecuteWithRetryAsync(func, numberOfRetriesToAttempt).Result;

            //Assert
            Assert.Equal(result, true);
        }
Exemplo n.º 3
0
        public void TestExecuteWithRetry_OperationFails_VerifyOnFailureActionIsCalled()
        {
            //Arrange
            const int numberOfRetriesToAttempt   = 3;
            const int numberOfFailuresToSimulate = 3;
            TimeSpan  retryTimeSpan = new TimeSpan(0, 0, 0, 1);

            var operationSimulator       = new OperationSimulator(numberOfFailuresToSimulate);
            Func <Task <bool> >     func = () => operationSimulator.SimulateOperationWithFailures();
            Action <int, Exception> actionUponFailure = new Action <int, Exception>(operationSimulator.ThrowException);

            //Act
            Exception ex = Assert.Throws <AggregateException>(() => RetryOperationHelper.ExecuteWithRetryAsync(func, numberOfRetriesToAttempt, retryTimeSpan, actionUponFailure).Wait());

            Assert.Equal(ex.InnerException.Message, "OperationSimulator: ThrowException: Exception thrown to identify method");
        }
Exemplo n.º 4
0
        public async Task <AuthorizationResult> AcquireAuthorizationAsync(
            Uri authorizationUri,
            Uri redirectUri,
            RequestContext requestContext,
            CancellationToken cancellationToken)
        {
            bool ssoMode = string.Equals(redirectUri.OriginalString, Constants.UapWEBRedirectUri, StringComparison.OrdinalIgnoreCase);

            WebAuthenticationResult  webAuthenticationResult;
            WebAuthenticationOptions options = (_useCorporateNetwork &&
                                                (ssoMode || redirectUri.Scheme == Constants.MsAppScheme))
                ? WebAuthenticationOptions.UseCorporateNetwork
                : WebAuthenticationOptions.None;

            if (_silentMode)
            {
                options |= WebAuthenticationOptions.SilentMode;
            }

            try
            {
                webAuthenticationResult = await RetryOperationHelper.ExecuteWithRetryAsync(
                    () => InvokeWABOnMainThreadAsync(authorizationUri, redirectUri, ssoMode, options),
                    WABRetryAttempts,
                    onAttemptFailed : (attemptNumber, exception) =>
                {
                    _requestContext.Logger.Warning($"Attempt {attemptNumber} to call WAB failed");
                    _requestContext.Logger.WarningPii(exception);
                })
                                          .ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                requestContext.Logger.ErrorPii(ex);
                throw new MsalException(
                          MsalError.AuthenticationUiFailedError,
                          "Web Authentication Broker (WAB) authentication failed. To collect WAB logs, please follow https://aka.ms/msal-net-wab-logs",
                          ex);
            }

            AuthorizationResult result = ProcessAuthorizationResult(webAuthenticationResult);

            return(result);
        }