public void Then_it_should_not_throw_any_exceptions()
        {
            Should.NotThrow(_action);

            IgnoredException.ShouldBeOfType <DivideByZeroException>();
            IgnoredException.Message.ShouldBe("Attempted to divide by zero.");

            Result.ShouldBe(new[] { 1 });
        }
コード例 #2
0
        public async Task <bool> BeginAsync()
        {
            if (!IsAsync)
            {
                throw new ArgumentException($"{nameof(Retry)} is not Asynchronous");
            }

            ThrowIfNull(($"{nameof(toRetryAsync)}", toRetryAsync));

            for (int attempt = 1; attempt <= Attempts; attempt++)
            {
                AttemptStart?.Invoke(this, new AttemptStartEventArgs(attempt));

                try
                {
                    if (await toRetryAsync())
                    {
                        return(true);
                    }
                }
                catch (Exception ex)
                {
                    CheckContinueThrow(
                        ex,
                        IgnoreExceptions,
                        ExceptionWhitelist,
                        ExceptionBlacklist
                        );

                    IgnoredException?.Invoke(this, new UnhandledExceptionEventArgs(ex, false));
                }

                AttemptFailure?.Invoke(this, new AttemptStartEventArgs(attempt));

                await Task.Delay(
                    GetWaitTime(
                        attempt,
                        InitialDelay,
                        backoff
                        ));
            }

            return(false);
        }