Skip to content

Commit 06b39ff

Browse files
authored
Fix S3878 (#2197)
Fix S3878 warnings.
1 parent c90c0f6 commit 06b39ff

3 files changed

Lines changed: 15 additions & 12 deletions

File tree

test/Polly.Specs/Polly.Specs.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<Include>[Polly]*</Include>
1010
<IncludePollyUsings>true</IncludePollyUsings>
1111
<NoWarn>$(NoWarn);CA1030;CA1031;CA2008;CA2201</NoWarn>
12-
<NoWarn>$(NoWarn);S103;S104;S2184;S3878;S6966</NoWarn>
12+
<NoWarn>$(NoWarn);S103;S104;S2184;S6966</NoWarn>
1313
<NoWarn>$(NoWarn);SA1204;SA1402;SA1600</NoWarn>
1414
</PropertyGroup>
1515

test/Polly.Specs/Wrap/PolicyWrapSpecs.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,10 @@ public void Wrapping_nothing_using_static_wrap_syntax_should_throw()
253253
public void Wrapping_only_one_policy_using_static_wrap_syntax_should_throw()
254254
{
255255
Policy singlePolicy = Policy.Handle<Exception>().Retry();
256+
257+
#pragma warning disable S3878 // Remove this array creation and simply pass the elements
256258
Action config = () => Policy.Wrap(new[] { singlePolicy });
259+
#pragma warning restore S3878
257260

258261
config.Should().Throw<ArgumentException>().And.ParamName.Should().Be("policies");
259262
}
@@ -263,7 +266,7 @@ public void Wrapping_two_policies_using_static_wrap_syntax_should_not_throw()
263266
{
264267
Policy retry = Policy.Handle<Exception>().Retry();
265268
Policy breaker = Policy.Handle<Exception>().CircuitBreaker(1, TimeSpan.FromSeconds(10));
266-
Action config = () => Policy.Wrap(new[] { retry, breaker });
269+
Action config = () => Policy.Wrap(retry, breaker);
267270

268271
config.Should().NotThrow();
269272
}
@@ -275,7 +278,7 @@ public void Wrapping_more_than_two_policies_using_static_wrap_syntax_should_not_
275278
Policy divideByZeroRetry = Policy.Handle<DivideByZeroException>().Retry(2);
276279
Policy breaker = Policy.Handle<Exception>().CircuitBreaker(1, TimeSpan.FromSeconds(10));
277280

278-
Action config = () => Policy.Wrap(new[] { divideByZeroRetry, retry, breaker });
281+
Action config = () => Policy.Wrap(divideByZeroRetry, retry, breaker);
279282

280283
config.Should().NotThrow();
281284
}
@@ -308,7 +311,7 @@ public void Wrapping_nothing_using_static_wrap_strongly_typed_syntax_should_thro
308311
public void Wrapping_only_one_policy_using_static_wrap_strongly_typed_syntax_should_throw()
309312
{
310313
Policy<int> singlePolicy = Policy<int>.Handle<Exception>().Retry();
311-
Action config = () => Policy.Wrap<int>(new[] { singlePolicy });
314+
Action config = () => Policy.Wrap<int>(singlePolicy);
312315

313316
config.Should().Throw<ArgumentException>().And.ParamName.Should().Be("policies");
314317
}
@@ -318,7 +321,7 @@ public void Wrapping_two_policies_using_static_wrap_strongly_typed_syntax_should
318321
{
319322
Policy<int> retry = Policy<int>.Handle<Exception>().Retry();
320323
Policy<int> breaker = Policy<int>.Handle<Exception>().CircuitBreaker(1, TimeSpan.FromSeconds(10));
321-
Action config = () => Policy.Wrap<int>(new[] { retry, breaker });
324+
Action config = () => Policy.Wrap<int>(retry, breaker);
322325

323326
config.Should().NotThrow();
324327
}
@@ -330,7 +333,7 @@ public void Wrapping_more_than_two_policies_using_static_wrap_strongly_typed_syn
330333
Policy<int> divideByZeroRetry = Policy<int>.Handle<DivideByZeroException>().Retry(2);
331334
Policy<int> breaker = Policy<int>.Handle<Exception>().CircuitBreaker(1, TimeSpan.FromSeconds(10));
332335

