Skip to content

Commit

Permalink
add some missing asserts (#1002)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Jan 7, 2023
1 parent c874285 commit 55aaa7c
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 16 deletions.
4 changes: 4 additions & 0 deletions src/Polly.Specs/Caching/CacheAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,8 @@ public async Task Should_execute_oncachemiss_and_oncacheput_if_cache_does_not_ho

contextPassedToOnCachePut.Should().BeSameAs(contextToExecute);
keyPassedToOnCachePut.Should().Be(operationKey);
contextPassedToOnCacheMiss.Should().NotBeNull();
keyPassedToOnCacheMiss.Should().Be("SomeOperationKey");
}

[Fact]
Expand Down Expand Up @@ -675,6 +677,8 @@ public async Task Should_execute_oncachemiss_but_not_oncacheput_if_cache_does_no

contextPassedToOnCachePut.Should().BeNull();
keyPassedToOnCachePut.Should().BeNull();
contextPassedToOnCacheMiss.Should().BeEmpty();
keyPassedToOnCacheMiss.Should().Be("SomeOperationKey");
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2276,6 +2276,7 @@ await breaker.Awaiting(x => x.RaiseExceptionAsync<DivideByZeroException>())
// duration has passed, circuit now half open
breaker.CircuitState.Should().Be(CircuitState.HalfOpen);
onHalfOpenCalled.Should().Be(1);
onResetCalled.Should().Be(0);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2270,6 +2270,7 @@ public void Should_call_onhalfopen_when_automatically_transitioning_to_halfopen_
// duration has passed, circuit now half open
breaker.CircuitState.Should().Be(CircuitState.HalfOpen);
onHalfOpenCalled.Should().Be(1);
onResetCalled.Should().Be(0);
}

[Fact]
Expand Down
1 change: 1 addition & 0 deletions src/Polly.Specs/CircuitBreaker/CircuitBreakerAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,7 @@ await breaker.Awaiting(x => x.RaiseExceptionAsync<DivideByZeroException>())
// duration has passed, circuit now half open
breaker.CircuitState.Should().Be(CircuitState.HalfOpen);
onHalfOpenCalled.Should().Be(1);
onResetCalled.Should().Be(0);
}

[Fact]
Expand Down
1 change: 1 addition & 0 deletions src/Polly.Specs/CircuitBreaker/CircuitBreakerSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,7 @@ public void Should_call_onhalfopen_when_automatically_transitioning_to_halfopen_
// duration has passed, circuit now half open
breaker.CircuitState.Should().Be(CircuitState.HalfOpen);
onHalfOpenCalled.Should().Be(1);
onResetCalled.Should().Be(0);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,7 @@ await breaker.Awaiting(x => x.ExecuteAsync(() => Task.FromResult(ResultPrimitive
// duration has passed, circuit now half open
breaker.CircuitState.Should().Be(CircuitState.HalfOpen);
onHalfOpenCalled.Should().Be(1);
onResetCalled.Should().Be(0);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,7 @@ public void Should_call_onhalfopen_when_automatically_transitioning_to_halfopen_
// duration has passed, circuit now half open
breaker.CircuitState.Should().Be(CircuitState.HalfOpen);
onHalfOpenCalled.Should().Be(1);
onResetCalled.Should().Be(0);
}

[Fact]
Expand Down
28 changes: 19 additions & 9 deletions src/Polly.Specs/Registry/PolicyRegistrySpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,39 +268,42 @@ public void Should_be_able_to_retrieve_stored_Policy_by_interface_using_Indexer(
public void Should_not_throw_while_retrieving_when_key_does_not_exist_using_TryGet()
{
string key = Guid.NewGuid().ToString();
Policy outPolicy = null;
Policy policy = null;
bool result = false;

_registry.Invoking(r => result = r.TryGet(key, out outPolicy))
_registry.Invoking(r => result = r.TryGet(key, out policy))
.Should().NotThrow();

result.Should().BeFalse();
policy.Should().BeNull();
}

[Fact]
public void Should_not_throw_while_retrieving_when_key_does_not_exist_using_TryGetPolicyTResult()
{
string key = Guid.NewGuid().ToString();
Policy<ResultPrimitive> outPolicy = null;
Policy<ResultPrimitive> policy = null;
bool result = false;

_registry.Invoking(r => result = r.TryGet(key, out outPolicy))
_registry.Invoking(r => result = r.TryGet(key, out policy))
.Should().NotThrow();

result.Should().BeFalse();
policy.Should().BeNull();
}

[Fact]
public void Should_not_throw_while_retrieving_when_key_does_not_exist_using_TryGetPolicy_by_interface()
{
string key = Guid.NewGuid().ToString();
ISyncPolicy<ResultPrimitive> outPolicy = null;
ISyncPolicy<ResultPrimitive> policy = null;
bool result = false;

_registry.Invoking(r => result = r.TryGet<ISyncPolicy<ResultPrimitive>>(key, out outPolicy))
_registry.Invoking(r => result = r.TryGet<ISyncPolicy<ResultPrimitive>>(key, out policy))
.Should().NotThrow();

result.Should().BeFalse();
policy.Should().BeNull();
}

[Fact]
Expand All @@ -310,6 +313,7 @@ public void Should_throw_while_retrieving_using_Get_when_key_does_not_exist()
Policy policy = null;
_registry.Invoking(r => policy = r.Get<Policy>(key))
.Should().Throw<KeyNotFoundException>();
policy.Should().BeNull();
}

[Fact]
Expand All @@ -319,6 +323,7 @@ public void Should_throw_while_retrieving_using_GetTResult_when_key_does_not_exi
Policy<ResultPrimitive> policy = null;
_registry.Invoking(r => policy = r.Get<Policy<ResultPrimitive>>(key))
.Should().Throw<KeyNotFoundException>();
policy.Should().BeNull();
}

[Fact]
Expand All @@ -328,25 +333,27 @@ public void Should_throw_while_retrieving_using_Get_by_interface_when_key_does_n
ISyncPolicy<ResultPrimitive> policy = null;
_registry.Invoking(r => policy = r.Get<ISyncPolicy<ResultPrimitive>>(key))
.Should().Throw<KeyNotFoundException>();
policy.Should().BeNull();
}

