Skip to content

Commit

Permalink
Update FluentAssertions (#869)
Browse files Browse the repository at this point in the history
* FluentAssertions" Version="5.10.3

* Update NoOpTResultAsyncSpecs.cs

* Update AdvancedCircuitBreakerAsyncSpecs.cs
  • Loading branch information
SimonCropp committed Jun 11, 2021
1 parent 493bb07 commit ab27d3c
Show file tree
Hide file tree
Showing 22 changed files with 649 additions and 633 deletions.
2 changes: 1 addition & 1 deletion src/Polly.Specs/Bulkhead/BulkheadAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void Should_call_onBulkheadRejected_with_passed_context()

Within(CohesionTimeLimit, () => Expect(0, () => bulkhead.BulkheadAvailableCount, nameof(bulkhead.BulkheadAvailableCount)));

bulkhead.Awaiting(async b => await b.ExecuteAsync(ctx => TaskHelper.EmptyTask, contextPassedToExecute)).Should().Throw<BulkheadRejectedException>();
bulkhead.Awaiting(b => b.ExecuteAsync(ctx => TaskHelper.EmptyTask, contextPassedToExecute)).Should().Throw<BulkheadRejectedException>();

cancellationSource.Cancel();
tcs.SetCanceled();
Expand Down
2 changes: 1 addition & 1 deletion src/Polly.Specs/Bulkhead/BulkheadTResultAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void Should_call_onBulkheadRejected_with_passed_context()

Within(CohesionTimeLimit, () => Expect(0, () => bulkhead.BulkheadAvailableCount, nameof(bulkhead.BulkheadAvailableCount)));

bulkhead.Awaiting(async b => await b.ExecuteAsync(ctx => Task.FromResult(1), contextPassedToExecute)).Should().Throw<BulkheadRejectedException>();
bulkhead.Awaiting(b => b.ExecuteAsync(ctx => Task.FromResult(1), contextPassedToExecute)).Should().Throw<BulkheadRejectedException>();

cancellationSource.Cancel();
tcs.SetCanceled();
Expand Down
506 changes: 254 additions & 252 deletions src/Polly.Specs/CircuitBreaker/AdvancedCircuitBreakerAsyncSpecs.cs

Large diffs are not rendered by default.

192 changes: 97 additions & 95 deletions src/Polly.Specs/CircuitBreaker/CircuitBreakerAsyncSpecs.cs

Large diffs are not rendered by default.

77 changes: 38 additions & 39 deletions src/Polly.Specs/CircuitBreaker/CircuitBreakerTResultAsyncSpecs.cs

Large diffs are not rendered by default.

52 changes: 25 additions & 27 deletions src/Polly.Specs/Fallback/FallbackAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void Should_not_execute_fallback_when_executed_delegate_throws_exception_
.Handle<DivideByZeroException>()
.FallbackAsync(fallbackActionAsync);

fallbackPolicy.Awaiting(async x => await x.RaiseExceptionAsync<ArgumentNullException>()).Should().Throw<ArgumentNullException>();
fallbackPolicy.Awaiting(x => x.RaiseExceptionAsync<ArgumentNullException>()).Should().Throw<ArgumentNullException>();

fallbackActionExecuted.Should().BeFalse();
}
Expand All @@ -128,7 +128,7 @@ public void Should_execute_fallback_when_executed_delegate_throws_exception_hand
.Handle<DivideByZeroException>()
.FallbackAsync(fallbackActionAsync);

fallbackPolicy.Awaiting(async x => await x.RaiseExceptionAsync<DivideByZeroException>()).Should().NotThrow();
fallbackPolicy.Awaiting(x => x.RaiseExceptionAsync<DivideByZeroException>()).Should().NotThrow();

fallbackActionExecuted.Should().BeTrue();
}
Expand All @@ -145,7 +145,7 @@ public void Should_execute_fallback_when_executed_delegate_throws_one_of_excepti
.Or<ArgumentException>()
.FallbackAsync(fallbackActionAsync);

