Skip to content

Commit

Permalink
Fix SA1501/IDE0055 (#1957)
Browse files Browse the repository at this point in the history
* Fix SA1501/IDE0055

* Improve unit test coverage
  • Loading branch information
baranyaimate authored Feb 16, 2024
1 parent caa44e3 commit 5fe3377
Show file tree
Hide file tree
Showing 76 changed files with 1,405 additions and 534 deletions.
12 changes: 8 additions & 4 deletions src/Polly/AsyncPolicy.ContextAndKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public abstract partial class AsyncPolicy
/// <param name="policyKey">The unique, used-definable key to assign to this <see cref="AsyncPolicy"/> instance.</param>
public AsyncPolicy WithPolicyKey(string policyKey)
{
if (policyKeyInternal != null) throw PolicyKeyMustBeImmutableException(nameof(policyKey));
if (policyKeyInternal != null)
throw PolicyKeyMustBeImmutableException(nameof(policyKey));

policyKeyInternal = policyKey;
return this;
Expand All @@ -22,7 +23,8 @@ public AsyncPolicy WithPolicyKey(string policyKey)
/// <param name="policyKey">The unique, used-definable key to assign to this <see cref="IAsyncPolicy"/> instance.</param>
IAsyncPolicy IAsyncPolicy.WithPolicyKey(string policyKey)
{
if (policyKeyInternal != null) throw PolicyKeyMustBeImmutableException(nameof(policyKey));
if (policyKeyInternal != null)
throw PolicyKeyMustBeImmutableException(nameof(policyKey));

policyKeyInternal = policyKey;
return this;
Expand All @@ -38,7 +40,8 @@ public abstract partial class AsyncPolicy<TResult>
/// <param name="policyKey">The unique, used-definable key to assign to this <see cref="AsyncPolicy{TResult}"/> instance.</param>
public AsyncPolicy<TResult> WithPolicyKey(string policyKey)
{
if (policyKeyInternal != null) throw PolicyKeyMustBeImmutableException(nameof(policyKey));
if (policyKeyInternal != null)
throw PolicyKeyMustBeImmutableException(nameof(policyKey));

policyKeyInternal = policyKey;
return this;
Expand All @@ -51,7 +54,8 @@ public AsyncPolicy<TResult> WithPolicyKey(string policyKey)
/// <param name="policyKey">The unique, used-definable key to assign to this <see cref="IAsyncPolicy{TResult}"/> instance.</param>
IAsyncPolicy<TResult> IAsyncPolicy<TResult>.WithPolicyKey(string policyKey)
{
if (policyKeyInternal != null) throw PolicyKeyMustBeImmutableException(nameof(policyKey));
if (policyKeyInternal != null)
throw PolicyKeyMustBeImmutableException(nameof(policyKey));

policyKeyInternal = policyKey;
return this;
Expand Down
12 changes: 8 additions & 4 deletions src/Polly/AsyncPolicy.ExecuteOverloads.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public Task ExecuteAsync(Func<Context, CancellationToken, Task> action, IDiction
[DebuggerStepThrough]
public async Task ExecuteAsync(Func<Context, CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext)
{
if (context == null) throw new ArgumentNullException(nameof(context));
if (context == null)
throw new ArgumentNullException(nameof(context));

SetPolicyContext(context, out string priorPolicyWrapKey, out string priorPolicyKey);

Expand Down Expand Up @@ -213,7 +214,8 @@ public Task<TResult> ExecuteAsync<TResult>(Func<Context, CancellationToken, Task
[DebuggerStepThrough]
public async Task<TResult> ExecuteAsync<TResult>(Func<Context, CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext)
{
if (context == null) throw new ArgumentNullException(nameof(context));
if (context == null)
throw new ArgumentNullException(nameof(context));

SetPolicyContext(context, out string priorPolicyWrapKey, out string priorPolicyKey);

Expand Down Expand Up @@ -329,7 +331,8 @@ public Task<PolicyResult> ExecuteAndCaptureAsync(Func<Context, CancellationToken
[DebuggerStepThrough]
public async Task<PolicyResult> ExecuteAndCaptureAsync(Func<Context, CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext)
{
if (context == null) throw new ArgumentNullException(nameof(context));
if (context == null)
throw new ArgumentNullException(nameof(context));

try
{
Expand Down Expand Up @@ -453,7 +456,8 @@ public Task<PolicyResult<TResult>> ExecuteAndCaptureAsync<TResult>(Func<Context,
[DebuggerStepThrough]
public async Task<PolicyResult<TResult>> ExecuteAndCaptureAsync<TResult>(Func<Context, CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext)
{
if (context == null) throw new ArgumentNullException(nameof(context));
if (context == null)
throw new ArgumentNullException(nameof(context));

try
{
Expand Down
6 changes: 4 additions & 2 deletions src/Polly/AsyncPolicy.TResult.ExecuteOverloads.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ public Task<TResult> ExecuteAsync(Func<Context, CancellationToken, Task<TResult>
[DebuggerStepThrough]
public async Task<TResult> ExecuteAsync(Func<Context, CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext)
{
if (context == null) throw new ArgumentNullException(nameof(context));
if (context == null)
throw new ArgumentNullException(nameof(context));

SetPolicyContext(context, out string priorPolicyWrapKey, out string priorPolicyKey);

Expand Down Expand Up @@ -220,7 +221,8 @@ public Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(Func<Context, Cancella
[DebuggerStepThrough]
public async Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(Func<Context, CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext)
{
if (context == null) throw new ArgumentNullException(nameof(context));
if (context == null)
throw new ArgumentNullException(nameof(context));

try
{
Expand Down
2 changes: 1 addition & 1 deletion src/Polly/Bulkhead/AsyncBulkheadEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Polly.Bulkhead;

internal static class AsyncBulkheadEngine
{
internal static async Task<TResult> ImplementationAsync<TResult>(
internal static async Task<TResult> ImplementationAsync<TResult>(
Func<Context, CancellationToken, Task<TResult>> action,
Context context,
Func<Context, Task> onBulkheadRejectedAsync,
Expand Down
9 changes: 6 additions & 3 deletions src/Polly/Bulkhead/AsyncBulkheadSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ public static AsyncBulkheadPolicy BulkheadAsync(
int maxQueuingActions,
Func<Context, Task> onBulkheadRejectedAsync)
{
if (maxParallelization <= 0) throw new ArgumentOutOfRangeException(nameof(maxParallelization), "Value must be greater than zero.");
if (maxQueuingActions < 0) throw new ArgumentOutOfRangeException(nameof(maxQueuingActions), "Value must be greater than or equal to zero.");
if (onBulkheadRejectedAsync == null) throw new ArgumentNullException(nameof(onBulkheadRejectedAsync));
if (maxParallelization <= 0)
throw new ArgumentOutOfRangeException(nameof(maxParallelization), "Value must be greater than zero.");
if (maxQueuingActions < 0)
throw new ArgumentOutOfRangeException(nameof(maxQueuingActions), "Value must be greater than or equal to zero.");
if (onBulkheadRejectedAsync == null)
throw new ArgumentNullException(nameof(onBulkheadRejectedAsync));

return new AsyncBulkheadPolicy(
maxParallelization,
Expand Down
9 changes: 6 additions & 3 deletions src/Polly/Bulkhead/AsyncBulkheadTResultSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ public static AsyncBulkheadPolicy<TResult> BulkheadAsync<TResult>(int maxParalle
/// <exception cref="ArgumentNullException">onBulkheadRejectedAsync</exception>
public static AsyncBulkheadPolicy<TResult> BulkheadAsync<TResult>(int maxParallelization, int maxQueuingActions, Func<Context, Task> onBulkheadRejectedAsync)
{
if (maxParallelization <= 0) throw new ArgumentOutOfRangeException(nameof(maxParallelization), "Value must be greater than zero.");
if (maxQueuingActions < 0) throw new ArgumentOutOfRangeException(nameof(maxQueuingActions), "Value must be greater than or equal to zero.");
if (onBulkheadRejectedAsync == null) throw new ArgumentNullException(nameof(onBulkheadRejectedAsync));
if (maxParallelization <= 0)
throw new ArgumentOutOfRangeException(nameof(maxParallelization), "Value must be greater than zero.");
if (maxQueuingActions < 0)
throw new ArgumentOutOfRangeException(nameof(maxQueuingActions), "Value must be greater than or equal to zero.");
if (onBulkheadRejectedAsync == null)
throw new ArgumentNullException(nameof(onBulkheadRejectedAsync));

return new AsyncBulkheadPolicy<TResult>(
maxParallelization,
Expand Down
9 changes: 6 additions & 3 deletions src/Polly/Bulkhead/BulkheadSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ public static BulkheadPolicy Bulkhead(int maxParallelization, int maxQueuingActi
/// <exception cref="ArgumentNullException">onBulkheadRejected</exception>
public static BulkheadPolicy Bulkhead(int maxParallelization, int maxQueuingActions, Action<Context> onBulkheadRejected)
{
if (maxParallelization <= 0) throw new ArgumentOutOfRangeException(nameof(maxParallelization), "Value must be greater than zero.");
if (maxQueuingActions < 0) throw new ArgumentOutOfRangeException(nameof(maxQueuingActions), "Value must be greater than or equal to zero.");
if (onBulkheadRejected == null) throw new ArgumentNullException(nameof(onBulkheadRejected));
if (maxParallelization <= 0)
throw new ArgumentOutOfRangeException(nameof(maxParallelization), "Value must be greater than zero.");
if (maxQueuingActions < 0)
throw new ArgumentOutOfRangeException(nameof(maxQueuingActions), "Value must be greater than or equal to zero.");
if (onBulkheadRejected == null)
throw new ArgumentNullException(nameof(onBulkheadRejected));

return new BulkheadPolicy(
maxParallelization,
Expand Down
9 changes: 6 additions & 3 deletions src/Polly/Bulkhead/BulkheadTResultSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ public static BulkheadPolicy<TResult> Bulkhead<TResult>(int maxParallelization,
/// <exception cref="ArgumentNullException">onBulkheadRejected</exception>
public static BulkheadPolicy<TResult> Bulkhead<TResult>(int maxParallelization, int maxQueuingActions, Action<Context> onBulkheadRejected)
{
if (maxParallelization <= 0) throw new ArgumentOutOfRangeException(nameof(maxParallelization), "Value must be greater than zero.");
if (maxQueuingActions < 0) throw new ArgumentOutOfRangeException(nameof(maxQueuingActions), "Value must be greater than or equal to zero.");
if (onBulkheadRejected == null) throw new ArgumentNullException(nameof(onBulkheadRejected));
if (maxParallelization <= 0)
throw new ArgumentOutOfRangeException(nameof(maxParallelization), "Value must be greater than zero.");
if (maxQueuingActions < 0)
throw new ArgumentOutOfRangeException(nameof(maxQueuingActions), "Value must be greater than or equal to zero.");
if (onBulkheadRejected == null)
throw new ArgumentNullException(nameof(onBulkheadRejected));

return new BulkheadPolicy<TResult>(
maxParallelization,
Expand Down
4 changes: 1 addition & 3 deletions src/Polly/Caching/AsyncCachePolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ protected override Task ImplementationAsync(
Func<Context, CancellationToken, Task> action,
Context context,
CancellationToken cancellationToken,
bool continueOnCapturedContext) =>
// Pass-through/NOOP policy action, for void-returning executions through the cache policy.
action(context, cancellationToken);
bool continueOnCapturedContext) => action(context, cancellationToken); // Pass-through/NOOP policy action, for void-returning executions through the cache policy.

/// <inheritdoc/>
[DebuggerStepThrough]
Expand Down
36 changes: 24 additions & 12 deletions src/Polly/Caching/AsyncCacheSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, Tim
/// <exception cref="ArgumentNullException">cacheKeyStrategy</exception>
public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, ICacheKeyStrategy cacheKeyStrategy, Action<Context, string, Exception>? onCacheError = null)
{
if (cacheProvider == null) throw new ArgumentNullException(nameof(cacheProvider));
if (ttlStrategy == null) throw new ArgumentNullException(nameof(ttlStrategy));
if (cacheKeyStrategy == null) throw new ArgumentNullException(nameof(cacheKeyStrategy));
if (cacheProvider == null)
throw new ArgumentNullException(nameof(cacheProvider));
if (ttlStrategy == null)
throw new ArgumentNullException(nameof(ttlStrategy));
if (cacheKeyStrategy == null)
throw new ArgumentNullException(nameof(cacheKeyStrategy));

Action<Context, string> emptyDelegate = (_, _) => { };

Expand Down Expand Up @@ -105,9 +108,12 @@ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, Tim
/// <exception cref="ArgumentNullException">cacheKeyStrategy</exception>
public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Func<Context, string> cacheKeyStrategy, Action<Context, string, Exception>? onCacheError = null)
{
if (cacheProvider == null) throw new ArgumentNullException(nameof(cacheProvider));
if (ttlStrategy == null) throw new ArgumentNullException(nameof(ttlStrategy));
if (cacheKeyStrategy == null) throw new ArgumentNullException(nameof(cacheKeyStrategy));
if (cacheProvider == null)
throw new ArgumentNullException(nameof(cacheProvider));
if (ttlStrategy == null)
throw new ArgumentNullException(nameof(ttlStrategy));
if (cacheKeyStrategy == null)
throw new ArgumentNullException(nameof(cacheKeyStrategy));

Action<Context, string> emptyDelegate = (_, _) => { };

Expand Down Expand Up @@ -296,13 +302,19 @@ public static AsyncCachePolicy CacheAsync(
Action<Context, string, Exception>? onCacheGetError,
Action<Context, string, Exception>? onCachePutError)
{
if (cacheProvider == null) throw new ArgumentNullException(nameof(cacheProvider));
if (ttlStrategy == null) throw new ArgumentNullException(nameof(ttlStrategy));
if (cacheKeyStrategy == null) throw new ArgumentNullException(nameof(cacheKeyStrategy));
if (cacheProvider == null)
throw new ArgumentNullException(nameof(cacheProvider));
if (ttlStrategy == null)
throw new ArgumentNullException(nameof(ttlStrategy));
if (cacheKeyStrategy == null)
throw new ArgumentNullException(nameof(cacheKeyStrategy));

if (onCacheGet == null) throw new ArgumentNullException(nameof(onCacheGet));
if (onCacheMiss == null) throw new ArgumentNullException(nameof(onCacheMiss));
if (onCachePut == null) throw new ArgumentNullException(nameof(onCachePut));
if (onCacheGet == null)
throw new ArgumentNullException(nameof(onCacheGet));
if (onCacheMiss == null)
throw new ArgumentNullException(nameof(onCacheMiss));
if (onCachePut == null)
throw new ArgumentNullException(nameof(onCachePut));

return new AsyncCachePolicy(cacheProvider, ttlStrategy, cacheKeyStrategy, onCacheGet, onCacheMiss, onCachePut, onCacheGetError, onCachePutError);
}
Expand Down
Loading

0 comments on commit 5fe3377

Please sign in to comment.