Skip to content

Commit 00418ed

Browse files
authored
Enable nullable in tests (#1003)
1 parent a2cc212 commit 00418ed

File tree

63 files changed

+550
-554
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+550
-554
lines changed

src/Polly.Specs/Bulkhead/BulkheadAsyncSpecs.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public async Task Should_call_onBulkheadRejected_with_passed_context()
5757
string operationKey = "SomeKey";
5858
Context contextPassedToExecute = new Context(operationKey);
5959

60-
Context contextPassedToOnRejected = null;
60+
Context? contextPassedToOnRejected = null;
6161
Func<Context, Task> onRejectedAsync = async ctx => { contextPassedToOnRejected = ctx; await TaskHelper.EmptyTask; };
6262

6363
using (var bulkhead = Policy.BulkheadAsync(1, onRejectedAsync))
@@ -75,9 +75,9 @@ public async Task Should_call_onBulkheadRejected_with_passed_context()
7575
tcs.SetCanceled();
7676
}
7777

78-
contextPassedToOnRejected.Should().NotBeNull();
79-
contextPassedToOnRejected.OperationKey.Should().Be(operationKey);
80-
contextPassedToOnRejected.Should().BeSameAs(contextPassedToExecute);
78+
contextPassedToOnRejected!.Should().NotBeNull();
79+
contextPassedToOnRejected!.OperationKey.Should().Be(operationKey);
80+
contextPassedToOnRejected!.Should().BeSameAs(contextPassedToExecute);
8181
}
8282
}
8383

src/Polly.Specs/Bulkhead/BulkheadSpecs.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void Should_call_onBulkheadRejected_with_passed_context()
5555
string operationKey = "SomeKey";
5656
Context contextPassedToExecute = new Context(operationKey);
5757

58-
Context contextPassedToOnRejected = null;
58+
Context? contextPassedToOnRejected = null;
5959
Action<Context> onRejected = ctx => { contextPassedToOnRejected = ctx; };
6060

6161
using (BulkheadPolicy bulkhead = Policy.Bulkhead(1, onRejected))
@@ -72,9 +72,9 @@ public void Should_call_onBulkheadRejected_with_passed_context()
7272

7373
tcs.SetCanceled();
7474

75-
contextPassedToOnRejected.Should().NotBeNull();
76-
contextPassedToOnRejected.OperationKey.Should().Be(operationKey);
77-
contextPassedToOnRejected.Should().BeSameAs(contextPassedToExecute);
75+
contextPassedToOnRejected!.Should().NotBeNull();
76+
contextPassedToOnRejected!.OperationKey.Should().Be(operationKey);
77+
contextPassedToOnRejected!.Should().BeSameAs(contextPassedToExecute);
7878
}
7979
}
8080

src/Polly.Specs/Bulkhead/BulkheadSpecsBase.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ public BulkheadSpecsBase(ITestOutputHelper testOutputHelper)
3535

3636
#region Operating variables
3737

38-
protected IBulkheadPolicy BulkheadForStats { get; set; }
38+
protected IBulkheadPolicy BulkheadForStats { get; set; } = null!;
3939

40-
internal TraceableAction[] Actions { get; set; }
40+
internal TraceableAction[] Actions { get; set; } = { };
4141

42-
protected Task[] Tasks { get; set; }
42+
protected Task[] Tasks { get; set; } = { };
4343

4444
protected readonly AutoResetEvent StatusChangedEvent = new AutoResetEvent(false);
4545

4646
#endregion
4747

4848
#region Scenario
4949

50-
protected string Scenario { get; set; }
50+
protected string? Scenario { get; set; }
5151

5252
protected int MaxParallelization { get; set; }
5353
protected int MaxQueuingActions { get; set; }
@@ -236,7 +236,7 @@ protected void UpdateActuals()
236236
}
237237
}
238238

239-
protected AssertionFailure ActualsMatchExpecteds()
239+
protected AssertionFailure? ActualsMatchExpecteds()
240240
{
241241
UpdateActuals();
242242

@@ -283,7 +283,7 @@ protected AssertionFailure ActualsMatchExpecteds()
283283
return null;
284284
}
285285