fallbackPolicy.Awaiting(async x => await x.RaiseExceptionAsync<ArgumentException>()).Should().NotThrow();
fallbackPolicy.Awaiting(x => x.RaiseExceptionAsync<ArgumentException>()).Should().NotThrow();

fallbackActionExecuted.Should().BeTrue();
}
Expand All @@ -162,7 +162,7 @@ public void Should_not_execute_fallback_when_executed_delegate_throws_exception_
.Or<NullReferenceException>()
.FallbackAsync(fallbackActionAsync);

fallbackPolicy.Awaiting(async x => await x.RaiseExceptionAsync<ArgumentNullException>()).Should().Throw<ArgumentNullException>();
fallbackPolicy.Awaiting(x => x.RaiseExceptionAsync<ArgumentNullException>()).Should().Throw<ArgumentNullException>();

fallbackActionExecuted.Should().BeFalse();
}
Expand All @@ -177,7 +177,7 @@ public void Should_not_execute_fallback_when_exception_thrown_does_not_match_han
.Handle<DivideByZeroException>(e => false)
.FallbackAsync(fallbackActionAsync);

fallbackPolicy.Awaiting(async x => await x.RaiseExceptionAsync<DivideByZeroException>()).Should().Throw<DivideByZeroException>();
fallbackPolicy.Awaiting(x => x.RaiseExceptionAsync<DivideByZeroException>()).Should().Throw<DivideByZeroException>();

fallbackActionExecuted.Should().BeFalse();
}
Expand All @@ -193,7 +193,7 @@ public void Should_not_execute_fallback_when_exception_thrown_does_not_match_any
.Or<ArgumentNullException>(e => false)
.FallbackAsync(fallbackActionAsync);

fallbackPolicy.Awaiting(async x => await x.RaiseExceptionAsync<DivideByZeroException>()).Should().Throw<DivideByZeroException>();
fallbackPolicy.Awaiting(x => x.RaiseExceptionAsync<DivideByZeroException>()).Should().Throw<DivideByZeroException>();

fallbackActionExecuted.Should().BeFalse();
}
Expand All @@ -208,7 +208,7 @@ public void Should_execute_fallback_when_exception_thrown_matches_handling_predi
.Handle<DivideByZeroException>(e => true)
.FallbackAsync(fallbackActionAsync);

fallbackPolicy.Awaiting(async x => await x.RaiseExceptionAsync<DivideByZeroException>()).Should().NotThrow();
fallbackPolicy.Awaiting(x => x.RaiseExceptionAsync<DivideByZeroException>()).Should().NotThrow();

fallbackActionExecuted.Should().BeTrue();
}
Expand All @@ -225,7 +225,7 @@ public void Should_execute_fallback_when_exception_thrown_matches_one_of_handlin
.Or<ArgumentNullException>()
.FallbackAsync(fallbackActionAsync);

fallbackPolicy.Awaiting(async x => await x.RaiseExceptionAsync<DivideByZeroException>()).Should().NotThrow();
fallbackPolicy.Awaiting(x => x.RaiseExceptionAsync<DivideByZeroException>()).Should().NotThrow();

fallbackActionExecuted.Should().BeTrue();
}
Expand All @@ -244,7 +244,7 @@ public void Should_not_handle_exception_thrown_by_fallback_delegate_even_if_is_e
.Handle<DivideByZeroException>()
.FallbackAsync(fallbackActionAsync);

fallbackPolicy.Awaiting(async x => await x.RaiseExceptionAsync<DivideByZeroException>((e, i) => e.HelpLink = "FromExecuteDelegate"))
fallbackPolicy.Awaiting(x => x.RaiseExceptionAsync<DivideByZeroException>((e, i) => e.HelpLink = "FromExecuteDelegate"))
.Should().Throw<DivideByZeroException>().And.HelpLink.Should().Be("FromFallbackAction");

fallbackActionExecuted.Should().BeTrue();
Expand Down Expand Up @@ -319,7 +319,7 @@ public void Should_call_onFallback_with_the_passed_context()
.Handle<ArgumentNullException>()
.FallbackAsync(fallbackActionAsync, onFallbackAsync);