[Fact]
public void Should_throw_while_retrieving_when_key_does_not_exist_using_Indexer()
{
string key = Guid.NewGuid().ToString();
IsPolicy outPolicy = null;
_registry.Invoking(r => outPolicy = r[key])
IsPolicy policy = null;
_registry.Invoking(r => policy = r[key])
.Should().Throw<KeyNotFoundException>();
policy.Should().BeNull();
}


[Fact]
public void Should_throw_when_retrieving_using_Get_when_key_is_null()
{
string key = null;
Policy policy = null;
_registry.Invoking(r => policy = r.Get<Policy>(key))
.Should().Throw<ArgumentNullException>();
policy.Should().BeNull();
}

[Fact]
Expand All @@ -356,6 +363,7 @@ public void Should_throw_when_retrieving_using_GetTResult_when_key_is_null()
Policy<ResultPrimitive> policy = null;
_registry.Invoking(r => policy = r.Get<Policy<ResultPrimitive>>(key))
.Should().Throw<ArgumentNullException>();
policy.Should().BeNull();
}

[Fact]
Expand All @@ -365,6 +373,7 @@ public void Should_throw_when_retrieving_using_Get_by_interface_when_key_is_null
ISyncPolicy<ResultPrimitive> policy = null;
_registry.Invoking(r => policy = r.Get<ISyncPolicy<ResultPrimitive>>(key))
.Should().Throw<ArgumentNullException>();
policy.Should().BeNull();
}

[Fact]
Expand All @@ -374,6 +383,7 @@ public void Should_throw_when_retrieving_using_Indexer_when_key_is_null()
IsPolicy policy = null;
_registry.Invoking(r => policy = r[key])
.Should().Throw<ArgumentNullException>();
policy.Should().BeNull();
}
#endregion