286-
protected AssertionFailure AllTasksCompleted()
286+
protected AssertionFailure? AllTasksCompleted()
287287
{
288288
int countTasksCompleted = Tasks.Count(t => t.IsCompleted);
289289
if (countTasksCompleted < TotalActions)
@@ -311,13 +311,13 @@ protected void EnsureNoUnbservedTaskExceptions()
311311

312312
#endregion
313313

314-
protected AssertionFailure Expect(int expected, Func<int> actualFunc, string measure)
314+
protected AssertionFailure? Expect(int expected, Func<int> actualFunc, string measure)
315315
{
316316
int actual = actualFunc();
317317
return actual != expected ? new AssertionFailure(expected, actual, measure) : null;
318318
}
319319

320-
protected void Within(TimeSpan timeSpan, Func<AssertionFailure> actionContainingAssertions)
320+
protected void Within(TimeSpan timeSpan, Func<AssertionFailure?> actionContainingAssertions)
321321
{
322322
TimeSpan permitted = timeSpan;
323323
Stopwatch watch = Stopwatch.StartNew();

src/Polly.Specs/Bulkhead/BulkheadTResultAsyncSpecs.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public async Task Should_call_onBulkheadRejected_with_passed_context()
5858
string operationKey = "SomeKey";
5959
Context contextPassedToExecute = new Context(operationKey);
6060

61-
Context contextPassedToOnRejected = null;
61+
Context? contextPassedToOnRejected = null;
6262
Func<Context, Task> onRejectedAsync = async ctx => { contextPassedToOnRejected = ctx; await TaskHelper.EmptyTask; };
6363

6464
using (var bulkhead = Policy.BulkheadAsync<int>(1, onRejectedAsync))
@@ -82,10 +82,9 @@ public async Task Should_call_onBulkheadRejected_with_passed_context()
8282
tcs.SetCanceled();
8383
}
8484

85-
contextPassedToOnRejected.Should().NotBeNull();
86-
contextPassedToOnRejected.OperationKey.Should().Be(operationKey);
87-
contextPassedToOnRejected.Should().BeSameAs(contextPassedToExecute);
88-
85+
contextPassedToOnRejected!.Should().NotBeNull();
86+
contextPassedToOnRejected!.OperationKey.Should().Be(operationKey);
87+
contextPassedToOnRejected!.Should().BeSameAs(contextPassedToExecute);
8988
}
9089
}
9190

src/Polly.Specs/Bulkhead/BulkheadTResultSpecs.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void Should_call_onBulkheadRejected_with_passed_context()
5858
string operationKey = "SomeKey";
5959
Context contextPassedToExecute = new Context(operationKey);
6060

61-
Context contextPassedToOnRejected = null;
61+
Context? contextPassedToOnRejected = null;
6262
Action<Context> onRejected = ctx => { contextPassedToOnRejected = ctx; };
6363

6464
using (BulkheadPolicy<int> bulkhead = Policy.Bulkhead<int>(1, onRejected))
@@ -82,9 +82,9 @@ public void Should_call_onBulkheadRejected_with_passed_context()
8282
tcs.SetCanceled();
8383
}
8484

85-
contextPassedToOnRejected.Should().NotBeNull();
86-
contextPassedToOnRejected.OperationKey.Should().Be(operationKey);
87-
contextPassedToOnRejected.Should().BeSameAs(contextPassedToExecute);
85+
contextPassedToOnRejected!.Should().NotBeNull();
86+
contextPassedToOnRejected!.OperationKey.Should().Be(operationKey);
87+
contextPassedToOnRejected!.Should().BeSameAs(contextPassedToExecute);
8888
}
8989
}
9090

