2
2
using Polly . Contrib . Simmy . Utilities ;
3
3
using System ;
4
4
using System . Threading . Tasks ;
5
+ using Polly . Contrib . Simmy . Behavior . Options ;
5
6
using Xunit ;
6
7
7
8
namespace Polly . Contrib . Simmy . Specs . Behavior
@@ -25,16 +26,15 @@ public void Given_not_enabled_should_not_inject_behaviour()
25
26
Boolean userDelegateExecuted = false ;
26
27
Boolean injectedBehaviourExecuted = false ;
27
28
28
- var policy = MonkeyPolicy . InjectBehaviourAsync ( options =>
29
- {
30
- options . InjectionRate = 0.6 ;
31
- options . Enabled = ( ) => false ;
32
- options . Behaviour = ( ) =>
33
- {
34
- injectedBehaviourExecuted = true ;
35
- return Task . CompletedTask ;
36
- } ;
37
- } ) ;
29
+ var policy = MonkeyPolicy . InjectBehaviourAsync ( with =>
30
+ with . Behaviour ( ( ) =>
31
+ {
32
+ injectedBehaviourExecuted = true ;
33
+ return Task . CompletedTask ;
34
+ } )
35
+ . InjectionRate ( 0.6 )
36
+ . Enabled ( false )
37
+ ) ;
38
38
39
39
policy . ExecuteAsync ( ( ) => { userDelegateExecuted = true ; return Task . CompletedTask ; } ) ;
40
40
@@ -48,16 +48,15 @@ public void Given_enabled_and_randomly_within_threshold_should_inject_behaviour(
48
48
Boolean userDelegateExecuted = false ;
49
49
Boolean injectedBehaviourExecuted = false ;
50
50
51
- var policy = MonkeyPolicy . InjectBehaviourAsync ( options =>
52
- {
53
- options . InjectionRate = 0.6 ;
54
- options . Enabled = ( ) => true ;
55
- options . Behaviour = ( ) =>
56
- {
57
- injectedBehaviourExecuted = true ;
58
- return Task . CompletedTask ;
59
- } ;
60
- } ) ;
51
+ var policy = MonkeyPolicy . InjectBehaviourAsync ( with =>
52
+ with . Behaviour ( ( ) =>
53
+ {
54
+ injectedBehaviourExecuted = true ;
55
+ return Task . CompletedTask ;
56
+ } )
57
+ . InjectionRate ( 0.6 )
58
+ . Enabled ( )
59
+ ) ;
61
60
62
61
policy . ExecuteAsync ( ( ) => { userDelegateExecuted = true ; return Task . CompletedTask ; } ) ;
63
62
@@ -71,16 +70,15 @@ public void Given_enabled_and_randomly_not_within_threshold_should_not_inject_be
71
70
Boolean userDelegateExecuted = false ;
72
71
Boolean injectedBehaviourExecuted = false ;
73
72
74
- var policy = MonkeyPolicy . InjectBehaviourAsync ( options =>
75
- {
76
- options . InjectionRate = 0.4 ;
77
- options . Enabled = ( ) => true ;
78
- options . Behaviour = ( ) =>
79
- {
80
- injectedBehaviourExecuted = true ;
81
- return Task . CompletedTask ;
82
- } ;
83
- } ) ;
73
+ var policy = MonkeyPolicy . InjectBehaviourAsync ( with =>
74
+ with . Behaviour ( ( ) =>
75
+ {
76
+ injectedBehaviourExecuted = true ;
77
+ return Task . CompletedTask ;
78
+ } )
79
+ . InjectionRate ( 0.4 )
80
+ . Enabled ( false )
81
+ ) ;
84
82
85
83
policy . ExecuteAsync ( ( ) => { userDelegateExecuted = true ; return Task . CompletedTask ; } ) ;
86
84
@@ -94,17 +92,16 @@ public void Should_inject_behaviour_before_executing_user_delegate()
94
92
Boolean userDelegateExecuted = false ;
95
93
Boolean injectedBehaviourExecuted = false ;
96
94
97
- var policy = MonkeyPolicy . InjectBehaviourAsync ( options =>
98
- {
99
- options . InjectionRate = 0.6 ;
100
- options . Enabled = ( ) => true ;
101
- options . Behaviour = ( ) =>
102
- {
103
- userDelegateExecuted . Should ( ) . BeFalse ( ) ; // Not yet executed at the time the injected behaviour runs.
104
- injectedBehaviourExecuted = true ;
105
- return Task . CompletedTask ;
106
- } ;
107
- } ) ;
95
+ var policy = MonkeyPolicy . InjectBehaviourAsync ( with =>
96
+ with . Behaviour ( ( ) =>
97
+ {
98
+ userDelegateExecuted . Should ( ) . BeFalse ( ) ; // Not yet executed at the time the injected behaviour runs.
99
+ injectedBehaviourExecuted = true ;
100
+ return Task . CompletedTask ;
101
+ } )
102
+ . InjectionRate ( 0.6 )
103
+ . Enabled ( )
104
+ ) ;
108
105
109
106
policy . ExecuteAsync ( ( ) => { userDelegateExecuted = true ; return Task . CompletedTask ; } ) ;
110
107
0 commit comments