From 0719338fac06d05d659b3742852345b33112b318 Mon Sep 17 00:00:00 2001
From: gintsk <3540004+gintsk@users.noreply.github.com>
Date: Sat, 27 Jan 2024 19:02:40 +0200
Subject: [PATCH] Fix SA1602/S6608/S4144 warnings (#1936)
- Remove redundant SA1602.
- Fix S6608.
- Fix S4144.
---
test/Polly.Core.Tests/Polly.Core.Tests.csproj | 2 +-
.../Retry/RetryResilienceStrategyTests.cs | 4 +--
.../Polly.Core.Tests/Utils/ObjectPoolTests.cs | 2 +-
.../Polly.Extensions.Tests.csproj | 2 +-
.../ReloadableResiliencePipelineTests.cs | 4 +--
.../Fallback/FallbackTResultAsyncSpecs.cs | 28 -------------------
test/Polly.Specs/PolicyTResultAsyncSpecs.cs | 12 --------
test/Polly.Specs/Polly.Specs.csproj | 4 +--
test/Polly.TestUtils/Polly.TestUtils.csproj | 2 +-
9 files changed, 10 insertions(+), 50 deletions(-)
diff --git a/test/Polly.Core.Tests/Polly.Core.Tests.csproj b/test/Polly.Core.Tests/Polly.Core.Tests.csproj
index 3a56ef265ad..b982b9b6add 100644
--- a/test/Polly.Core.Tests/Polly.Core.Tests.csproj
+++ b/test/Polly.Core.Tests/Polly.Core.Tests.csproj
@@ -5,7 +5,7 @@
Test
enable
100
- $(NoWarn);SA1600;SA1204;SA1602;S6608
+ $(NoWarn);SA1600;SA1204
[Polly.Core]*
true
diff --git a/test/Polly.Core.Tests/Retry/RetryResilienceStrategyTests.cs b/test/Polly.Core.Tests/Retry/RetryResilienceStrategyTests.cs
index 0a94d396896..6e5a4717398 100644
--- a/test/Polly.Core.Tests/Retry/RetryResilienceStrategyTests.cs
+++ b/test/Polly.Core.Tests/Retry/RetryResilienceStrategyTests.cs
@@ -89,9 +89,9 @@ public void ExecuteAsync_MultipleRetries_EnsureDiscardedResultsDisposed()
// assert
result.IsDisposed.Should().BeFalse();
results.Count.Should().Be(_options.MaxRetryAttempts + 1);
- results.Last().IsDisposed.Should().BeFalse();
+ results[results.Count - 1].IsDisposed.Should().BeFalse();
- results.Remove(results.Last());
+ results.Remove(results[results.Count - 1]);
results.Should().AllSatisfy(r => r.IsDisposed.Should().BeTrue());
}
diff --git a/test/Polly.Core.Tests/Utils/ObjectPoolTests.cs b/test/Polly.Core.Tests/Utils/ObjectPoolTests.cs
index b9383df28c9..eb5d46e195b 100644
--- a/test/Polly.Core.Tests/Utils/ObjectPoolTests.cs
+++ b/test/Polly.Core.Tests/Utils/ObjectPoolTests.cs
@@ -52,7 +52,7 @@ public void MaxCapacityOverflow_Respected()
var items2 = GetStoreReturn(pool, count);
// Assert
- items1.Last().Should().NotBeSameAs(items2.Last());
+ items1[items1.Count - 1].Should().NotBeSameAs(items2[items2.Count - 1]);
}
[Fact]
diff --git a/test/Polly.Extensions.Tests/Polly.Extensions.Tests.csproj b/test/Polly.Extensions.Tests/Polly.Extensions.Tests.csproj
index b33283d0398..c45f7a77232 100644
--- a/test/Polly.Extensions.Tests/Polly.Extensions.Tests.csproj
+++ b/test/Polly.Extensions.Tests/Polly.Extensions.Tests.csproj
@@ -5,7 +5,7 @@
Test
enable
100
- $(NoWarn);SA1600;SA1204;S6608
+ $(NoWarn);SA1600;SA1204
[Polly.Extensions]*
diff --git a/test/Polly.Extensions.Tests/ReloadableResiliencePipelineTests.cs b/test/Polly.Extensions.Tests/ReloadableResiliencePipelineTests.cs
index 6546ee3a2e6..547fc1db61f 100644
--- a/test/Polly.Extensions.Tests/ReloadableResiliencePipelineTests.cs
+++ b/test/Polly.Extensions.Tests/ReloadableResiliencePipelineTests.cs
@@ -74,11 +74,11 @@ public void AddResiliencePipeline_EnsureReloadable(string? name)
resList[i].Received(1).Dispose();
}
- resList.Last().Received(0).Dispose();
+ resList[resList.Count - 1].Received(0).Dispose();
// check disposal of service provider
serviceProvider.Dispose();
- resList.Last().Received(1).Dispose();
+ resList[resList.Count - 1].Received(1).Dispose();
pipeline.Invoking(p => p.Execute(() => { })).Should().Throw();
foreach (var ev in fakeListener.Events)
diff --git a/test/Polly.Specs/Fallback/FallbackTResultAsyncSpecs.cs b/test/Polly.Specs/Fallback/FallbackTResultAsyncSpecs.cs
index 618d7cd336c..45350dde783 100644
--- a/test/Polly.Specs/Fallback/FallbackTResultAsyncSpecs.cs
+++ b/test/Polly.Specs/Fallback/FallbackTResultAsyncSpecs.cs
@@ -61,20 +61,6 @@ public void Should_throw_when_onFallback_delegate_is_null()
.And.ParamName.Should().Be("onFallbackAsync");
}
- [Fact]
- public void Should_throw_when_onFallback_delegate_is_null_with_action_with_cancellation()
- {
- Func> fallbackAction = _ => Task.FromResult(ResultPrimitive.Substitute);
- Func, Task> onFallbackAsync = null!;
-
- Action policy = () => Policy
- .HandleResult(ResultPrimitive.Fault)
- .FallbackAsync(fallbackAction, onFallbackAsync);
-
- policy.Should().Throw()
- .And.ParamName.Should().Be("onFallbackAsync");
- }
-
[Fact]
public void Should_throw_when_onFallback_delegate_is_null_with_context()
{
@@ -89,20 +75,6 @@ public void Should_throw_when_onFallback_delegate_is_null_with_context()
.And.ParamName.Should().Be("onFallbackAsync");
}
- [Fact]
- public void Should_throw_when_onFallback_delegate_is_null_with_context_with_action_with_cancellation()
- {
- Func> fallbackAction = (_, _) => Task.FromResult(ResultPrimitive.Substitute);
- Func, Context, Task> onFallbackAsync = null!;
-
- Action policy = () => Policy
- .HandleResult(ResultPrimitive.Fault)
- .FallbackAsync(fallbackAction, onFallbackAsync);
-
- policy.Should().Throw()
- .And.ParamName.Should().Be("onFallbackAsync");
- }
-
#endregion
#region Policy operation tests
diff --git a/test/Polly.Specs/PolicyTResultAsyncSpecs.cs b/test/Polly.Specs/PolicyTResultAsyncSpecs.cs
index 5b88db91271..18957deb20f 100644
--- a/test/Polly.Specs/PolicyTResultAsyncSpecs.cs
+++ b/test/Polly.Specs/PolicyTResultAsyncSpecs.cs
@@ -110,18 +110,6 @@ public async Task Executing_the_policy_function_should_throw_when_context_is_nul
ex.And.ParamName.Should().Be("context");
}
- [Fact]
- public async Task Execute_and_capturing_the_policy_function_should_throw_when_context_data_is_null()
- {
- var policy = Policy
- .HandleResult(ResultPrimitive.Fault)
- .RetryAsync((_, _, _) => { });
-
- var ex = await policy.Awaiting(p => p.ExecuteAndCaptureAsync(_ => Task.FromResult(ResultPrimitive.Good), null!))
- .Should().ThrowAsync();
- ex.And.ParamName.Should().Be("context");
- }
-
[Fact]
public async Task Executing_the_policy_function_should_pass_context_to_executed_delegate()
{
diff --git a/test/Polly.Specs/Polly.Specs.csproj b/test/Polly.Specs/Polly.Specs.csproj
index c69d15f0651..737cab0336b 100644
--- a/test/Polly.Specs/Polly.Specs.csproj
+++ b/test/Polly.Specs/Polly.Specs.csproj
@@ -8,8 +8,8 @@
75,60,70
[Polly]*
true
- $(NoWarn);S103;S104;CA2000;IDE0011;SA1600;SA1204;SA1602;CA2008;CA1806;CA2201;
- $(NoWarn);S3878;CA1030;S4144;S3717;SA1129;SA1407;S1402;SA1649;SA1402;S4056;CA1031
+ $(NoWarn);S103;S104;CA2000;IDE0011;SA1600;SA1204;CA2008;CA1806;CA2201;
+ $(NoWarn);S3878;CA1030;S3717;SA1129;SA1407;S1402;SA1649;SA1402;S4056;CA1031
$(NoWarn);S2184;
diff --git a/test/Polly.TestUtils/Polly.TestUtils.csproj b/test/Polly.TestUtils/Polly.TestUtils.csproj
index 66f550f0165..28fed5ec0e8 100644
--- a/test/Polly.TestUtils/Polly.TestUtils.csproj
+++ b/test/Polly.TestUtils/Polly.TestUtils.csproj
@@ -4,7 +4,7 @@
$(TargetFrameworks);net481
Library
enable
- $(NoWarn);SA1600;SA1204;SA1602;CA1062
+ $(NoWarn);SA1600;SA1204;CA1062
false
false
false