Skip to content

Commit c542b0e

Browse files
authored
Fix SA1649 warnings (#2173)
1 parent e622a7d commit c542b0e

File tree

7 files changed

+287
-285
lines changed

7 files changed

+287
-285
lines changed

test/Polly.Specs/PolicyContextAndKeyAsyncSpecs.cs renamed to test/Polly.Specs/PolicyKeyAsyncSpecs.cs

Lines changed: 0 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -202,151 +202,3 @@ await retry.ExecuteAsync<int>(async _ =>
202202
}
203203
#endregion
204204
}
205-
206-
public class PolicyTResultKeyAsyncSpecs
207-
{
208-
#region Configuration
209-
210-
[Fact]
211-
public void Should_be_able_fluently_to_configure_the_policy_key()
212-
{
213-
var policy = Policy.HandleResult<int>(0).RetryAsync().WithPolicyKey(Guid.NewGuid().ToString());
214-
215-
policy.Should().BeAssignableTo<AsyncPolicy<int>>();
216-
}
217-
218-
[Fact]
219-
public void Should_be_able_fluently_to_configure_the_policy_key_via_interface()
220-
{
221-
IAsyncPolicy<int> policyAsInterface = Policy.HandleResult<int>(0).RetryAsync();
222-
var policyAsInterfaceAfterWithPolicyKey = policyAsInterface.WithPolicyKey(Guid.NewGuid().ToString());
223-
224-
policyAsInterfaceAfterWithPolicyKey.Should().BeAssignableTo<IAsyncPolicy<int>>();
225-
}
226-
227-
[Fact]
228-
public void PolicyKey_property_should_be_the_fluently_configured_policy_key()
229-
{
230-
const string Key = "SomePolicyKey";
231-
232-
var policy = Policy.HandleResult(0).RetryAsync().WithPolicyKey(Key);
233-
234-
policy.PolicyKey.Should().Be(Key);
235-
}
236-
237-
[Fact]
238-
public void Should_not_be_able_to_configure_the_policy_key_explicitly_more_than_once()
239-
{
240-
var policy = Policy.HandleResult(0).RetryAsync();
241-
242-
Action configure = () => policy.WithPolicyKey(Guid.NewGuid().ToString());
243-
244-
configure.Should().NotThrow();
245-
246-
configure.Should().Throw<ArgumentException>().And.ParamName.Should().Be("policyKey");
247-
}
248-
249-
[Fact]
250-
public void Should_not_be_able_to_configure_the_policy_key_explicitly_more_than_once_via_interface()
251-
{
252-
IAsyncPolicy<int> policyAsInterface = Policy.HandleResult(0).RetryAsync();
253-
Action configure = () => policyAsInterface.WithPolicyKey(Guid.NewGuid().ToString());
254-
255-
configure.Should().NotThrow();
256-
257-
configure.Should().Throw<ArgumentException>().And.ParamName.Should().Be("policyKey");
258-
}
259-
260-
[Fact]
261-
public void PolicyKey_property_should_be_non_null_or_empty_if_not_explicitly_configured()
262-
{
263-
var policy = Policy.HandleResult(0).RetryAsync();
264-
265-
policy.PolicyKey.Should().NotBeNullOrEmpty();
266-
}
267-
268-
[Fact]
269-
public void PolicyKey_property_should_start_with_policy_type_if_not_explicitly_configured()
270-
{
271-
var policy = Policy.HandleResult(0).RetryAsync();
272-
273-
policy.PolicyKey.Should().StartWith("AsyncRetry");
274-
}
275-
276-
[Fact]
277-
public void PolicyKey_property_should_be_unique_for_different_instances_if_not_explicitly_configured()
278-
{
279-
var policy1 = Policy.HandleResult(0).RetryAsync();
280-
var policy2 = Policy.HandleResult(0).RetryAsync();
281-
282-
policy1.PolicyKey.Should().NotBe(policy2.PolicyKey);
283-
}
284-
285-
[Fact]
286-
public void PolicyKey_property_should_return_consistent_value_for_same_policy_instance_if_not_explicitly_configured()
287-
{
288-
var policy = Policy.HandleResult(0).RetryAsync();
289-
290-
var keyRetrievedFirst = policy.PolicyKey;
291-
var keyRetrievedSecond = policy.PolicyKey;
292-
293-
keyRetrievedSecond.Should().Be(keyRetrievedFirst);
294-
}
295-
296-
[Fact]
297-
public void Should_not_be_able_to_configure_the_policy_key_explicitly_after_retrieving_default_value()
298-
{
299-
var policy = Policy.HandleResult(0).RetryAsync();
300-
301-
string retrieveKeyWhenNotExplicitlyConfigured = policy.PolicyKey;
302-
303-
Action configure = () => policy.WithPolicyKey(Guid.NewGuid().ToString());
304-
305-
configure.Should().Throw<ArgumentException>().And.ParamName.Should().Be("policyKey");
306-
}
307-
308-
#endregion
309-
310-
#region PolicyKey and execution Context tests
311-
312-
[Fact]
313-
public async Task Should_pass_PolicyKey_to_execution_context()
314-
{
315-
string policyKey = Guid.NewGuid().ToString();
316-
317-
string? policyKeySetOnExecutionContext = null;
318-
Action<DelegateResult<ResultPrimitive>, int, Context> onRetry = (_, _, context) => { policyKeySetOnExecutionContext = context.PolicyKey; };
319-
var retry = Policy.HandleResult(ResultPrimitive.Fault).RetryAsync(1, onRetry).WithPolicyKey(policyKey);
320-
321-
await retry.RaiseResultSequenceAsync(ResultPrimitive.Fault, ResultPrimitive.Good);
322-
323-
policyKeySetOnExecutionContext.Should().Be(policyKey);
324-
}
325-
326-
[Fact]
327-
public async Task Should_pass_OperationKey_to_execution_context()
328-
{
329-
string operationKey = "SomeKey";
330-
331-
string? operationKeySetOnContext = null;
332-
Action<DelegateResult<ResultPrimitive>, int, Context> onRetry = (_, _, context) => { operationKeySetOnContext = context.OperationKey; };
333-
var retry = Policy.HandleResult(ResultPrimitive.Fault).RetryAsync(1, onRetry);
334-
335-
bool firstExecution = true;
336-
await retry.ExecuteAsync(async _ =>
337-
{
338-
await TaskHelper.EmptyTask;
339-
if (firstExecution)
340-
{
341-
firstExecution = false;
342-
return ResultPrimitive.Fault;
343-
}
344-
345-
return ResultPrimitive.Good;
346-
}, new Context(operationKey));
347-
348-
operationKeySetOnContext.Should().Be(operationKey);
349-
}
350-
351-
#endregion
352-
}

