diff --git a/test/Polly.Specs/PolicyContextAndKeyAsyncSpecs.cs b/test/Polly.Specs/PolicyContextAndKeyAsyncSpecs.cs index 7948d057fdd..2fad80e08cd 100644 --- a/test/Polly.Specs/PolicyContextAndKeyAsyncSpecs.cs +++ b/test/Polly.Specs/PolicyContextAndKeyAsyncSpecs.cs @@ -103,6 +103,13 @@ public void Should_not_be_able_to_configure_the_policy_key_explicitly_after_retr configure.Should().Throw().And.ParamName.Should().Be("policyKey"); } + [Fact] + public void Should_throw_when_onretry_is_null() + { + var policyBuilder = Policy.Handle(); + Assert.Throws("onRetry", () => policyBuilder.RetryAsync(3, default(Action))); + } + #endregion #region PolicyKey and execution Context tests diff --git a/test/Polly.Specs/Retry/RetryForeverAsyncSpecs.cs b/test/Polly.Specs/Retry/RetryForeverAsyncSpecs.cs index f3cbec69021..61b58d34489 100644 --- a/test/Polly.Specs/Retry/RetryForeverAsyncSpecs.cs +++ b/test/Polly.Specs/Retry/RetryForeverAsyncSpecs.cs @@ -96,6 +96,44 @@ await policy.Awaiting(x => x.RaiseExceptionAsync()) .Should().NotThrowAsync(); } + [Fact] + public void Should_throw_when_onretry_exception_is_null() + { + var policyBuilder = Policy.Handle(); + Assert.Throws("onRetry", () => policyBuilder.RetryForeverAsync(default(Action))); + } + + [Fact] + public void Should_throw_when_onretry_exception_int_is_null() + { + var policyBuilder = Policy.Handle(); + Assert.Throws("onRetry", () => policyBuilder.RetryForeverAsync(default(Action))); + } + + [Fact] + public void Should_throw_when_onretry_exception_context_is_null() + { + var policyBuilder = Policy.Handle(); + Assert.Throws("onRetry", () => policyBuilder.RetryForeverAsync(default(Action))); + } + + [Fact] + public void Should_throw_when_onretry_exception_int_context_is_null() + { + var policyBuilder = Policy.Handle(); + Assert.Throws("onRetry", () => policyBuilder.RetryForeverAsync(default(Action))); + } + + [Fact] + public void Should_throw_when_onretry_exception_timespan_context_is_null() + { + var policyBuilder = Policy.Handle(); + Assert.Throws("onRetry", () => policyBuilder.WaitAndRetryAsync( + retryCount: 3, + sleepDurationProvider: _ => TimeSpan.FromSeconds(1), + onRetry: default(Action))); + } + [Fact] public async Task Should_call_onretry_on_each_retry_with_the_current_exception() { diff --git a/test/Polly.Specs/Retry/WaitAndRetryAsyncSpecs.cs b/test/Polly.Specs/Retry/WaitAndRetryAsyncSpecs.cs index 7c18bcaa9d7..fbc8971044b 100644 --- a/test/Polly.Specs/Retry/WaitAndRetryAsyncSpecs.cs +++ b/test/Polly.Specs/Retry/WaitAndRetryAsyncSpecs.cs @@ -33,6 +33,67 @@ public void Should_throw_when_onretry_action_is_null_without_context() .ParamName.Should().Be("onRetry"); } + [Fact] + public void Should_throw_when_onretry_exception_timespan_context_is_null_with_sleep_durations() + { + Action policy = () => Policy + .Handle() + .WaitAndRetryAsync(Enumerable.Empty(), default(Action)); + + policy.Should().Throw().And + .ParamName.Should().Be("onRetry"); + } + + [Fact] + public void Should_throw_when_onretry_exception_timespan_int_context_is_null_with_sleep_duration_provider_int_timespan() + { + Func provider = _ => TimeSpan.Zero; + + Action policy = () => Policy + .Handle() + .WaitAndRetryAsync(3, provider, default(Action)); + + policy.Should().Throw().And + .ParamName.Should().Be("onRetry"); + } + + [Fact] + public void Should_throw_when_onretry_exception_timespan_int_context_is_null_with_sleep_durations() + { + Action policy = () => Policy + .Handle() + .WaitAndRetryAsync(Enumerable.Empty(), default(Action)); + + policy.Should().Throw().And + .ParamName.Should().Be("onRetry"); + } + + [Fact] + public void Should_throw_when_onretry_exception_timespan_context_is_null_with_sleep_duration_provider() + { + Func provider = (_, _) => 1.Seconds(); + + Action policy = () => Policy + .Handle() + .WaitAndRetryAsync(3, provider, default(Action)); + + policy.Should().Throw().And + .ParamName.Should().Be("onRetry"); + } + + [Fact] + public void Should_throw_when_onretry_exception_timespan_int_context_is_null_with_sleep_duration_provider() + { + Func provider = (_, _) => 1.Seconds(); + + Action policy = () => Policy + .Handle() + .WaitAndRetryAsync(3, provider, default(Action)); + + policy.Should().Throw().And + .ParamName.Should().Be("onRetry"); + } + [Fact] public async Task Should_not_throw_when_specified_exception_thrown_same_number_of_times_as_there_are_sleep_durations() { diff --git a/test/Polly.Specs/Retry/WaitAndRetryForeverAsyncSpecs.cs b/test/Polly.Specs/Retry/WaitAndRetryForeverAsyncSpecs.cs index 4e88fd0ac4a..2516619892f 100644 --- a/test/Polly.Specs/Retry/WaitAndRetryForeverAsyncSpecs.cs +++ b/test/Polly.Specs/Retry/WaitAndRetryForeverAsyncSpecs.cs @@ -33,6 +33,78 @@ public void Should_throw_when_sleep_duration_provider_is_null_with_context() .ParamName.Should().Be("sleepDurationProvider"); } + [Fact] + public void Should_throw_when_sleep_duration_provider_int_timespan_is_null() + { + Action policy = () => Policy + .Handle() + .WaitAndRetryForeverAsync(default(Func)); + + policy.Should().Throw().And + .ParamName.Should().Be("sleepDurationProvider"); + } + + [Fact] + public void Should_throw_when_sleep_duration_provider_int_timespan_is_null_with_onretry() + { + Action onRetry = (_, _, _) => { }; + + Action policy = () => Policy + .Handle() + .WaitAndRetryForeverAsync(default, onRetry); + + policy.Should().Throw().And + .ParamName.Should().Be("sleepDurationProvider"); + } + + [Fact] + public void Should_throw_when_sleep_duration_provider_int_context_timespan_is_null() + { + Action policy = () => Policy + .Handle() + .WaitAndRetryForeverAsync(default(Func)); + + policy.Should().Throw().And + .ParamName.Should().Be("sleepDurationProvider"); + } + + [Fact] + public void Should_throw_when_onretry_exception_int_timespan_is_null_with_sleep_duration_provider() + { + Func provider = _ => TimeSpan.Zero; + + Action policy = () => Policy + .Handle() + .WaitAndRetryForeverAsync(provider, default(Action)); + + policy.Should().Throw().And + .ParamName.Should().Be("onRetry"); + } + + [Fact] + public void Should_throw_when_sleep_duration_provider_int_context_timespan_is_null_with_retry() + { + Action policy = () => Policy + .Handle() + .WaitAndRetryForeverAsync(default(Func), default(Action)); + + policy.Should().Throw().And + .ParamName.Should().Be("sleepDurationProvider"); + } + + [Fact] + public void Should_throw_when_onretry_exception_int_timespan_context_is_null_with_sleep_duration_provider() + { + Func provider = (_, _) => 1.Seconds(); + + Action policy = () => Policy + .Handle() + .WaitAndRetryForeverAsync(provider, default(Action)); + + policy.Should().Throw().And + .ParamName.Should().Be("onRetry"); + } + [Fact] public void Should_throw_when_onretry_action_is_null_without_context() {