@@ -109,6 +109,60 @@ public void Should_inject_behaviour_before_executing_user_delegate()
109
109
injectedBehaviourExecuted . Should ( ) . BeTrue ( ) ;
110
110
}
111
111
112
+ #region BeforeInject
113
+ [ Fact ]
114
+ public async Task Should_call_before_inject_callback_before_injecting_behavior ( )
115
+ {
116
+ var beforeInjectExecuted = false ;
117
+ var injectedBehaviourExecuted = false ;
118
+
119
+ var policy = MonkeyPolicy . InjectBehaviourAsync ( with =>
120
+ with . Behaviour ( async ( ) =>
121
+ {
122
+ beforeInjectExecuted . Should ( ) . BeTrue ( ) ;
123
+ injectedBehaviourExecuted = true ;
124
+ } )
125
+ . BeforeInject ( async ( context , cancellation ) =>
126
+ {
127
+ injectedBehaviourExecuted . Should ( ) . BeFalse ( ) ;
128
+ beforeInjectExecuted = true ;
129
+ } )
130
+ . InjectionRate ( 0.6 )
131
+ . Enabled ( )
132
+ ) ;
133
+
134
+ await policy . ExecuteAsync ( ( ) => Task . CompletedTask ) ;
135
+
136
+ beforeInjectExecuted . Should ( ) . BeTrue ( ) ;
137
+ injectedBehaviourExecuted . Should ( ) . BeTrue ( ) ;
138
+ }
139
+
140
+ [ Fact ]
141
+ public async Task Should_not_call_before_inject_callback_if_not_injecting ( )
142
+ {
143
+ var beforeInjectExecuted = false ;
144
+ var behaviorExecuted = false ;
145
+
146
+ var policy = MonkeyPolicy . InjectBehaviourAsync ( with =>
147
+ with . Behaviour ( async ( ) =>
148
+ {
149
+ behaviorExecuted = true ;
150
+ } )
151
+ . BeforeInject ( async ( context , cancellation ) =>
152
+ {
153
+ beforeInjectExecuted = true ;
154
+ } )
155
+ . InjectionRate ( 0.4 )
156
+ . Enabled ( )
157
+ ) ;
158
+
159
+ await policy . ExecuteAsync ( ( ) => Task . CompletedTask ) ;
160
+
161
+ beforeInjectExecuted . Should ( ) . BeFalse ( ) ;
162
+ behaviorExecuted . Should ( ) . BeFalse ( ) ;
163
+ }
164
+ #endregion
165
+
112
166
#region invalid threshold on configuration and execution time
113
167
114
168
[ Fact ]
0 commit comments