@@ -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- }
0 commit comments