fallbackPolicy.Awaiting(async p => await p.ExecuteAsync(ctx => throw new ArgumentNullException(),
fallbackPolicy.Awaiting(p => p.ExecuteAsync(ctx => throw new ArgumentNullException(),
new { key1 = "value1", key2 = "value2" }.AsDictionary()))
.Should().NotThrow();

Expand All @@ -341,7 +341,7 @@ public void Should_call_onFallback_with_the_passed_context_when_execute_and_capt
.Handle<ArgumentNullException>()
.FallbackAsync(fallbackActionAsync, onFallbackAsync);

fallbackPolicy.Awaiting(async p => await p.ExecuteAndCaptureAsync(ctx => throw new ArgumentNullException(),
fallbackPolicy.Awaiting(p => p.ExecuteAndCaptureAsync(ctx => throw new ArgumentNullException(),
new { key1 = "value1", key2 = "value2" }.AsDictionary()))
.Should().NotThrow();

Expand All @@ -364,12 +364,10 @@ public void Should_call_onFallback_with_independent_context_for_independent_call
.Or<DivideByZeroException>()
.FallbackAsync(fallbackActionAsync, onFallbackAsync);

fallbackPolicy.Awaiting(async
p => await p.ExecuteAsync(ctx => throw new ArgumentNullException(), new { key = "value1" }.AsDictionary()))
fallbackPolicy.Awaiting(p => p.ExecuteAsync(ctx => throw new ArgumentNullException(), new { key = "value1" }.AsDictionary()))
.Should().NotThrow();

fallbackPolicy.Awaiting(async
p => await p.ExecuteAsync(ctx => throw new DivideByZeroException(), new { key = "value2" }.AsDictionary()))
fallbackPolicy.Awaiting(p => p.ExecuteAsync(ctx => throw new DivideByZeroException(), new { key = "value2" }.AsDictionary()))
.Should().NotThrow();

contextData.Count.Should().Be(2);
Expand Down Expand Up @@ -413,7 +411,7 @@ public void Should_call_fallbackAction_with_the_passed_context()
.Handle<ArgumentNullException>()
.FallbackAsync(fallbackActionAsync, onFallbackAsync);

fallbackPolicy.Awaiting(async p => await p.ExecuteAsync(ctx => throw new ArgumentNullException(),
fallbackPolicy.Awaiting(p => p.ExecuteAsync(ctx => throw new ArgumentNullException(),
new { key1 = "value1", key2 = "value2" }.AsDictionary()))
.Should().NotThrow();

Expand All @@ -435,7 +433,7 @@ public void Should_call_fallbackAction_with_the_passed_context_when_execute_and_
.Handle<ArgumentNullException>()
.FallbackAsync(fallbackActionAsync, onFallbackAsync);

fallbackPolicy.Awaiting(async p => await p.ExecuteAndCaptureAsync(ctx => throw new ArgumentNullException(),
fallbackPolicy.Awaiting(p => p.ExecuteAndCaptureAsync(ctx => throw new ArgumentNullException(),
new { key1 = "value1", key2 = "value2" }.AsDictionary()))
.Should().NotThrow();

Expand Down Expand Up @@ -502,7 +500,7 @@ public void Should_call_fallbackAction_with_the_exception_when_execute_and_captu
.Handle<ArgumentNullException>()
.FallbackAsync(fallbackFunc, onFallback);

fallbackPolicy.Awaiting(async p => await p.ExecuteAndCaptureAsync(() => throw new ArgumentNullException()))
fallbackPolicy.Awaiting(p => p.ExecuteAndCaptureAsync(() => throw new ArgumentNullException()))
.Should().NotThrow();

fallbackException.Should().NotBeNull()
Expand Down Expand Up @@ -564,7 +562,7 @@ public void Should_not_call_fallbackAction_with_the_exception_if_exception_unhan
.Handle<DivideByZeroException>()
.FallbackAsync(fallbackFunc, onFallback);

fallbackPolicy.Awaiting(async p => await p.ExecuteAsync(() => throw new ArgumentNullException()))
fallbackPolicy.Awaiting(p => p.ExecuteAsync(() => throw new ArgumentNullException()))
.Should().Throw<ArgumentNullException>();

fallbackException.Should().BeNull();
Expand Down Expand Up @@ -596,7 +594,7 @@ public void Should_execute_action_when_non_faulting_and_cancellationToken_not_ca
AttemptDuringWhichToCancel = null,
};

policy.Awaiting(async x => await x.RaiseExceptionAndOrCancellationAsync<DivideByZeroException>(scenario, cancellationTokenSource, onExecute))
policy.Awaiting(x => x.RaiseExceptionAndOrCancellationAsync<DivideByZeroException>(scenario, cancellationTokenSource, onExecute))
.Should().NotThrow();
attemptsInvoked.Should().Be(1);

Expand Down Expand Up @@ -625,7 +623,7 @@ public void Should_execute_fallback_when_faulting_and_cancellationToken_not_canc
AttemptDuringWhichToCancel = null,
};

policy.Awaiting(async x => await x.RaiseExceptionAndOrCancellationAsync<DivideByZeroException>(scenario, cancellationTokenSource, onExecute))
policy.Awaiting(x => x.RaiseExceptionAndOrCancellationAsync<DivideByZeroException>(scenario, cancellationTokenSource, onExecute))
.Should().NotThrow();
attemptsInvoked.Should().Be(1);

Expand Down Expand Up @@ -656,7 +654,7 @@ public void Should_not_execute_action_when_cancellationToken_cancelled_before_ex

cancellationTokenSource.Cancel();

policy.Awaiting(async x => await x.RaiseExceptionAndOrCancellationAsync<DivideByZeroException>(scenario, cancellationTokenSource, onExecute))
policy.Awaiting(x => x.RaiseExceptionAndOrCancellationAsync<DivideByZeroException>(scenario, cancellationTokenSource, onExecute))
.Should().Throw<OperationCanceledException>()
.And.CancellationToken.Should().Be(cancellationToken);
attemptsInvoked.Should().Be(0);
Expand Down Expand Up @@ -688,7 +686,7 @@ public void Should_report_cancellation_and_not_execute_fallback_during_otherwise
ActionObservesCancellation = true
};

policy.Awaiting(async x => await x.RaiseExceptionAndOrCancellationAsync<DivideByZeroException>(scenario, cancellationTokenSource, onExecute))
policy.Awaiting(x => x.RaiseExceptionAndOrCancellationAsync<DivideByZeroException>(scenario, cancellationTokenSource, onExecute))
.Should().Throw<OperationCanceledException>()
.And.CancellationToken.Should().Be(cancellationToken);
attemptsInvoked.Should().Be(1);
Expand Down Expand Up @@ -720,7 +718,7 @@ public void Should_handle_cancellation_and_execute_fallback_during_otherwise_non
ActionObservesCancellation = true
};

policy.Awaiting(async x => await x.RaiseExceptionAndOrCancellationAsync<DivideByZeroException>(scenario, cancellationTokenSource, onExecute))
policy.Awaiting(x => x.RaiseExceptionAndOrCancellationAsync<DivideByZeroException>(scenario, cancellationTokenSource, onExecute))
.Should().NotThrow();
attemptsInvoked.Should().Be(1);

Expand Down Expand Up @@ -751,7 +749,7 @@ public void Should_not_report_cancellation_and_not_execute_fallback_if_non_fault
ActionObservesCancellation = false
};

policy.Awaiting(async x => await x.RaiseExceptionAndOrCancellationAsync<DivideByZeroException>(scenario, cancellationTokenSource, onExecute))
policy.Awaiting(x => x.RaiseExceptionAndOrCancellationAsync<DivideByZeroException>(scenario, cancellationTokenSource, onExecute))
.Should().NotThrow();
attemptsInvoked.Should().Be(1);

Expand Down Expand Up @@ -783,7 +781,7 @@ public void Should_report_unhandled_fault_and_not_execute_fallback_if_action_exe
ActionObservesCancellation = false
};

policy.Awaiting(async x => await x.RaiseExceptionAndOrCancellationAsync<NullReferenceException>(scenario, cancellationTokenSource, onExecute))
policy.Awaiting(x => x.RaiseExceptionAndOrCancellationAsync<NullReferenceException>(scenario, cancellationTokenSource, onExecute))
.Should().Throw<NullReferenceException>();
attemptsInvoked.Should().Be(1);

Expand Down Expand Up @@ -815,7 +813,7 @@ public void Should_handle_handled_fault_and_execute_fallback_following_faulting_
ActionObservesCancellation = false
};

policy.Awaiting(async x => await x.RaiseExceptionAndOrCancellationAsync<DivideByZeroException>(scenario, cancellationTokenSource, onExecute))
policy.Awaiting(x => x.RaiseExceptionAndOrCancellationAsync<DivideByZeroException>(scenario, cancellationTokenSource, onExecute))
.Should().NotThrow();
attemptsInvoked.Should().Be(1);

Expand Down
2 changes: 1 addition & 1 deletion src/Polly.Specs/Fallback/FallbackTResultAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ public void Should_call_fallbackAction_with_the_passed_context_when_execute_and_
.HandleResult(ResultPrimitive.Fault)
.FallbackAsync(fallbackActionAsync, onFallbackAsync);

fallbackPolicy.Awaiting(async p => await p.ExecuteAndCaptureAsync(ctx => Task.FromResult(ResultPrimitive.Fault),
fallbackPolicy.Awaiting(p => p.ExecuteAndCaptureAsync(ctx => Task.FromResult(ResultPrimitive.Fault),
new { key1 = "value1", key2 = "value2" }.AsDictionary()))
.Should().NotThrow();

Expand Down
4 changes: 2 additions & 2 deletions src/Polly.Specs/NoOp/NoOpAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void Should_execute_user_delegate()
var policy = Policy.NoOpAsync();
bool executed = false;

policy.Awaiting(async p => await p.ExecuteAsync(() => { executed = true; return TaskHelper.EmptyTask; }))
policy.Awaiting(p => p.ExecuteAsync(() => { executed = true; return TaskHelper.EmptyTask; }))
.Should().NotThrow();

executed.Should().BeTrue();
Expand All @@ -30,7 +30,7 @@ public void Should_execute_user_delegate_without_adding_extra_cancellation_behav
{
cts.Cancel();

policy.Awaiting(async p => await p.ExecuteAsync(
policy.Awaiting(p => p.ExecuteAsync(
ct => { executed = true; return TaskHelper.EmptyTask; }, cts.Token))
.Should().NotThrow();
}
Expand Down
10 changes: 7 additions & 3 deletions src/Polly.Specs/NoOp/NoOpTResultAsyncSpecs.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Threading;
using System;
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
using Polly.NoOp;
using Xunit;

namespace Polly.Specs.NoOp
Expand All @@ -13,7 +15,8 @@ public void Should_execute_user_delegate()
var policy = Policy.NoOpAsync<int?>();
int? result = null;

policy.Awaiting(async p => result = await p.ExecuteAsync(() => Task.FromResult((int?)10)))
Func<AsyncNoOpPolicy<int?>, Task> action = async p => result = await p.ExecuteAsync(() => Task.FromResult((int?)10));
policy.Awaiting(action)
.Should().NotThrow();

result.HasValue.Should().BeTrue();
Expand All @@ -30,7 +33,8 @@ public void Should_execute_user_delegate_without_adding_extra_cancellation_behav
{
cts.Cancel();

policy.Awaiting(async p => result = await p.ExecuteAsync(ct => Task.FromResult((int?)10), cts.Token))
Func<AsyncNoOpPolicy<int?>, Task> action = async p => result = await p.ExecuteAsync(ct => Task.FromResult((int?)10), cts.Token);
policy.Awaiting(action)
.Should().NotThrow();
}

Expand Down
Loading

0 comments on commit ab27d3c

Please sign in to comment.