@@ -7,6 +7,43 @@ public class CircuitBreakerTResultSpecs : IDisposable
77{
88 #region Configuration tests
99
10+ [ Fact ]
11+ public void Should_throw_when_action_is_null ( )
12+ {
13+ var flags = BindingFlags . NonPublic | BindingFlags . Instance ;
14+ Func < Context , CancellationToken , EmptyStruct > action = null ! ;
15+ PolicyBuilder < EmptyStruct > policyBuilder = new PolicyBuilder < EmptyStruct > ( exception => exception ) ;
16+
17+ var exceptionsAllowedBeforeBreaking = 1 ;
18+ var durationOfBreak = TimeSpan . Zero ;
19+ Action < DelegateResult < EmptyStruct > , CircuitState , TimeSpan , Context > onBreak = null ! ;
20+ Action < Context > onReset = null ! ;
21+ Action onHalfOpen = null ! ;
22+ ICircuitController < EmptyStruct > breakerController = new ConsecutiveCountCircuitController < EmptyStruct > (
23+ exceptionsAllowedBeforeBreaking ,
24+ durationOfBreak ,
25+ onBreak ,
26+ onReset ,
27+ onHalfOpen ) ;
28+
29+ var instance = Activator . CreateInstance (
30+ typeof ( CircuitBreakerPolicy < EmptyStruct > ) ,
31+ flags ,
32+ null ,
33+ [ policyBuilder , breakerController ] ,
34+ null ) ! ;
35+ var instanceType = instance . GetType ( ) ;
36+ var methods = instanceType . GetMethods ( flags ) ;
37+ var methodInfo = methods . First ( method => method is { Name : "Implementation" , ReturnType . Name : "EmptyStruct" } ) ;
38+
39+ var func = ( ) => methodInfo . Invoke ( instance , [ action , new Context ( ) , CancellationToken . None ] ) ;
40+
41+ var exceptionAssertions = func . Should ( ) . Throw < TargetInvocationException > ( ) ;
42+ exceptionAssertions . And . Message . Should ( ) . Be ( "Exception has been thrown by the target of an invocation." ) ;
43+ exceptionAssertions . And . InnerException . Should ( ) . BeOfType < ArgumentNullException > ( )
44+ . Which . ParamName . Should ( ) . Be ( "action" ) ;
45+ }
46+
1047 [ Fact ]
1148 public void Should_be_able_to_handle_a_duration_of_timespan_maxvalue ( )
1249 {
0 commit comments