Skip to content
Merged
8 changes: 4 additions & 4 deletions src/Polly.Specs/Bulkhead/BulkheadAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public async Task Should_call_onBulkheadRejected_with_passed_context()
string operationKey = "SomeKey";
Context contextPassedToExecute = new Context(operationKey);

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

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

contextPassedToOnRejected.Should().NotBeNull();
contextPassedToOnRejected.OperationKey.Should().Be(operationKey);
contextPassedToOnRejected.Should().BeSameAs(contextPassedToExecute);
contextPassedToOnRejected!.Should().NotBeNull();
contextPassedToOnRejected!.OperationKey.Should().Be(operationKey);
contextPassedToOnRejected!.Should().BeSameAs(contextPassedToExecute);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/Polly.Specs/Bulkhead/BulkheadSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void Should_call_onBulkheadRejected_with_passed_context()
string operationKey = "SomeKey";
Context contextPassedToExecute = new Context(operationKey);

Context contextPassedToOnRejected = null;
Context? contextPassedToOnRejected = null;
Action<Context> onRejected = ctx => { contextPassedToOnRejected = ctx; };

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

tcs.SetCanceled();

contextPassedToOnRejected.Should().NotBeNull();
contextPassedToOnRejected.OperationKey.Should().Be(operationKey);
contextPassedToOnRejected.Should().BeSameAs(contextPassedToExecute);
contextPassedToOnRejected!.Should().NotBeNull();
contextPassedToOnRejected!.OperationKey.Should().Be(operationKey);
contextPassedToOnRejected!.Should().BeSameAs(contextPassedToExecute);
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/Polly.Specs/Bulkhead/BulkheadSpecsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ public BulkheadSpecsBase(ITestOutputHelper testOutputHelper)

#region Operating variables

protected IBulkheadPolicy BulkheadForStats { get; set; }
protected IBulkheadPolicy BulkheadForStats { get; set; } = null!;

internal TraceableAction[] Actions { get; set; }
internal TraceableAction[] Actions { get; set; } = { };

protected Task[] Tasks { get; set; }
protected Task[] Tasks { get; set; } = { };

protected readonly AutoResetEvent StatusChangedEvent = new AutoResetEvent(false);

#endregion

#region Scenario

protected string Scenario { get; set; }
protected string? Scenario { get; set; }

protected int MaxParallelization { get; set; }
protected int MaxQueuingActions { get; set; }
Expand Down Expand Up @@ -236,7 +236,7 @@ protected void UpdateActuals()
}
}

protected AssertionFailure ActualsMatchExpecteds()
protected AssertionFailure? ActualsMatchExpecteds()
{
UpdateActuals();

Expand Down Expand Up @@ -283,7 +283,7 @@ protected AssertionFailure ActualsMatchExpecteds()
return null;
}

