Skip to content

Commit

Permalink
Add tests for multiple nested aggregate exceptions App-vNext#818
Browse files Browse the repository at this point in the history
  • Loading branch information
sideproject committed Jan 24, 2021
1 parent dd52d54 commit 118236e
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/Polly.Specs/Retry/RetrySpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,52 @@ public void Should_call_onretry_with_handled_exception_nested_in_aggregate_as_se
passedToOnRetry.Should().BeSameAs(toRaiseAsInner);
}

[Fact]
public void Should_call_onretry_with_handled_exception_nested_in_aggregate_inside_another_aggregate_as_first_exception()
{
Exception passedToOnRetry = null;

var policy = Policy
.HandleInner<DivideByZeroException>()
.Retry(3, (exception, _) => passedToOnRetry = exception);

Exception toRaiseAsInner = new DivideByZeroException();

Exception aggregateException = new AggregateException(
new AggregateException(
new Exception("First: With Inner Exception",
toRaiseAsInner),
new Exception("Second: Without Inner Exception")),
new Exception("Exception"));

policy.RaiseException(aggregateException);

passedToOnRetry.Should().BeSameAs(toRaiseAsInner);
}

[Fact]
public void Should_call_onretry_with_handled_exception_nested_in_aggregate_inside_another_aggregate_as_second_exception()
{
Exception passedToOnRetry = null;

var policy = Policy
.HandleInner<DivideByZeroException>()
.Retry(3, (exception, _) => passedToOnRetry = exception);

Exception toRaiseAsInner = new DivideByZeroException();

Exception aggregateException = new AggregateException(
new Exception("Exception"),
new AggregateException(
new Exception("First: Without Inner Exception"),
new Exception("Second: With Inner Exception",
toRaiseAsInner)));

policy.RaiseException(aggregateException);

passedToOnRetry.Should().BeSameAs(toRaiseAsInner);
}

[Fact]
public void Should_not_call_onretry_when_no_retries_are_performed()
{
Expand Down

0 comments on commit 118236e

Please sign in to comment.