333-
Action config = () => Policy.Wrap<int>(new[] { divideByZeroRetry, retry, breaker });
336+
Action config = () => Policy.Wrap<int>(divideByZeroRetry, retry, breaker);
334337

335338
config.Should().NotThrow();
336339
}

test/Polly.Specs/Wrap/PolicyWrapSpecsAsync.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public void Wrapping_nothing_using_static_wrap_syntax_should_throw()
253253
public void Wrapping_only_one_policy_using_static_wrap_syntax_should_throw()
254254
{
255255
AsyncPolicy singlePolicy = Policy.Handle<Exception>().RetryAsync();
256-
Action config = () => Policy.WrapAsync(new[] { singlePolicy });
256+
Action config = () => Policy.WrapAsync(singlePolicy);
257257

258258
config.Should().Throw<ArgumentException>().And.ParamName.Should().Be("policies");
259259
}
@@ -263,7 +263,7 @@ public void Wrapping_two_policies_using_static_wrap_syntax_should_not_throw()
263263
{
264264
AsyncPolicy retry = Policy.Handle<Exception>().RetryAsync();
265265
AsyncPolicy breaker = Policy.Handle<Exception>().CircuitBreakerAsync(1, TimeSpan.FromSeconds(10));
266-
Action config = () => Policy.WrapAsync(new[] { retry, breaker });
266+
Action config = () => Policy.WrapAsync(retry, breaker);
267267

268268
config.Should().NotThrow();
269269
}
@@ -275,7 +275,7 @@ public void Wrapping_more_than_two_policies_using_static_wrap_syntax_should_not_
275275
AsyncPolicy divideByZeroRetry = Policy.Handle<DivideByZeroException>().RetryAsync(2);
276276
AsyncPolicy breaker = Policy.Handle<Exception>().CircuitBreakerAsync(1, TimeSpan.FromSeconds(10));
277277

278-
Action config = () => Policy.WrapAsync(new[] { divideByZeroRetry, retry, breaker });
278+
Action config = () => Policy.WrapAsync(divideByZeroRetry, retry, breaker);
279279

280280
config.Should().NotThrow();
281281
}
@@ -308,7 +308,7 @@ public void Wrapping_nothing_using_static_wrap_strongly_typed_syntax_should_thro
308308
public void Wrapping_only_one_policy_using_static_wrap_strongly_typed_syntax_should_throw()
309309
{
310310
AsyncPolicy<int> singlePolicy = Policy<int>.Handle<Exception>().RetryAsync();
311-
Action config = () => Policy.WrapAsync<int>(new[] { singlePolicy });
311+
Action config = () => Policy.WrapAsync<int>(singlePolicy);
312312

313313
config.Should().Throw<ArgumentException>().And.ParamName.Should().Be("policies");
314314
}
@@ -318,7 +318,7 @@ public void Wrapping_two_policies_using_static_wrap_strongly_typed_syntax_should
318318
{
319319
AsyncPolicy<int> retry = Policy<int>.Handle<Exception>().RetryAsync();
320320
AsyncPolicy<int> breaker = Policy<int>.Handle<Exception>().CircuitBreakerAsync(1, TimeSpan.FromSeconds(10));
321-
Action config = () => Policy.WrapAsync<int>(new[] { retry, breaker });
321+
Action config = () => Policy.WrapAsync<int>(retry, breaker);
322322

323323
config.Should().NotThrow();
324324
}
@@ -330,7 +330,7 @@ public void Wrapping_more_than_two_policies_using_static_wrap_strongly_typed_syn
330330
AsyncPolicy<int> divideByZeroRetry = Policy<int>.Handle<DivideByZeroException>().RetryAsync(2);
331331
AsyncPolicy<int> breaker = Policy<int>.Handle<Exception>().CircuitBreakerAsync(1, TimeSpan.FromSeconds(10));
332332

333-
Action config = () => Policy.WrapAsync<int>(new[] { divideByZeroRetry, retry, breaker });
333+
Action config = () => Policy.WrapAsync<int>(divideByZeroRetry, retry, breaker);
334334

335335
config.Should().NotThrow();
336336
}

0 commit comments

Comments
 (0)