protected AssertionFailure AllTasksCompleted()
protected AssertionFailure? AllTasksCompleted()
{
int countTasksCompleted = Tasks.Count(t => t.IsCompleted);
if (countTasksCompleted < TotalActions)
Expand Down Expand Up @@ -311,13 +311,13 @@ protected void EnsureNoUnbservedTaskExceptions()

#endregion

protected AssertionFailure Expect(int expected, Func<int> actualFunc, string measure)
protected AssertionFailure? Expect(int expected, Func<int> actualFunc, string measure)
{
int actual = actualFunc();
return actual != expected ? new AssertionFailure(expected, actual, measure) : null;
}

protected void Within(TimeSpan timeSpan, Func<AssertionFailure> actionContainingAssertions)
protected void Within(TimeSpan timeSpan, Func<AssertionFailure?> actionContainingAssertions)
{
TimeSpan permitted = timeSpan;
Stopwatch watch = Stopwatch.StartNew();
Expand Down
9 changes: 4 additions & 5 deletions src/Polly.Specs/Bulkhead/BulkheadTResultAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public async Task Should_call_onBulkheadRejected_with_passed_context()
string operationKey = "SomeKey";
Context contextPassedToExecute = new Context(operationKey);

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

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

contextPassedToOnRejected.Should().NotBeNull();
contextPassedToOnRejected.OperationKey.Should().Be(operationKey);
contextPassedToOnRejected.Should().BeSameAs(contextPassedToExecute);

contextPassedToOnRejected!.Should().NotBeNull();
contextPassedToOnRejected!.OperationKey.Should().Be(operationKey);
contextPassedToOnRejected!.Should().BeSameAs(contextPassedToExecute);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/Polly.Specs/Bulkhead/BulkheadTResultSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void Should_call_onBulkheadRejected_with_passed_context()
string operationKey = "SomeKey";
Context contextPassedToExecute = new Context(operationKey);

Context contextPassedToOnRejected = null;
Context? contextPassedToOnRejected = null;
Action<Context> onRejected = ctx => { contextPassedToOnRejected = ctx; };

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

contextPassedToOnRejected.Should().NotBeNull();
contextPassedToOnRejected.OperationKey.Should().Be(operationKey);
contextPassedToOnRejected.Should().BeSameAs(contextPassedToExecute);
contextPassedToOnRejected!.Should().NotBeNull();
contextPassedToOnRejected!.OperationKey.Should().Be(operationKey);
contextPassedToOnRejected!.Should().BeSameAs(contextPassedToExecute);
}
}

