コード例 #1
0
        public static Task RaiseExceptionAsync <TException>(this AsyncPolicy policy, TException instance) where TException : Exception
        {
            ExceptionAndOrCancellationScenario scenario = new ExceptionAndOrCancellationScenario
            {
                ActionObservesCancellation    = false,
                AttemptDuringWhichToCancel    = null,
                NumberOfTimesToRaiseException = 1
            };

            return(policy.RaiseExceptionAndOrCancellationAsync(scenario, new CancellationTokenSource(), () => { }, _ => instance));
        }
コード例 #2
0
        public static Task RaiseExceptionAsync <TException>(this AsyncPolicy policy, int numberOfTimesToRaiseException, Action <TException, int> configureException = null, CancellationToken cancellationToken = default(CancellationToken)) where TException : Exception, new()
        {
            ExceptionAndOrCancellationScenario scenario = new ExceptionAndOrCancellationScenario
            {
                ActionObservesCancellation    = false,
                AttemptDuringWhichToCancel    = null,
                NumberOfTimesToRaiseException = numberOfTimesToRaiseException
            };

            Func <int, TException> exceptionFactory = i =>
            {
                var exception = new TException();
                configureException?.Invoke(exception, i);
                return(exception);
            };

            return(policy.RaiseExceptionAndOrCancellationAsync(scenario, new CancellationTokenSource(), () => { }, exceptionFactory));
        }
コード例 #3
0
 public static Task <TResult> RaiseExceptionAndOrCancellationAsync <TException, TResult>(this AsyncPolicy policy, ExceptionAndOrCancellationScenario scenario, CancellationTokenSource cancellationTokenSource, Action onExecute, TResult successResult) where TException : Exception, new()
 {
     return(policy.RaiseExceptionAndOrCancellationAsync(scenario, cancellationTokenSource, onExecute,
                                                        _ => new TException(), successResult));
 }
コード例 #4
0
 public static Task RaiseExceptionAndOrCancellationAsync <TException>(this AsyncPolicy policy, ExceptionAndOrCancellationScenario scenario, CancellationTokenSource cancellationTokenSource, Action onExecute) where TException : Exception, new()
 {
     return(policy.RaiseExceptionAndOrCancellationAsync <TException>(scenario, cancellationTokenSource, onExecute, _ => new TException()));
 }