Skip to content

Commit aba7a34

Browse files
committed
fix some nullables in tests
1 parent 0462a4d commit aba7a34

8 files changed

+80
-80
lines changed

src/Polly.Specs/Caching/CacheAsyncSpecs.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ public async Task Should_execute_delegate_and_put_value_in_cache_if_cache_does_n
7878
IAsyncCacheProvider stubCacheProvider = new StubCacheProvider();
7979
var cache = Policy.CacheAsync(stubCacheProvider, TimeSpan.MaxValue);
8080

81-
(bool cacheHit1, object fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
81+
(bool cacheHit1, object? fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
8282
cacheHit1.Should().BeFalse();
8383
fromCache1.Should().BeNull();
8484

8585
(await cache.ExecuteAsync(async _ => { await TaskHelper.EmptyTask; return valueToReturn; }, new Context(operationKey))).Should().Be(valueToReturn);
8686

87-
(bool cacheHit2, object fromCache2) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
87+
(bool cacheHit2, object? fromCache2) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
8888
cacheHit2.Should().BeTrue();
8989
fromCache2.Should().Be(valueToReturn);
9090
}
@@ -99,7 +99,7 @@ public async Task Should_execute_delegate_and_put_value_in_cache_but_when_it_exp
9999
TimeSpan ttl = TimeSpan.FromMinutes(30);
100100
var cache = Policy.CacheAsync(stubCacheProvider, ttl);
101101

102-
(bool cacheHit1, object fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
102+
(bool cacheHit1, object? fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
103103
cacheHit1.Should().BeFalse();
104104
fromCache1.Should().BeNull();
105105

@@ -117,7 +117,7 @@ public async Task Should_execute_delegate_and_put_value_in_cache_but_when_it_exp
117117
// First execution should execute delegate and put result in the cache.
118118
(await cache.ExecuteAsync(func, new Context(operationKey))).Should().Be(valueToReturn);
119119
delegateInvocations.Should().Be(1);
120-
(bool cacheHit2, object fromCache2) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
120+
(bool cacheHit2, object? fromCache2) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
121121
cacheHit2.Should().BeTrue();
122122
fromCache2.Should().Be(valueToReturn);
123123

@@ -144,13 +144,13 @@ public async Task Should_execute_delegate_but_not_put_value_in_cache_if_cache_do
144144
IAsyncCacheProvider stubCacheProvider = new StubCacheProvider();
145145
var cache = Policy.CacheAsync(stubCacheProvider, TimeSpan.Zero);
146146

147-
(bool cacheHit1, object fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
147+
(bool cacheHit1, object? fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
148148
cacheHit1.Should().BeFalse();
149149
fromCache1.Should().BeNull();
150150

151151
(await cache.ExecuteAsync(async _ => { await TaskHelper.EmptyTask; return valueToReturn; }, new Context(operationKey))).Should().Be(valueToReturn);
152152

153-
(bool cacheHit2, object fromCache2) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
153+
(bool cacheHit2, object? fromCache2) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
154154
cacheHit2.Should().BeFalse();
155155
fromCache2.Should().BeNull();
156156
}
@@ -240,13 +240,13 @@ public async Task Should_execute_delegate_and_put_value_in_cache_if_cache_does_n
240240
IAsyncCacheProvider stubCacheProvider = new StubCacheProvider();
241241
var cache = Policy.CacheAsync(stubCacheProvider, TimeSpan.MaxValue);
242242

243-
(bool cacheHit1, object fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
243+
(bool cacheHit1, object? fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
244244
cacheHit1.Should().BeFalse();
245245
fromCache1.Should().BeNull();
246246

247247
(await cache.ExecuteAsync(async _ => { await TaskHelper.EmptyTask; return valueToReturn; }, new Context(operationKey))).Should().Be(valueToReturn);
248248

249-
(bool cacheHit2, object fromCache2) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
249+
(bool cacheHit2, object? fromCache2) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
250250
cacheHit2.Should().BeTrue();
251251
fromCache2.Should().Be(valueToReturn);
252252
}
@@ -284,13 +284,13 @@ public async Task Should_execute_delegate_and_put_value_in_cache_if_cache_does_n
284284
IAsyncCacheProvider stubCacheProvider = new StubCacheProvider();
285285
var cache = Policy.CacheAsync(stubCacheProvider, TimeSpan.MaxValue);
286286

287-
(bool cacheHit1, object fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
287+
(bool cacheHit1, object? fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
288288
cacheHit1.Should().BeFalse();
289289
fromCache1.Should().BeNull();
290290

291291
(await cache.ExecuteAsync(async _ => { await TaskHelper.EmptyTask; return valueToReturn; }, new Context(operationKey))).Should().Be(valueToReturn);
292292

293-
(bool cacheHit2, object fromCache2) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
293+
(bool cacheHit2, object? fromCache2) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
294294
cacheHit2.Should().BeTrue();
295295
fromCache2.Should().Be(valueToReturn);
296296
}
@@ -502,7 +502,7 @@ public async Task Should_honour_cancellation_during_delegate_execution_and_not_p
502502
await cache.Awaiting(policy => policy.ExecuteAsync(func, new Context(operationKey), tokenSource.Token))
503503
.Should().ThrowAsync<OperationCanceledException>();
504504

505-
(bool cacheHit, object fromCache) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
505+
(bool cacheHit, object? fromCache) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
506506
cacheHit.Should().BeFalse();
507507
fromCache.Should().BeNull();
508508
}
@@ -562,7 +562,7 @@ public async Task Should_call_onError_delegate_if_cache_put_errors()
562562

563563
var cache = Policy.CacheAsync(stubCacheProvider, TimeSpan.MaxValue, onError);
564564

565-
(bool cacheHit1, object fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
565+
(bool cacheHit1, object? fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
566566
cacheHit1.Should().BeFalse();
567567
fromCache1.Should().BeNull();
568568

@@ -572,7 +572,7 @@ public async Task Should_call_onError_delegate_if_cache_put_errors()
572572
exceptionFromCacheProvider.Should().Be(ex);
573573

574574
// failed to put it in the cache
575-
(bool cacheHit2, object fromCache2) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
575+
(bool cacheHit2, object? fromCache2) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
576576
cacheHit2.Should().BeFalse();
577577
fromCache2.Should().BeNull();
578578
}
@@ -632,13 +632,13 @@ public async Task Should_execute_oncachemiss_and_oncacheput_if_cache_does_not_ho
632632
IAsyncCacheProvider stubCacheProvider = new StubCacheProvider();
633633
var cache = Policy.CacheAsync(stubCacheProvider, new RelativeTtl(TimeSpan.MaxValue), DefaultCacheKeyStrategy.Instance, emptyDelegate, onCacheMiss, onCachePut, noErrorHandling, noErrorHandling);
634634

635-
(bool cacheHit1, object fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
635+
(bool cacheHit1, object? fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
636636
cacheHit1.Should().BeFalse();
637637
fromCache1.Should().BeNull();
638638

639639
(await cache.ExecuteAsync(async _ => { await TaskHelper.EmptyTask; return valueToReturn; }, contextToExecute)).Should().Be(valueToReturn);
640640

641-
(bool cacheHit2, object fromCache2) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
641+
(bool cacheHit2, object? fromCache2) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
642642
cacheHit2.Should().BeTrue();
643643
fromCache2.Should().Be(valueToReturn);
644644

@@ -669,7 +669,7 @@ public async Task Should_execute_oncachemiss_but_not_oncacheput_if_cache_does_no
669669
IAsyncCacheProvider stubCacheProvider = new StubCacheProvider();
670670
var cache = Policy.CacheAsync(stubCacheProvider, new RelativeTtl(TimeSpan.Zero), DefaultCacheKeyStrategy.Instance, emptyDelegate, onCacheMiss, onCachePut, noErrorHandling, noErrorHandling);
671671

672-
(bool cacheHit, object fromCache) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
672+
(bool cacheHit, object? fromCache) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
673673
cacheHit.Should().BeFalse();
674674
fromCache.Should().BeNull();
675675

src/Polly.Specs/Caching/CacheSpecs.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ public void Should_execute_delegate_and_put_value_in_cache_if_cache_does_not_hol
7777
ISyncCacheProvider stubCacheProvider = new StubCacheProvider();
7878
CachePolicy cache = Policy.Cache(stubCacheProvider, TimeSpan.MaxValue);
7979

80-
(bool cacheHit1, object fromCache1) = stubCacheProvider.TryGet(operationKey);
80+
(bool cacheHit1, object? fromCache1) = stubCacheProvider.TryGet(operationKey);
8181
cacheHit1.Should().BeFalse();
8282
fromCache1.Should().BeNull();
8383

8484
cache.Execute(_ => valueToReturn, new Context(operationKey)).Should().Be(valueToReturn);
8585

86-
(bool cacheHit2, object fromCache2) = stubCacheProvider.TryGet(operationKey);
86+
(bool cacheHit2, object? fromCache2) = stubCacheProvider.TryGet(operationKey);
8787
cacheHit2.Should().BeTrue();
8888
fromCache2.Should().Be(valueToReturn);
8989
}
@@ -98,7 +98,7 @@ public void Should_execute_delegate_and_put_value_in_cache_but_when_it_expires_e
9898
TimeSpan ttl = TimeSpan.FromMinutes(30);
9999
CachePolicy cache = Policy.Cache(stubCacheProvider, ttl);
100100

101-
(bool cacheHit1, object fromCache1) = stubCacheProvider.TryGet(operationKey);
101+
(bool cacheHit1, object? fromCache1) = stubCacheProvider.TryGet(operationKey);
102102
cacheHit1.Should().BeFalse();
103103
fromCache1.Should().BeNull();
104104

@@ -116,7 +116,7 @@ public void Should_execute_delegate_and_put_value_in_cache_but_when_it_expires_e
116116
cache.Execute(func, new Context(operationKey)).Should().Be(valueToReturn);
117117
delegateInvocations.Should().Be(1);
118118

119-
(bool cacheHit2, object fromCache2) = stubCacheProvider.TryGet(operationKey);
119+
(bool cacheHit2, object? fromCache2) = stubCacheProvider.TryGet(operationKey);
120120
cacheHit2.Should().BeTrue();
121121
fromCache2.Should().Be(valueToReturn);
122122

@@ -143,13 +143,13 @@ public void Should_execute_delegate_but_not_put_value_in_cache_if_cache_does_not
143143
ISyncCacheProvider stubCacheProvider = new StubCacheProvider();
144144
CachePolicy cache = Policy.Cache(stubCacheProvider, TimeSpan.Zero);
145145

146-
(bool cacheHit1, object fromCache1) = stubCacheProvider.TryGet(operationKey);
146+
(bool cacheHit1, object? fromCache1) = stubCacheProvider.TryGet(operationKey);
147147
cacheHit1.Should().BeFalse();
148148
fromCache1.Should().BeNull();
149149

150150
cache.Execute(_ => valueToReturn, new Context(operationKey)).Should().Be(valueToReturn);
151151

152-
(bool cacheHit2, object fromCache2) = stubCacheProvider.TryGet(operationKey);
152+
(bool cacheHit2, object? fromCache2) = stubCacheProvider.TryGet(operationKey);
153153
cacheHit2.Should().BeFalse();
154154
fromCache2.Should().BeNull();
155155
}
@@ -238,13 +238,13 @@ public void Should_execute_delegate_and_put_value_in_cache_if_cache_does_not_hol
238238
ISyncCacheProvider stubCacheProvider = new StubCacheProvider();
239239
CachePolicy cache = Policy.Cache(stubCacheProvider, TimeSpan.MaxValue);
240240

241-
(bool cacheHit1, object fromCache1) = stubCacheProvider.TryGet(operationKey);
241+
(bool cacheHit1, object? fromCache1) = stubCacheProvider.TryGet(operationKey);
242242
cacheHit1.Should().BeFalse();
243243
fromCache1.Should().BeNull();
244244

245245
cache.Execute(_ => valueToReturn, new Context(operationKey)).Should().Be(valueToReturn);
246246

247-
(bool cacheHit2, object fromCache2) = stubCacheProvider.TryGet(operationKey);
247+
(bool cacheHit2, object? fromCache2) = stubCacheProvider.TryGet(operationKey);
248248
cacheHit2.Should().BeTrue();
249249
fromCache2.Should().Be(valueToReturn);
250250
}
@@ -281,13 +281,13 @@ public void Should_execute_delegate_and_put_value_in_cache_if_cache_does_not_hol
281281
ISyncCacheProvider stubCacheProvider = new StubCacheProvider();
282282
CachePolicy cache = Policy.Cache(stubCacheProvider, TimeSpan.MaxValue);
283283

284-
(bool cacheHit1, object fromCache1) = stubCacheProvider.TryGet(operationKey);
284+
(bool cacheHit1, object? fromCache1) = stubCacheProvider.TryGet(operationKey);
285285
cacheHit1.Should().BeFalse();
286286
fromCache1.Should().BeNull();
287287

288288
cache.Execute(_ => valueToReturn, new Context(operationKey)).Should().Be(valueToReturn);
289289

290-
(bool cacheHit2, object fromCache2) = stubCacheProvider.TryGet(operationKey);
290+
(bool cacheHit2, object? fromCache2) = stubCacheProvider.TryGet(operationKey);
291291
cacheHit2.Should().BeTrue();
292292
fromCache2.Should().Be(valueToReturn);
293293
}
@@ -493,7 +493,7 @@ public void Should_honour_cancellation_during_delegate_execution_and_not_put_to_
493493
cache.Invoking(policy => policy.Execute(func, new Context(operationKey), tokenSource.Token))
494494
.Should().Throw<OperationCanceledException>();
495495

496-
(bool cacheHit, object fromCache) = stubCacheProvider.TryGet(operationKey);
496+
(bool cacheHit, object? fromCache) = stubCacheProvider.TryGet(operationKey);
497497
cacheHit.Should().BeFalse();
498498
fromCache.Should().BeNull();
499499
}
@@ -551,7 +551,7 @@ public void Should_call_onError_delegate_if_cache_put_errors()
551551

552552
CachePolicy cache = Policy.Cache(stubCacheProvider, TimeSpan.MaxValue, onError);
553553

554-
(bool cacheHit1, object fromCache1) = stubCacheProvider.TryGet(operationKey);
554+
(bool cacheHit1, object? fromCache1) = stubCacheProvider.TryGet(operationKey);
555555
cacheHit1.Should().BeFalse();
556556
fromCache1.Should().BeNull();
557557

@@ -561,7 +561,7 @@ public void Should_call_onError_delegate_if_cache_put_errors()
561561
exceptionFromCacheProvider.Should().Be(ex);
562562

563563
// failed to put it in the cache
564-
(bool cacheHit2, object fromCache2) = stubCacheProvider.TryGet(operationKey);
564+
(bool cacheHit2, object? fromCache2) = stubCacheProvider.TryGet(operationKey);
565565
cacheHit2.Should().BeFalse();
566566
fromCache2.Should().BeNull();
567567

@@ -621,13 +621,13 @@ public void Should_execute_oncachemiss_and_oncacheput_if_cache_does_not_hold_val
621621
ISyncCacheProvider stubCacheProvider = new StubCacheProvider();
622622
CachePolicy cache = Policy.Cache(stubCacheProvider, new RelativeTtl(TimeSpan.MaxValue), DefaultCacheKeyStrategy.Instance, emptyDelegate, onCacheMiss, onCachePut, noErrorHandling, noErrorHandling);
623623

624-
(bool cacheHit1, object fromCache1) = stubCacheProvider.TryGet(operationKey);
624+
(bool cacheHit1, object? fromCache1) = stubCacheProvider.TryGet(operationKey);
625625
cacheHit1.Should().BeFalse();
626626
fromCache1.Should().BeNull();
627627

628628
cache.Execute(_ => valueToReturn, contextToExecute).Should().Be(valueToReturn);
629629

630-
(bool cacheHit2, object fromCache2) = stubCacheProvider.TryGet(operationKey);
630+
(bool cacheHit2, object? fromCache2) = stubCacheProvider.TryGet(operationKey);
631631
cacheHit2.Should().BeTrue();
632632
fromCache2.Should().Be(valueToReturn);
633633

@@ -659,7 +659,7 @@ public void Should_execute_oncachemiss_but_not_oncacheput_if_cache_does_not_hold
659659
ISyncCacheProvider stubCacheProvider = new StubCacheProvider();
660660
CachePolicy cache = Policy.Cache(stubCacheProvider, new RelativeTtl(TimeSpan.Zero), DefaultCacheKeyStrategy.Instance, emptyDelegate, onCacheMiss, onCachePut, noErrorHandling, noErrorHandling);
661661

662-
(bool cacheHit, object fromCache) = stubCacheProvider.TryGet(operationKey);
662+
(bool cacheHit, object? fromCache) = stubCacheProvider.TryGet(operationKey);
663663
cacheHit.Should().BeFalse();
664664
fromCache.Should().BeNull();
665665

0 commit comments

Comments
 (0)