test/Polly.Specs/PolicyContextAndKeySpecs.cs renamed to test/Polly.Specs/PolicyKeySpecs.cs

Lines changed: 0 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -180,139 +180,3 @@ public void Should_pass_OperationKey_to_execution_context_in_generic_execution_o
180180
}
181181
#endregion
182182
}
183-
184-
public class PolicyTResultKeySpecs
185-
{
186-
#region Configuration
187-
188-
[Fact]
189-
public void Should_be_able_fluently_to_configure_the_policy_key()
190-
{
191-
var policy = Policy.HandleResult<int>(0).Retry().WithPolicyKey(Guid.NewGuid().ToString());
192-
193-
policy.Should().BeAssignableTo<Policy<int>>();
194-
}
195-
196-
[Fact]
197-
public void Should_be_able_fluently_to_configure_the_policy_key_via_interface()
198-
{
199-
ISyncPolicy<int> policyAsInterface = Policy.HandleResult<int>(0).Retry();
200-
var policyAsInterfaceAfterWithPolicyKey = policyAsInterface.WithPolicyKey(Guid.NewGuid().ToString());
201-
202-
policyAsInterfaceAfterWithPolicyKey.Should().BeAssignableTo<ISyncPolicy<int>>();
203-
}
204-
205-
[Fact]
206-
public void PolicyKey_property_should_be_the_fluently_configured_policy_key()
207-
{
208-
const string Key = "SomePolicyKey";
209-
210-
var policy = Policy.HandleResult(0).Retry().WithPolicyKey(Key);
211-
212-
policy.PolicyKey.Should().Be(Key);
213-
}
214-
215-
[Fact]
216-
public void Should_not_be_able_to_configure_the_policy_key_explicitly_more_than_once()
217-
{
218-
var policy = Policy.HandleResult(0).Retry();
219-
220-
Action configure = () => policy.WithPolicyKey(Guid.NewGuid().ToString());
221-
222-
configure.Should().NotThrow();
223-
224-
configure.Should().Throw<ArgumentException>().And.ParamName.Should().Be("policyKey");
225-
}
226-
227-
[Fact]
228-
public void PolicyKey_property_should_be_non_null_or_empty_if_not_explicitly_configured()
229-
{
230-
var policy = Policy.HandleResult(0).Retry();
231-
232-
policy.PolicyKey.Should().NotBeNullOrEmpty();
233-
}
234-
235-
[Fact]
236-
public void PolicyKey_property_should_start_with_policy_type_if_not_explicitly_configured()
237-
{
238-
var policy = Policy.HandleResult(0).Retry();
239-
240-
policy.PolicyKey.Should().StartWith("Retry");
241-
}
242-
243-
[Fact]
244-
public void PolicyKey_property_should_be_unique_for_different_instances_if_not_explicitly_configured()
245-
{
246-
var policy1 = Policy.HandleResult(0).Retry();
247-
var policy2 = Policy.HandleResult(0).Retry();
248-
249-
policy1.PolicyKey.Should().NotBe(policy2.PolicyKey);
250-
}
251-
252-
[Fact]
253-
public void PolicyKey_property_should_return_consistent_value_for_same_policy_instance_if_not_explicitly_configured()
254-
{
255-
var policy = Policy.HandleResult(0).Retry();
256-
257-
var keyRetrievedFirst = policy.PolicyKey;
258-
var keyRetrievedSecond = policy.PolicyKey;
259-
260-
keyRetrievedSecond.Should().Be(keyRetrievedFirst);
261-
}
262-
263-
[Fact]
264-
public void Should_not_be_able_to_configure_the_policy_key_explicitly_after_retrieving_default_value()
265-
{
266-
var policy = Policy.HandleResult(0).Retry();
267-
268-
string retrieveKeyWhenNotExplicitlyConfigured = policy.PolicyKey;
269-
270-
Action configure = () => policy.WithPolicyKey(Guid.NewGuid().ToString());
271-
272-
configure.Should().Throw<ArgumentException>().And.ParamName.Should().Be("policyKey");
273-
}
274-
275-
#endregion
276-
277-
#region PolicyKey and execution Context tests
278-
279-
[Fact]
280-
public void Should_pass_PolicyKey_to_execution_context()
281-
{
282-
string policyKey = Guid.NewGuid().ToString();
283-
284-
string? policyKeySetOnExecutionContext = null;
285-
Action<DelegateResult<ResultPrimitive>, int, Context> onRetry = (_, _, context) => { policyKeySetOnExecutionContext = context.PolicyKey; };
286-
var retry = Policy.HandleResult(ResultPrimitive.Fault).Retry(1, onRetry).WithPolicyKey(policyKey);
287-
288-
retry.RaiseResultSequence(ResultPrimitive.Fault, ResultPrimitive.Good);
289-
290-
policyKeySetOnExecutionContext.Should().Be(policyKey);
291-
}
292-
293-
[Fact]
294-
public void Should_pass_OperationKey_to_execution_context()
295-
{
296-
string operationKey = "SomeKey";
297-
298-
string? operationKeySetOnContext = null;
299-
Action<DelegateResult<ResultPrimitive>, int, Context> onRetry = (_, _, context) => { operationKeySetOnContext = context.OperationKey; };
300-
var retry = Policy.HandleResult(ResultPrimitive.Fault).Retry(1, onRetry);
301-
302-
bool firstExecution = true;
303-
retry.Execute(_ =>
304-
{
305-
if (firstExecution)
306-
{
307-
firstExecution = false;
308-
return ResultPrimitive.Fault;
309-
}
310-
311-
return ResultPrimitive.Good;
312-
}, new Context(operationKey));
313-
314-
operationKeySetOnContext.Should().Be(operationKey);
315-
}
316-
317-
#endregion
318-
}

0 commit comments

Comments
 (0)