Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SA1602/S6608/S4144 warnings #1936

Merged
merged 3 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/Polly.Core.Tests/Polly.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ProjectType>Test</ProjectType>
<Nullable>enable</Nullable>
<Threshold>100</Threshold>
<NoWarn>$(NoWarn);SA1600;SA1204;SA1602;S6608</NoWarn>
<NoWarn>$(NoWarn);SA1600;SA1204</NoWarn>
<Include>[Polly.Core]*</Include>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions test/Polly.Core.Tests/Retry/RetryResilienceStrategyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
martincostello marked this conversation as resolved.
Show resolved Hide resolved
results.Should().AllSatisfy(r => r.IsDisposed.Should().BeTrue());
}

Expand Down
2 changes: 1 addition & 1 deletion test/Polly.Core.Tests/Utils/ObjectPoolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion test/Polly.Extensions.Tests/Polly.Extensions.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ProjectType>Test</ProjectType>
<Nullable>enable</Nullable>
<Threshold>100</Threshold>
<NoWarn>$(NoWarn);SA1600;SA1204;S6608</NoWarn>
<NoWarn>$(NoWarn);SA1600;SA1204</NoWarn>
<Include>[Polly.Extensions]*</Include>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ObjectDisposedException>();

foreach (var ev in fakeListener.Events)
Expand Down
28 changes: 0 additions & 28 deletions test/Polly.Specs/Fallback/FallbackTResultAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CancellationToken, Task<ResultPrimitive>> fallbackAction = _ => Task.FromResult(ResultPrimitive.Substitute);
Func<DelegateResult<ResultPrimitive>, Task> onFallbackAsync = null!;

Action policy = () => Policy
.HandleResult(ResultPrimitive.Fault)
.FallbackAsync(fallbackAction, onFallbackAsync);

policy.Should().Throw<ArgumentNullException>()
.And.ParamName.Should().Be("onFallbackAsync");
}

[Fact]
public void Should_throw_when_onFallback_delegate_is_null_with_context()
{
Expand All @@ -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<Context, CancellationToken, Task<ResultPrimitive>> fallbackAction = (_, _) => Task.FromResult(ResultPrimitive.Substitute);
Func<DelegateResult<ResultPrimitive>, Context, Task> onFallbackAsync = null!;

Action policy = () => Policy
.HandleResult(ResultPrimitive.Fault)
.FallbackAsync(fallbackAction, onFallbackAsync);

policy.Should().Throw<ArgumentNullException>()
.And.ParamName.Should().Be("onFallbackAsync");
}

#endregion

#region Policy operation tests
Expand Down
12 changes: 0 additions & 12 deletions test/Polly.Specs/PolicyTResultAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArgumentNullException>();
ex.And.ParamName.Should().Be("context");
}
martincostello marked this conversation as resolved.
Show resolved Hide resolved

[Fact]
public async Task Executing_the_policy_function_should_pass_context_to_executed_delegate()
{
Expand Down
4 changes: 2 additions & 2 deletions test/Polly.Specs/Polly.Specs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<Threshold>75,60,70</Threshold>
<Include>[Polly]*</Include>
<IncludePollyUsings>true</IncludePollyUsings>
<NoWarn>$(NoWarn);S103;S104;CA2000;IDE0011;SA1600;SA1204;SA1602;CA2008;CA1806;CA2201;</NoWarn>
<NoWarn>$(NoWarn);S3878;CA1030;S4144;S3717;SA1129;SA1407;S1402;SA1649;SA1402;S4056;CA1031</NoWarn>
<NoWarn>$(NoWarn);S103;S104;CA2000;IDE0011;SA1600;SA1204;CA2008;CA1806;CA2201;</NoWarn>
<NoWarn>$(NoWarn);S3878;CA1030;S3717;SA1129;SA1407;S1402;SA1649;SA1402;S4056;CA1031</NoWarn>
<NoWarn>$(NoWarn);S2184;</NoWarn>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion test/Polly.TestUtils/Polly.TestUtils.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('Windows'))">$(TargetFrameworks);net481</TargetFrameworks>
<ProjectType>Library</ProjectType>
<Nullable>enable</Nullable>
<NoWarn>$(NoWarn);SA1600;SA1204;SA1602;CA1062</NoWarn>
<NoWarn>$(NoWarn);SA1600;SA1204;CA1062</NoWarn>
<IsPackable>false</IsPackable>
<EnablePackageValidation>false</EnablePackageValidation>
<UsePublicApiAnalyzers>false</UsePublicApiAnalyzers>
Expand Down
Loading