Skip to content

Commit

Permalink
fix some nullables in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Jan 7, 2023
1 parent 0462a4d commit aba7a34
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 80 deletions.
32 changes: 16 additions & 16 deletions src/Polly.Specs/Caching/CacheAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ public async Task Should_execute_delegate_and_put_value_in_cache_if_cache_does_n
IAsyncCacheProvider stubCacheProvider = new StubCacheProvider();
var cache = Policy.CacheAsync(stubCacheProvider, TimeSpan.MaxValue);

(bool cacheHit1, object fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
(bool cacheHit1, object? fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
cacheHit1.Should().BeFalse();
fromCache1.Should().BeNull();

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

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

(bool cacheHit1, object fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
(bool cacheHit1, object? fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
cacheHit1.Should().BeFalse();
fromCache1.Should().BeNull();

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

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

(bool cacheHit1, object fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
(bool cacheHit1, object? fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
cacheHit1.Should().BeFalse();
fromCache1.Should().BeNull();

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

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

(bool cacheHit1, object fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
(bool cacheHit1, object? fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
cacheHit1.Should().BeFalse();
fromCache1.Should().BeNull();

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

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

(bool cacheHit1, object fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
(bool cacheHit1, object? fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
cacheHit1.Should().BeFalse();
fromCache1.Should().BeNull();

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

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

(bool cacheHit, object fromCache) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
(bool cacheHit, object? fromCache) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
cacheHit.Should().BeFalse();
fromCache.Should().BeNull();
}
Expand Down Expand Up @@ -562,7 +562,7 @@ public async Task Should_call_onError_delegate_if_cache_put_errors()

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

(bool cacheHit1, object fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
(bool cacheHit1, object? fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
cacheHit1.Should().BeFalse();
fromCache1.Should().BeNull();

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

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

(bool cacheHit1, object fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
(bool cacheHit1, object? fromCache1) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
cacheHit1.Should().BeFalse();
fromCache1.Should().BeNull();

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

(bool cacheHit2, object fromCache2) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
(bool cacheHit2, object? fromCache2) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
cacheHit2.Should().BeTrue();
fromCache2.Should().Be(valueToReturn);

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

(bool cacheHit, object fromCache) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
(bool cacheHit, object? fromCache) = await stubCacheProvider.TryGetAsync(operationKey, CancellationToken.None, false);
cacheHit.Should().BeFalse();
fromCache.Should().BeNull();

Expand Down
32 changes: 16 additions & 16 deletions src/Polly.Specs/Caching/CacheSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ public void Should_execute_delegate_and_put_value_in_cache_if_cache_does_not_hol
ISyncCacheProvider stubCacheProvider = new StubCacheProvider();
CachePolicy cache = Policy.Cache(stubCacheProvider, TimeSpan.MaxValue);

(bool cacheHit1, object fromCache1) = stubCacheProvider.TryGet(operationKey);
(bool cacheHit1, object? fromCache1) = stubCacheProvider.TryGet(operationKey);
cacheHit1.Should().BeFalse();
fromCache1.Should().BeNull();

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

(bool cacheHit2, object fromCache2) = stubCacheProvider.TryGet(operationKey);
(bool cacheHit2, object? fromCache2) = stubCacheProvider.TryGet(operationKey);
cacheHit2.Should().BeTrue();
fromCache2.Should().Be(valueToReturn);
}
Expand All @@ -98,7 +98,7 @@ public void Should_execute_delegate_and_put_value_in_cache_but_when_it_expires_e
TimeSpan ttl = TimeSpan.FromMinutes(30);
CachePolicy cache = Policy.Cache(stubCacheProvider, ttl);

(bool cacheHit1, object fromCache1) = stubCacheProvider.TryGet(operationKey);
(bool cacheHit1, object? fromCache1) = stubCacheProvider.TryGet(operationKey);
cacheHit1.Should().BeFalse();
fromCache1.Should().BeNull();

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

(bool cacheHit2, object fromCache2) = stubCacheProvider.TryGet(operationKey);
(bool cacheHit2, object? fromCache2) = stubCacheProvider.TryGet(operationKey);
cacheHit2.Should().BeTrue();
fromCache2.Should().Be(valueToReturn);

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

(bool cacheHit1, object fromCache1) = stubCacheProvider.TryGet(operationKey);
(bool cacheHit1, object? fromCache1) = stubCacheProvider.TryGet(operationKey);
cacheHit1.Should().BeFalse();
fromCache1.Should().BeNull();

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

(bool cacheHit2, object fromCache2) = stubCacheProvider.TryGet(operationKey);
(bool cacheHit2, object? fromCache2) = stubCacheProvider.TryGet(operationKey);
cacheHit2.Should().BeFalse();
fromCache2.Should().BeNull();
}
Expand Down Expand Up @@ -238,13 +238,13 @@ public void Should_execute_delegate_and_put_value_in_cache_if_cache_does_not_hol
ISyncCacheProvider stubCacheProvider = new StubCacheProvider();
CachePolicy cache = Policy.Cache(stubCacheProvider, TimeSpan.MaxValue);

(bool cacheHit1, object fromCache1) = stubCacheProvider.TryGet(operationKey);
(bool cacheHit1, object? fromCache1) = stubCacheProvider.TryGet(operationKey);
cacheHit1.Should().BeFalse();
fromCache1.Should().BeNull();

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

(bool cacheHit2, object fromCache2) = stubCacheProvider.TryGet(operationKey);
(bool cacheHit2, object? fromCache2) = stubCacheProvider.TryGet(operationKey);
cacheHit2.Should().BeTrue();
fromCache2.Should().Be(valueToReturn);
}
Expand Down Expand Up @@ -281,13 +281,13 @@ public void Should_execute_delegate_and_put_value_in_cache_if_cache_does_not_hol
ISyncCacheProvider stubCacheProvider = new StubCacheProvider();
CachePolicy cache = Policy.Cache(stubCacheProvider, TimeSpan.MaxValue);

(bool cacheHit1, object fromCache1) = stubCacheProvider.TryGet(operationKey);
(bool cacheHit1, object? fromCache1) = stubCacheProvider.TryGet(operationKey);
cacheHit1.Should().BeFalse();
fromCache1.Should().BeNull();

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

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

(bool cacheHit, object fromCache) = stubCacheProvider.TryGet(operationKey);
(bool cacheHit, object? fromCache) = stubCacheProvider.TryGet(operationKey);
cacheHit.Should().BeFalse();
fromCache.Should().BeNull();
}
Expand Down Expand Up @@ -551,7 +551,7 @@ public void Should_call_onError_delegate_if_cache_put_errors()

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

(bool cacheHit1, object fromCache1) = stubCacheProvider.TryGet(operationKey);
(bool cacheHit1, object? fromCache1) = stubCacheProvider.TryGet(operationKey);
cacheHit1.Should().BeFalse();
fromCache1.Should().BeNull();

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

// failed to put it in the cache
(bool cacheHit2, object fromCache2) = stubCacheProvider.TryGet(operationKey);
(bool cacheHit2, object? fromCache2) = stubCacheProvider.TryGet(operationKey);
cacheHit2.Should().BeFalse();
fromCache2.Should().BeNull();

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

(bool cacheHit1, object fromCache1) = stubCacheProvider.TryGet(operationKey);
(bool cacheHit1, object? fromCache1) = stubCacheProvider.TryGet(operationKey);
cacheHit1.Should().BeFalse();
fromCache1.Should().BeNull();

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

(bool cacheHit2, object fromCache2) = stubCacheProvider.TryGet(operationKey);
(bool cacheHit2, object? fromCache2) = stubCacheProvider.TryGet(operationKey);
cacheHit2.Should().BeTrue();
fromCache2.Should().Be(valueToReturn);

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

(bool cacheHit, object fromCache) = stubCacheProvider.TryGet(operationKey);
(bool cacheHit, object? fromCache) = stubCacheProvider.TryGet(operationKey);
cacheHit.Should().BeFalse();
fromCache.Should().BeNull();

Expand Down
Loading

0 comments on commit aba7a34

Please sign in to comment.