Skip to content

Commit 0c9bef1

Browse files
authored
Fix IDE0011 warning (#2171)
Fix IDE0011 warnings and remove rule suppression.
1 parent 9ca23fe commit 0c9bef1

21 files changed

+131
-29
lines changed

test/Polly.Specs/Bulkhead/BulkheadSpecsBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ protected BulkheadSpecsBase(ITestOutputHelper testOutputHelper)
7878
public void Should_control_executions_per_specification(int maxParallelization, int maxQueuingActions, int totalActions, bool cancelQueuing, bool cancelExecuting, string scenario)
7979
{
8080
if (totalActions < 0)
81+
{
8182
throw new ArgumentOutOfRangeException(nameof(totalActions));
83+
}
8284

8385
MaxParallelization = maxParallelization;
8486
MaxQueuingActions = maxQueuingActions;

test/Polly.Specs/CircuitBreaker/AdvancedCircuitBreakerAsyncSpecs.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,9 +1602,15 @@ await breaker.ExecuteAsync(async () =>
16021602
permitFirstExecutionEnd.Set();
16031603
Task.WaitAll(new[] { firstExecution, secondExecution }, testTimeoutToExposeDeadlocks).Should().BeTrue();
16041604
if (firstExecution.IsFaulted)
1605+
{
16051606
throw firstExecution!.Exception!;
1607+
}
1608+
16061609
if (secondExecution.IsFaulted)
1610+
{
16071611
throw secondExecution!.Exception!;
1612+
}
1613+
16081614
firstExecution.Status.Should().Be(TaskStatus.RanToCompletion);
16091615
secondExecution.Status.Should().Be(TaskStatus.RanToCompletion);
16101616

@@ -1711,9 +1717,15 @@ await breaker.ExecuteAsync(async () =>
17111717
permitFirstExecutionEnd.Set();
17121718
Task.WaitAll(new[] { firstExecution, secondExecution }, testTimeoutToExposeDeadlocks).Should().BeTrue();
17131719
if (firstExecution.IsFaulted)
1720+
{
17141721
throw firstExecution!.Exception!;
1722+
}
1723+
17151724
if (secondExecution.IsFaulted)
1725+
{
17161726
throw secondExecution!.Exception!;
1727+
}
1728+
17171729
firstExecution.Status.Should().Be(TaskStatus.RanToCompletion);
17181730
secondExecution.Status.Should().Be(TaskStatus.RanToCompletion);
17191731

@@ -2030,7 +2042,10 @@ await breaker.Awaiting(x => x.RaiseExceptionAsync<DivideByZeroException>())
20302042
// Graceful cleanup: allow executions time to end naturally; timeout if any deadlocks; expose any execution faults. This validates the test ran as expected (and background delegates are complete) before we assert on outcomes.
20312043
longRunningExecution.Wait(testTimeoutToExposeDeadlocks).Should().BeTrue();
20322044
if (longRunningExecution.IsFaulted)
2045+
{
20332046
throw longRunningExecution!.Exception!;
2047+
}
2048+
20342049
longRunningExecution.Status.Should().Be(TaskStatus.RanToCompletion);
20352050

20362051
// onBreak() should still only have been called once.

test/Polly.Specs/CircuitBreaker/AdvancedCircuitBreakerSpecs.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,9 +1605,15 @@ public void Should_only_allow_single_execution_on_first_entering_halfopen_state_
16051605
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
16061606

16071607
if (firstExecution.IsFaulted)
1608+
{
16081609
throw firstExecution!.Exception!;
1610+
}
1611+
16091612
if (secondExecution.IsFaulted)
1613+
{
16101614
throw secondExecution!.Exception!;
1615+
}
1616+
16111617
firstExecution.Status.Should().Be(TaskStatus.RanToCompletion);
16121618
secondExecution.Status.Should().Be(TaskStatus.RanToCompletion);
16131619

@@ -1717,9 +1723,15 @@ public void Should_allow_single_execution_per_break_duration_in_halfopen_state__
17171723
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
17181724

17191725
if (firstExecution.IsFaulted)
1726+
{
17201727
throw firstExecution!.Exception!;
1728+
}
1729+
17211730
if (secondExecution.IsFaulted)
1731+
{
17221732
throw secondExecution!.Exception!;
1733+
}
1734+
17231735
firstExecution.Status.Should().Be(TaskStatus.RanToCompletion);
17241736
secondExecution.Status.Should().Be(TaskStatus.RanToCompletion);
17251737

test/Polly.Specs/CircuitBreaker/CircuitBreakerAsyncSpecs.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,15 @@ await breaker.ExecuteAsync(async () =>
454454
permitFirstExecutionEnd.Set();
455455
Task.WaitAll(new[] { firstExecution, secondExecution }, testTimeoutToExposeDeadlocks).Should().BeTrue();
456456
if (firstExecution.IsFaulted)
457+
{
457458
throw firstExecution!.Exception!;
459+
}
460+
458461
if (secondExecution.IsFaulted)
462+
{
459463
throw secondExecution!.Exception!;
464+
}
465+
460466
firstExecution.Status.Should().Be(TaskStatus.RanToCompletion);
461467
secondExecution.Status.Should().Be(TaskStatus.RanToCompletion);
462468

@@ -557,9 +563,15 @@ await breaker.ExecuteAsync(async () =>
557563
permitFirstExecutionEnd.Set();
558564
Task.WaitAll(new[] { firstExecution, secondExecution }, testTimeoutToExposeDeadlocks).Should().BeTrue();
559565
if (firstExecution.IsFaulted)
566+
{
560567
throw firstExecution!.Exception!;
568+
}
569+
561570
if (secondExecution.IsFaulted)
571+
{
562572
throw secondExecution!.Exception!;
573+
}
574+
563575
firstExecution.Status.Should().Be(TaskStatus.RanToCompletion);
564576
secondExecution.Status.Should().Be(TaskStatus.RanToCompletion);
565577

@@ -822,7 +834,10 @@ await breaker.Awaiting(x => x.RaiseExceptionAsync<DivideByZeroException>())
822834
// Graceful cleanup: allow executions time to end naturally; timeout if any deadlocks; expose any execution faults. This validates the test ran as expected (and background delegates are complete) before we assert on outcomes.
823835
longRunningExecution.Wait(testTimeoutToExposeDeadlocks).Should().BeTrue();
824836
if (longRunningExecution.IsFaulted)
837+
{
825838
throw longRunningExecution!.Exception!;
839+
}
840+
826841
longRunningExecution.Status.Should().Be(TaskStatus.RanToCompletion);
827842

828843
// onBreak() should still only have been called once.

test/Polly.Specs/CircuitBreaker/CircuitBreakerSpecs.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,15 @@ public void Should_only_allow_single_execution_on_first_entering_halfopen_state_
450450
permitFirstExecutionEnd.Set();
451451
Task.WaitAll(new[] { firstExecution, secondExecution }, testTimeoutToExposeDeadlocks).Should().BeTrue();
452452
if (firstExecution.IsFaulted)
453+
{
453454
throw firstExecution!.Exception!;
455+
}
456+
454457
if (secondExecution.IsFaulted)
458+
{
455459
throw secondExecution!.Exception!;
460+
}
461+
456462
firstExecution.Status.Should().Be(TaskStatus.RanToCompletion);
457463
secondExecution.Status.Should().Be(TaskStatus.RanToCompletion);
458464

@@ -551,9 +557,15 @@ public void Should_allow_single_execution_per_break_duration_in_halfopen_state__
551557
permitFirstExecutionEnd.Set();
552558
Task.WaitAll(new[] { firstExecution, secondExecution }, testTimeoutToExposeDeadlocks).Should().BeTrue();
553559
if (firstExecution.IsFaulted)
560+
{
554561
throw firstExecution!.Exception!;
562+
}
563+
555564
if (secondExecution.IsFaulted)
565+
{
556566
throw secondExecution!.Exception!;
567+
}
568+
557569
firstExecution.Status.Should().Be(TaskStatus.RanToCompletion);
558570
secondExecution.Status.Should().Be(TaskStatus.RanToCompletion);
559571

@@ -813,7 +825,10 @@ public void Should_call_onbreak_when_breaking_circuit_first_time_but_not_for_sub
813825
// Graceful cleanup: allow executions time to end naturally; timeout if any deadlocks; expose any execution faults. This validates the test ran as expected (and background delegates are complete) before we assert on outcomes.
814826
longRunningExecution.Wait(testTimeoutToExposeDeadlocks).Should().BeTrue();
815827
if (longRunningExecution.IsFaulted)
828+
{
816829
throw longRunningExecution!.Exception!;
830+
}
831+
817832
longRunningExecution.Status.Should().Be(TaskStatus.RanToCompletion);
818833

819834
// onBreak() should still only have been called once.

test/Polly.Specs/CircuitBreaker/CircuitBreakerTResultAsyncSpecs.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,15 @@ await breaker.ExecuteAsync(async () =>
524524
#pragma warning restore xUnit1031
525525

526526
if (firstExecution.IsFaulted)
527+
{
527528
throw firstExecution!.Exception!;
529+
}
530+
528531
if (secondExecution.IsFaulted)
532+
{
529533
throw secondExecution!.Exception!;
534+
}
535+
530536
firstExecution.Status.Should().Be(TaskStatus.RanToCompletion);
531537
secondExecution.Status.Should().Be(TaskStatus.RanToCompletion);
532538

@@ -635,9 +641,15 @@ await breaker.ExecuteAsync(async () =>
635641
#pragma warning restore xUnit1031
636642

637643
if (firstExecution.IsFaulted)
644+
{
638645
throw firstExecution!.Exception!;
646+
}
647+
639648
if (secondExecution.IsFaulted)
649+
{
640650
throw secondExecution!.Exception!;
651+
}
652+
641653
firstExecution.Status.Should().Be(TaskStatus.RanToCompletion);
642654
secondExecution.Status.Should().Be(TaskStatus.RanToCompletion);
643655

@@ -904,7 +916,10 @@ public async Task Should_call_onbreak_when_breaking_circuit_first_time_but_not_f
904916
#pragma warning restore xUnit1031
905917

906918
if (longRunningExecution.IsFaulted)
919+
{
907920
throw longRunningExecution!.Exception!;
921+
}
922+
908923
longRunningExecution.Status.Should().Be(TaskStatus.RanToCompletion);
909924

910925
// onBreak() should still only have been called once.

test/Polly.Specs/CircuitBreaker/CircuitBreakerTResultSpecs.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,15 @@ public void Should_only_allow_single_execution_on_first_entering_halfopen_state_
517517
permitFirstExecutionEnd.Set();
518518
Task.WaitAll(new[] { firstExecution, secondExecution }, testTimeoutToExposeDeadlocks).Should().BeTrue();
519519
if (firstExecution.IsFaulted)
520+
{
520521
throw firstExecution!.Exception!;
522+
}
523+
521524
if (secondExecution.IsFaulted)
525+
{
522526
throw secondExecution!.Exception!;
527+
}
528+
523529
firstExecution.Status.Should().Be(TaskStatus.RanToCompletion);
524530
secondExecution.Status.Should().Be(TaskStatus.RanToCompletion);
525531

@@ -621,9 +627,15 @@ public void Should_allow_single_execution_per_break_duration_in_halfopen_state__
621627
permitFirstExecutionEnd.Set();
622628
Task.WaitAll(new[] { firstExecution, secondExecution }, testTimeoutToExposeDeadlocks).Should().BeTrue();
623629
if (firstExecution.IsFaulted)
630+
{
624631
throw firstExecution!.Exception!;
632+
}
633+
625634
if (secondExecution.IsFaulted)
635+
{
626636
throw secondExecution!.Exception!;
637+
}
638+
627639
firstExecution.Status.Should().Be(TaskStatus.RanToCompletion);
628640
secondExecution.Status.Should().Be(TaskStatus.RanToCompletion);
629641

@@ -885,7 +897,10 @@ public void Should_call_onbreak_when_breaking_circuit_first_time_but_not_for_sub
885897
// Graceful cleanup: allow executions time to end naturally; timeout if any deadlocks; expose any execution faults. This validates the test ran as expected (and background delegates are complete) before we assert on outcomes.
886898
longRunningExecution.Wait(testTimeoutToExposeDeadlocks).Should().BeTrue();
887899
if (longRunningExecution.IsFaulted)
900+
{
888901
throw longRunningExecution!.Exception!;
902+
}
903+
889904
longRunningExecution.Status.Should().Be(TaskStatus.RanToCompletion);
890905

891906
// onBreak() should still only have been called once.

test/Polly.Specs/Helpers/Bulkhead/AssertionFailure.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ public class AssertionFailure
55
public AssertionFailure(int expected, int actual, string measure)
66
{
77
if (string.IsNullOrWhiteSpace(measure))
8+
{
89
throw new ArgumentNullException(nameof(measure));
10+
}
911

1012
Expected = expected;
1113
Actual = actual;

test/Polly.Specs/Helpers/Caching/StubErroringCacheProvider.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@ public StubErroringCacheProvider(Exception? getException, Exception? putExceptio
1616
public (bool, object?) TryGet(string key)
1717
{
1818
if (_getException != null)
19+
{
1920
throw _getException;
21+
}
22+
2023
return _innerProvider.TryGet(key);
2124
}
2225

2326
public void Put(string key, object? value, Ttl ttl)
2427
{
2528
if (_putException != null)
29+
{
2630
throw _putException;
31+
}
32+
2733
_innerProvider.Put(key, value, ttl);
2834
}
2935

test/Polly.Specs/Helpers/Custom/AddBehaviourIfHandle/AddBehaviourIfHandleSyntax.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@ internal static class AddBehaviourIfHandleSyntax
55
internal static AddBehaviourIfHandlePolicy WithBehaviour(this PolicyBuilder policyBuilder, Action<Exception> behaviourIfHandle)
66
{
77
if (behaviourIfHandle == null)
8+
{
89
throw new ArgumentNullException(nameof(behaviourIfHandle));
10+
}
911

1012
return new AddBehaviourIfHandlePolicy(behaviourIfHandle, policyBuilder);
1113
}
1214

1315
internal static AddBehaviourIfHandlePolicy<TResult> WithBehaviour<TResult>(this PolicyBuilder<TResult> policyBuilder, Action<DelegateResult<TResult>> behaviourIfHandle)
1416
{
1517
if (behaviourIfHandle == null)
18+
{
1619
throw new ArgumentNullException(nameof(behaviourIfHandle));
20+
}
1721

1822
return new AddBehaviourIfHandlePolicy<TResult>(behaviourIfHandle, policyBuilder);
1923
}

0 commit comments

Comments
 (0)