src/Polly.Specs/Caching/CacheAsyncSpecs.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class CacheAsyncSpecs : IDisposable
1818
[Fact]
1919
public void Should_throw_when_cache_provider_is_null()
2020
{
21-
IAsyncCacheProvider cacheProvider = null;
21+
IAsyncCacheProvider cacheProvider = null!;
2222
Action action = () => Policy.CacheAsync(cacheProvider, TimeSpan.MaxValue);
2323
action.Should().Throw<ArgumentNullException>().And.ParamName.Should().Be("cacheProvider");
2424
}
@@ -27,7 +27,7 @@ public void Should_throw_when_cache_provider_is_null()
2727
public void Should_throw_when_ttl_strategy_is_null()
2828
{
2929
IAsyncCacheProvider cacheProvider = new StubCacheProvider();
30-
ITtlStrategy ttlStrategy = null;
30+
ITtlStrategy ttlStrategy = null!;
3131
Action action = () => Policy.CacheAsync(cacheProvider, ttlStrategy);
3232
action.Should().Throw<ArgumentNullException>().And.ParamName.Should().Be("ttlStrategy");
3333
}
@@ -36,7 +36,7 @@ public void Should_throw_when_ttl_strategy_is_null()
3636
public void Should_throw_when_cache_key_strategy_is_null()
3737
{
3838
IAsyncCacheProvider cacheProvider = new StubCacheProvider();
39-
Func<Context, string> cacheKeyStrategy = null;
39+
Func<Context, string>? cacheKeyStrategy = null;
4040
Action action = () => Policy.CacheAsync(cacheProvider, TimeSpan.MaxValue, cacheKeyStrategy);
4141
action.Should().Throw<ArgumentNullException>().And.ParamName.Should().Be("cacheKeyStrategy");
4242
}
@@ -234,7 +234,7 @@ public async Task Should_allow_custom_ICacheKeyStrategy()
234234
[Fact]
235235
public async Task Should_execute_delegate_and_put_value_in_cache_if_cache_does_not_hold_value__default_for_reference_type()
236236
{
237-
ResultClass valueToReturn = default;
237+
ResultClass? valueToReturn = null;
238238
const string operationKey = "SomeOperationKey";
239239

240240
IAsyncCacheProvider stubCacheProvider = new StubCacheProvider();
@@ -254,7 +254,7 @@ public async Task Should_execute_delegate_and_put_value_in_cache_if_cache_does_n
254254
[Fact]
255255
public async Task Should_return_value_from_cache_and_not_execute_delegate_if_cache_holds_value__default_for_reference_type()
256256
{
257-
ResultClass valueToReturnFromCache = default;
257+
ResultClass? valueToReturnFromCache = null;
258258
ResultClass valueToReturnFromExecution = new ResultClass(ResultPrimitive.Good);
259259
const string operationKey = "SomeOperationKey";
260260

@@ -517,7 +517,7 @@ public async Task Should_call_onError_delegate_if_cache_get_errors()
517517
Exception ex = new Exception();
518518
IAsyncCacheProvider stubCacheProvider = new StubErroringCacheProvider(getException: ex, putException: null);
519519

520-
Exception exceptionFromCacheProvider = null;
520+
Exception? exceptionFromCacheProvider = null;
521521

522522
const string valueToReturnFromCache = "valueToReturnFromCache";
523523
const string valueToReturnFromExecution = "valueToReturnFromExecution";
@@ -553,7 +553,7 @@ public async Task Should_call_onError_delegate_if_cache_put_errors()
553553
Exception ex = new Exception();
554554
IAsyncCacheProvider stubCacheProvider = new StubErroringCacheProvider(getException: null, putException: ex);
555555

556-
Exception exceptionFromCacheProvider = null;
556+
Exception? exceptionFromCacheProvider = null;
557557

558558
const string valueToReturn = "valueToReturn";
559559
const string operationKey = "SomeOperationKey";
@@ -584,10 +584,10 @@ public async Task Should_execute_oncacheget_after_got_from_cache()
584584
const string valueToReturnFromExecution = "valueToReturnFromExecution";
585585

586586
const string operationKey = "SomeOperationKey";
587-
string keyPassedToDelegate = null;
587+
string? keyPassedToDelegate = null;
588588

589589
Context contextToExecute = new Context(operationKey);
590-
Context contextPassedToDelegate = null;
590+
Context? contextPassedToDelegate = null;
591591

592592
Action<Context, string, Exception> noErrorHandling = (_, _, _) => { };
593593
Action<Context, string> emptyDelegate = (_, _) => { };
@@ -617,12 +617,12 @@ public async Task Should_execute_oncachemiss_and_oncacheput_if_cache_does_not_ho
617617
const string valueToReturn = "valueToReturn";
618618

619619
const string operationKey = "SomeOperationKey";
620-
string keyPassedToOnCacheMiss = null;
621-
string keyPassedToOnCachePut = null;
620+
string? keyPassedToOnCacheMiss = null;
621+
string? keyPassedToOnCachePut = null;
622622

623623
Context contextToExecute = new Context(operationKey);
624-
Context contextPassedToOnCacheMiss = null;
625-
Context contextPassedToOnCachePut = null;
624+
Context? contextPassedToOnCacheMiss = null;
625+
Context? contextPassedToOnCachePut = null;
626626

627627
Action<Context, string, Exception> noErrorHandling = (_, _, _) => { };
628628
Action<Context, string> emptyDelegate = (_, _) => { };
@@ -654,12 +654,12 @@ public async Task Should_execute_oncachemiss_but_not_oncacheput_if_cache_does_no
654654
const string valueToReturn = "valueToReturn";
655655

656656
const string operationKey = "SomeOperationKey";
657-
string keyPassedToOnCacheMiss = null;
658-
string keyPassedToOnCachePut = null;
657+
string? keyPassedToOnCacheMiss = null;
658+
string? keyPassedToOnCachePut = null;
659659

660660
Context contextToExecute = new Context(operationKey);
661-
Context contextPassedToOnCacheMiss = null;
662-
Context contextPassedToOnCachePut = null;
661+
Context? contextPassedToOnCacheMiss = null;
662+
Context? contextPassedToOnCachePut = null;
663663

664664
Action<Context, string, Exception> noErrorHandling = (_, _, _) => { };
665665
Action<Context, string> emptyDelegate = (_, _) => { };

src/Polly.Specs/Caching/CacheSpecs.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class CacheSpecs : IDisposable
1818
[Fact]
1919
public void Should_throw_when_cache_provider_is_null()
2020
{
21-
ISyncCacheProvider cacheProvider = null;
21+
ISyncCacheProvider? cacheProvider = null;
2222
Action action = () => Policy.Cache(cacheProvider, TimeSpan.MaxValue);
2323
action.Should().Throw<ArgumentNullException>().And.ParamName.Should().Be("cacheProvider");
2424
}
@@ -27,7 +27,7 @@ public void Should_throw_when_cache_provider_is_null()
2727
public void Should_throw_when_ttl_strategy_is_null()
2828
{
2929
ISyncCacheProvider cacheProvider = new StubCacheProvider();
30-
ITtlStrategy ttlStrategy = null;
30+
ITtlStrategy? ttlStrategy = null;
3131
Action action = () => Policy.Cache(cacheProvider, ttlStrategy);
3232
action.Should().Throw<ArgumentNullException>().And.ParamName.Should().Be("ttlStrategy");
3333
}
@@ -36,7 +36,7 @@ public void Should_throw_when_ttl_strategy_is_null()
3636
public void Should_throw_when_cache_key_strategy_is_null()
3737
{
3838
ISyncCacheProvider cacheProvider = new StubCacheProvider();
39-
Func<Context, string> cacheKeyStrategy = null;
39+
Func<Context, string> cacheKeyStrategy = null!;
4040
Action action = () => Policy.Cache(cacheProvider, TimeSpan.MaxValue, cacheKeyStrategy);
4141
action.Should().Throw<ArgumentNullException>().And.ParamName.Should().Be("cacheKeyStrategy");
4242
}
@@ -232,7 +232,7 @@ public void Should_allow_custom_ICacheKeyStrategy()
232232
[Fact]
233233
public void Should_execute_delegate_and_put_value_in_cache_if_cache_does_not_hold_value__default_for_reference_type()
234234
{
235-
ResultClass valueToReturn = default;
235+
ResultClass? valueToReturn = null;
236236
const string operationKey = "SomeOperationKey";
237237

238238
ISyncCacheProvider stubCacheProvider = new StubCacheProvider();
@@ -252,7 +252,7 @@ public void Should_execute_delegate_and_put_value_in_cache_if_cache_does_not_hol
252252
[Fact]
253253
public void Should_return_value_from_cache_and_not_execute_delegate_if_cache_holds_value__default_for_reference_type()
254254
{
255-
ResultClass valueToReturnFromCache = default;
255+
ResultClass? valueToReturnFromCache = null;
256256
ResultClass valueToReturnFromExecution = new ResultClass(ResultPrimitive.Good);
257257
const string operationKey = "SomeOperationKey";
258258

@@ -508,7 +508,7 @@ public void Should_call_onError_delegate_if_cache_get_errors()
508508
Exception ex = new Exception();
509509
ISyncCacheProvider stubCacheProvider = new StubErroringCacheProvider(getException: ex, putException: null);
510510

511-
Exception exceptionFromCacheProvider = null;
511+
Exception? exceptionFromCacheProvider = null;
512512

513513
const string valueToReturnFromCache = "valueToReturnFromCache";
514514
const string valueToReturnFromExecution = "valueToReturnFromExecution";
@@ -542,7 +542,7 @@ public void Should_call_onError_delegate_if_cache_put_errors()
542542
Exception ex = new Exception();
543543
ISyncCacheProvider stubCacheProvider = new StubErroringCacheProvider(getException: null, putException: ex);
544544

545-
Exception exceptionFromCacheProvider = null;
545+
Exception? exceptionFromCacheProvider = null;
546546

547547
const string valueToReturn = "valueToReturn";
548548
const string operationKey = "SomeOperationKey";
@@ -574,10 +574,10 @@ public void Should_execute_oncacheget_after_got_from_cache()
574574
const string valueToReturnFromExecution = "valueToReturnFromExecution";
575575

576576
const string operationKey = "SomeOperationKey";
577-
string keyPassedToDelegate = null;
577+
string? keyPassedToDelegate = null;
578578

579579
Context contextToExecute = new Context(operationKey);
580-
Context contextPassedToDelegate = null;
580+
Context? contextPassedToDelegate = null;
581581

582582
Action<Context, string, Exception> noErrorHandling = (_, _, _) => { };
583583
Action<Context, string> emptyDelegate = (_, _) => { };
@@ -606,12 +606,12 @@ public void Should_execute_oncachemiss_and_oncacheput_if_cache_does_not_hold_val
606606
const string valueToReturn = "valueToReturn";
607607

608608
const string operationKey = "SomeOperationKey";
609-
string keyPassedToOnCacheMiss = null;
610-
string keyPassedToOnCachePut = null;
609+
string? keyPassedToOnCacheMiss = null;
610+
string? keyPassedToOnCachePut = null;
611611

612612
Context contextToExecute = new Context(operationKey);
613-
Context contextPassedToOnCacheMiss = null;
614-
Context contextPassedToOnCachePut = null;
613+
Context? contextPassedToOnCacheMiss = null;
614+
Context? contextPassedToOnCachePut = null;
615615

616616
Action<Context, string, Exception> noErrorHandling = (_, _, _) => { };
617617
Action<Context, string> emptyDelegate = (_, _) => { };
@@ -644,12 +644,12 @@ public void Should_execute_oncachemiss_but_not_oncacheput_if_cache_does_not_hold
644644
const string valueToReturn = "valueToReturn";
645645

646646
const string operationKey = "SomeOperationKey";
647-
string keyPassedToOnCacheMiss = null;
648-
string keyPassedToOnCachePut = null;
647+
string? keyPassedToOnCacheMiss = null;
648+
string? keyPassedToOnCachePut = null;
649649

650650
Context contextToExecute = new Context(operationKey);
651-
Context contextPassedToOnCacheMiss = null;
652-
Context contextPassedToOnCachePut = null;
651+
Context? contextPassedToOnCacheMiss = null;
652+
Context? contextPassedToOnCachePut = null;
653653

654654
Action<Context, string, Exception> noErrorHandling = (_, _, _) => { };
655655
Action<Context, string> emptyDelegate = (_, _) => { };

0 commit comments

Comments
 (0)