Expand Down
24 changes: 17 additions & 7 deletions src/Polly.Specs/Registry/ReadOnlyPolicyRegistrySpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,39 +121,42 @@ public void Should_be_able_to_retrieve_stored_Policy_by_interface_using_Indexer(
public void Should_not_throw_while_retrieving_when_key_does_not_exist_using_TryGet()
{
string key = Guid.NewGuid().ToString();
Policy outPolicy = null;
Policy policy = null;
bool result = false;

ReadOnlyRegistry.Invoking(r => result = r.TryGet(key, out outPolicy))
ReadOnlyRegistry.Invoking(r => result = r.TryGet(key, out policy))
.Should().NotThrow();

result.Should().BeFalse();
policy.Should().BeNull();
}

[Fact]
public void Should_not_throw_while_retrieving_when_key_does_not_exist_using_TryGetPolicyTResult()
{
string key = Guid.NewGuid().ToString();
Policy<ResultPrimitive> outPolicy = null;
Policy<ResultPrimitive> policy = null;
bool result = false;

ReadOnlyRegistry.Invoking(r => result = r.TryGet(key, out outPolicy))
ReadOnlyRegistry.Invoking(r => result = r.TryGet(key, out policy))
.Should().NotThrow();

result.Should().BeFalse();
policy.Should().BeNull();
}

[Fact]
public void Should_not_throw_while_retrieving_when_key_does_not_exist_using_TryGetPolicy_by_interface()
{
string key = Guid.NewGuid().ToString();
ISyncPolicy<ResultPrimitive> outPolicy = null;
ISyncPolicy<ResultPrimitive> policy = null;
bool result = false;

ReadOnlyRegistry.Invoking(r => result = r.TryGet<ISyncPolicy<ResultPrimitive>>(key, out outPolicy))
ReadOnlyRegistry.Invoking(r => result = r.TryGet<ISyncPolicy<ResultPrimitive>>(key, out policy))
.Should().NotThrow();

result.Should().BeFalse();
policy.Should().BeNull();
}

[Fact]
Expand All @@ -163,6 +166,7 @@ public void Should_throw_while_retrieving_using_Get_when_key_does_not_exist()
Policy policy = null;
ReadOnlyRegistry.Invoking(r => policy = r.Get<Policy>(key))
.Should().Throw<KeyNotFoundException>();
policy.Should().BeNull();
}

[Fact]
Expand All @@ -172,6 +176,7 @@ public void Should_throw_while_retrieving_using_GetTResult_when_key_does_not_exi
Policy<ResultPrimitive> policy = null;
ReadOnlyRegistry.Invoking(r => policy = r.Get<Policy<ResultPrimitive>>(key))
.Should().Throw<KeyNotFoundException>();
policy.Should().BeNull();
}

[Fact]
Expand All @@ -181,6 +186,7 @@ public void Should_throw_while_retrieving_using_Get_by_interface_when_key_does_n
ISyncPolicy<ResultPrimitive> policy = null;
ReadOnlyRegistry.Invoking(r => policy = r.Get<ISyncPolicy<ResultPrimitive>>(key))
.Should().Throw<KeyNotFoundException>();
policy.Should().BeNull();
}

[Fact]
Expand All @@ -190,16 +196,17 @@ public void Should_throw_while_retrieving_when_key_does_not_exist_using_Indexer(
IsPolicy outPolicy = null;
ReadOnlyRegistry.Invoking(r => outPolicy = r[key])
.Should().Throw<KeyNotFoundException>();
outPolicy.Should().BeNull();
}


[Fact]
public void Should_throw_when_retrieving_using_Get_when_key_is_null()
{
string key = null;
Policy policy = null;
ReadOnlyRegistry.Invoking(r => policy = r.Get<Policy>(key))
.Should().Throw<ArgumentNullException>();
policy.Should().BeNull();
}

[Fact]
Expand All @@ -209,6 +216,7 @@ public void Should_throw_when_retrieving_using_GetTResult_when_key_is_null()
Policy<ResultPrimitive> policy = null;
ReadOnlyRegistry.Invoking(r => policy = r.Get<Policy<ResultPrimitive>>(key))
.Should().Throw<ArgumentNullException>();
policy.Should().BeNull();
}

[Fact]
Expand All @@ -218,6 +226,7 @@ public void Should_throw_when_retrieving_using_Get_by_interface_when_key_is_null
ISyncPolicy<ResultPrimitive> policy = null;
ReadOnlyRegistry.Invoking(r => policy = r.Get<ISyncPolicy<ResultPrimitive>>(key))
.Should().Throw<ArgumentNullException>();
policy.Should().BeNull();
}

[Fact]
Expand All @@ -227,6 +236,7 @@ public void Should_throw_when_retrieving_using_Indexer_when_key_is_null()
IsPolicy policy = null;
ReadOnlyRegistry.Invoking(r => policy = r[key])
.Should().Throw<ArgumentNullException>();
policy.Should().BeNull();
}
#endregion

Expand Down

0 comments on commit 55aaa7c

Please sign in to comment.