Expand Down
34 changes: 17 additions & 17 deletions src/Polly.Specs/Caching/CacheAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class CacheAsyncSpecs : IDisposable
[Fact]
public void Should_throw_when_cache_provider_is_null()
{
IAsyncCacheProvider cacheProvider = null;
IAsyncCacheProvider cacheProvider = null!;
Action action = () => Policy.CacheAsync(cacheProvider, TimeSpan.MaxValue);
action.Should().Throw<ArgumentNullException>().And.ParamName.Should().Be("cacheProvider");
}
Expand All @@ -27,7 +27,7 @@ public void Should_throw_when_cache_provider_is_null()
public void Should_throw_when_ttl_strategy_is_null()
{
IAsyncCacheProvider cacheProvider = new StubCacheProvider();
ITtlStrategy ttlStrategy = null;
ITtlStrategy ttlStrategy = null!;
Action action = () => Policy.CacheAsync(cacheProvider, ttlStrategy);
action.Should().Throw<ArgumentNullException>().And.ParamName.Should().Be("ttlStrategy");
}
Expand All @@ -36,7 +36,7 @@ public void Should_throw_when_ttl_strategy_is_null()
public void Should_throw_when_cache_key_strategy_is_null()
{
IAsyncCacheProvider cacheProvider = new StubCacheProvider();
Func<Context, string> cacheKeyStrategy = null;
Func<Context, string>? cacheKeyStrategy = null;
Action action = () => Policy.CacheAsync(cacheProvider, TimeSpan.MaxValue, cacheKeyStrategy);
action.Should().Throw<ArgumentNullException>().And.ParamName.Should().Be("cacheKeyStrategy");
}
Expand Down Expand Up @@ -234,7 +234,7 @@ public async Task Should_allow_custom_ICacheKeyStrategy()
[Fact]
public async Task Should_execute_delegate_and_put_value_in_cache_if_cache_does_not_hold_value__default_for_reference_type()
{
ResultClass valueToReturn = default;
ResultClass? valueToReturn = null;
const string operationKey = "SomeOperationKey";

IAsyncCacheProvider stubCacheProvider = new StubCacheProvider();
Expand All @@ -254,7 +254,7 @@ public async Task Should_execute_delegate_and_put_value_in_cache_if_cache_does_n
[Fact]
public async Task Should_return_value_from_cache_and_not_execute_delegate_if_cache_holds_value__default_for_reference_type()
{
ResultClass valueToReturnFromCache = default;
ResultClass? valueToReturnFromCache = null;
ResultClass valueToReturnFromExecution = new ResultClass(ResultPrimitive.Good);
const string operationKey = "SomeOperationKey";

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

Exception exceptionFromCacheProvider = null;
Exception? exceptionFromCacheProvider = null;

const string valueToReturnFromCache = "valueToReturnFromCache";
const string valueToReturnFromExecution = "valueToReturnFromExecution";
Expand Down Expand Up @@ -553,7 +553,7 @@ public async Task Should_call_onError_delegate_if_cache_put_errors()
Exception ex = new Exception();
IAsyncCacheProvider stubCacheProvider = new StubErroringCacheProvider(getException: null, putException: ex);

Exception exceptionFromCacheProvider = null;
Exception? exceptionFromCacheProvider = null;

const string valueToReturn = "valueToReturn";
const string operationKey = "SomeOperationKey";
Expand Down Expand Up @@ -584,10 +584,10 @@ public async Task Should_execute_oncacheget_after_got_from_cache()
const string valueToReturnFromExecution = "valueToReturnFromExecution";

const string operationKey = "SomeOperationKey";
string keyPassedToDelegate = null;
string? keyPassedToDelegate = null;

Context contextToExecute = new Context(operationKey);
Context contextPassedToDelegate = null;
Context? contextPassedToDelegate = null;

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

const string operationKey = "SomeOperationKey";
string keyPassedToOnCacheMiss = null;
string keyPassedToOnCachePut = null;
string? keyPassedToOnCacheMiss = null;
string? keyPassedToOnCachePut = null;

Context contextToExecute = new Context(operationKey);
Context contextPassedToOnCacheMiss = null;
Context contextPassedToOnCachePut = null;
Context? contextPassedToOnCacheMiss = null;
Context? contextPassedToOnCachePut = null;

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

const string operationKey = "SomeOperationKey";
string keyPassedToOnCacheMiss = null;
string keyPassedToOnCachePut = null;
string? keyPassedToOnCacheMiss = null;
string? keyPassedToOnCachePut = null;

Context contextToExecute = new Context(operationKey);
Context contextPassedToOnCacheMiss = null;
Context contextPassedToOnCachePut = null;
Context? contextPassedToOnCacheMiss = null;
Context? contextPassedToOnCachePut = null;

Action<Context, string, Exception> noErrorHandling = (_, _, _) => { };
Action<Context, string> emptyDelegate = (_, _) => { };
Expand Down
34 changes: 17 additions & 17 deletions src/Polly.Specs/Caching/CacheSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class CacheSpecs : IDisposable
[Fact]
public void Should_throw_when_cache_provider_is_null()
{
ISyncCacheProvider cacheProvider = null;
ISyncCacheProvider? cacheProvider = null;
Action action = () => Policy.Cache(cacheProvider, TimeSpan.MaxValue);
action.Should().Throw<ArgumentNullException>().And.ParamName.Should().Be("cacheProvider");
}
Expand All @@ -27,7 +27,7 @@ public void Should_throw_when_cache_provider_is_null()
public void Should_throw_when_ttl_strategy_is_null()
{
ISyncCacheProvider cacheProvider = new StubCacheProvider();
ITtlStrategy ttlStrategy = null;
ITtlStrategy? ttlStrategy = null;
Action action = () => Policy.Cache(cacheProvider, ttlStrategy);
action.Should().Throw<ArgumentNullException>().And.ParamName.Should().Be("ttlStrategy");
}
Expand All @@ -36,7 +36,7 @@ public void Should_throw_when_ttl_strategy_is_null()
public void Should_throw_when_cache_key_strategy_is_null()
{
ISyncCacheProvider cacheProvider = new StubCacheProvider();
Func<Context, string> cacheKeyStrategy = null;
Func<Context, string> cacheKeyStrategy = null!;
Action action = () => Policy.Cache(cacheProvider, TimeSpan.MaxValue, cacheKeyStrategy);
action.Should().Throw<ArgumentNullException>().And.ParamName.Should().Be("cacheKeyStrategy");
}
Expand Down Expand Up @@ -232,7 +232,7 @@ public void Should_allow_custom_ICacheKeyStrategy()
[Fact]
public void Should_execute_delegate_and_put_value_in_cache_if_cache_does_not_hold_value__default_for_reference_type()
{
ResultClass valueToReturn = default;
ResultClass? valueToReturn = null;
const string operationKey = "SomeOperationKey";

ISyncCacheProvider stubCacheProvider = new StubCacheProvider();
Expand All @@ -252,7 +252,7 @@ public void Should_execute_delegate_and_put_value_in_cache_if_cache_does_not_hol
[Fact]
public void Should_return_value_from_cache_and_not_execute_delegate_if_cache_holds_value__default_for_reference_type()
{
ResultClass valueToReturnFromCache = default;
ResultClass? valueToReturnFromCache = null;
ResultClass valueToReturnFromExecution = new ResultClass(ResultPrimitive.Good);
const string operationKey = "SomeOperationKey";

Expand Down Expand Up @@ -508,7 +508,7 @@ public void Should_call_onError_delegate_if_cache_get_errors()
Exception ex = new Exception();
ISyncCacheProvider stubCacheProvider = new StubErroringCacheProvider(getException: ex, putException: null);

Exception exceptionFromCacheProvider = null;
Exception? exceptionFromCacheProvider = null;

const string valueToReturnFromCache = "valueToReturnFromCache";
const string valueToReturnFromExecution = "valueToReturnFromExecution";
Expand Down Expand Up @@ -542,7 +542,7 @@ public void Should_call_onError_delegate_if_cache_put_errors()
Exception ex = new Exception();
ISyncCacheProvider stubCacheProvider = new StubErroringCacheProvider(getException: null, putException: ex);

Exception exceptionFromCacheProvider = null;
Exception? exceptionFromCacheProvider = null;

const string valueToReturn = "valueToReturn";
const string operationKey = "SomeOperationKey";
Expand Down Expand Up @@ -574,10 +574,10 @@ public void Should_execute_oncacheget_after_got_from_cache()
const string valueToReturnFromExecution = "valueToReturnFromExecution";

const string operationKey = "SomeOperationKey";
string keyPassedToDelegate = null;
string? keyPassedToDelegate = null;

Context contextToExecute = new Context(operationKey);
Context contextPassedToDelegate = null;
Context? contextPassedToDelegate = null;

Action<Context, string, Exception> noErrorHandling = (_, _, _) => { };
Action<Context, string> emptyDelegate = (_, _) => { };
Expand Down Expand Up @@ -606,12 +606,12 @@ public void Should_execute_oncachemiss_and_oncacheput_if_cache_does_not_hold_val
const string valueToReturn = "valueToReturn";

const string operationKey = "SomeOperationKey";
string keyPassedToOnCacheMiss = null;
string keyPassedToOnCachePut = null;
string? keyPassedToOnCacheMiss = null;
string? keyPassedToOnCachePut = null;

Context contextToExecute = new Context(operationKey);
Context contextPassedToOnCacheMiss = null;
Context contextPassedToOnCachePut = null;
Context? contextPassedToOnCacheMiss = null;
Context? contextPassedToOnCachePut = null;

Action<Context, string, Exception> noErrorHandling = (_, _, _) => { };
Action<Context, string> emptyDelegate = (_, _) => { };
Expand Down Expand Up @@ -644,12 +644,12 @@ public void Should_execute_oncachemiss_but_not_oncacheput_if_cache_does_not_hold
const string valueToReturn = "valueToReturn";

const string operationKey = "SomeOperationKey";
string keyPassedToOnCacheMiss = null;
string keyPassedToOnCachePut = null;
string? keyPassedToOnCacheMiss = null;
string? keyPassedToOnCachePut = null;

Context contextToExecute = new Context(operationKey);
Context contextPassedToOnCacheMiss = null;
Context contextPassedToOnCachePut = null;
Context? contextPassedToOnCacheMiss = null;
Context? contextPassedToOnCachePut = null;

Action<Context, string, Exception> noErrorHandling = (_, _, _) => { };
Action<Context, string> emptyDelegate = (_, _) => { };
Expand Down
Loading