@@ -2484,6 +2484,160 @@ public void Should_open_circuit_with_timespan_maxvalue_if_manual_override_open()
2484
2484
passedBreakTimespan . Should ( ) . Be ( TimeSpan . MaxValue ) ;
2485
2485
}
2486
2486
2487
+ [ Fact ]
2488
+ public void Should_throw_when_failureThreshold_is_less_or_equals_than_zero ( )
2489
+ {
2490
+ Action < Exception , TimeSpan , Context > onBreak = ( _ , timespan , _ ) => { _ = timespan ; } ;
2491
+ Action < Context > onReset = _ => { } ;
2492
+
2493
+ var time = 1 . January ( 2000 ) ;
2494
+ SystemClock . UtcNow = ( ) => time ;
2495
+
2496
+ Action action = ( ) => Policy
2497
+ . Handle < DivideByZeroException > ( )
2498
+ . AdvancedCircuitBreakerAsync (
2499
+ failureThreshold : 0 ,
2500
+ samplingDuration : TimeSpan . FromSeconds ( 10 ) ,
2501
+ minimumThroughput : 4 ,
2502
+ durationOfBreak : TimeSpan . FromMinutes ( 1 ) ,
2503
+ onBreak : onBreak ,
2504
+ onReset : onReset ) ;
2505
+
2506
+ action . Should ( ) . Throw < ArgumentOutOfRangeException > ( ) . And . ParamName . Should ( ) . Be ( "failureThreshold" ) ;
2507
+ }
2508
+
2509
+ [ Fact ]
2510
+ public void Should_throw_when_failureThreshold_is_more_than_one ( )
2511
+ {
2512
+ Action < Exception , TimeSpan , Context > onBreak = ( _ , timespan , _ ) => { _ = timespan ; } ;
2513
+ Action < Context > onReset = _ => { } ;
2514
+
2515
+ var time = 1 . January ( 2000 ) ;
2516
+ SystemClock . UtcNow = ( ) => time ;
2517
+
2518
+ Action action = ( ) => Policy
2519
+ . Handle < DivideByZeroException > ( )
2520
+ . AdvancedCircuitBreakerAsync (
2521
+ failureThreshold : 1.5 ,
2522
+ samplingDuration : TimeSpan . FromSeconds ( 10 ) ,
2523
+ minimumThroughput : 4 ,
2524
+ durationOfBreak : TimeSpan . FromMinutes ( 1 ) ,
2525
+ onBreak : onBreak ,
2526
+ onReset : onReset ) ;
2527
+
2528
+ action . Should ( ) . Throw < ArgumentOutOfRangeException > ( ) . And . ParamName . Should ( ) . Be ( "failureThreshold" ) ;
2529
+ }
2530
+
2531
+ [ Fact ]
2532
+ public void Should_throw_when_samplingDuration_is_less_than_resolutionOfCircuit ( )
2533
+ {
2534
+ Action < Exception , TimeSpan , Context > onBreak = ( _ , timespan , _ ) => { _ = timespan ; } ;
2535
+ Action < Context > onReset = _ => { } ;
2536
+
2537
+ var time = 1 . January ( 2000 ) ;
2538
+ SystemClock . UtcNow = ( ) => time ;
2539
+
2540
+ Action action = ( ) => Policy
2541
+ . Handle < DivideByZeroException > ( )
2542
+ . AdvancedCircuitBreakerAsync (
2543
+ failureThreshold : 0.5 ,
2544
+ samplingDuration : TimeSpan . FromMilliseconds ( 10 ) ,
2545
+ minimumThroughput : 4 ,
2546
+ durationOfBreak : TimeSpan . FromMinutes ( 1 ) ,
2547
+ onBreak : onBreak ,
2548
+ onReset : onReset ) ;
2549
+
2550
+ action . Should ( ) . Throw < ArgumentOutOfRangeException > ( ) . And . ParamName . Should ( ) . Be ( "samplingDuration" ) ;
2551
+ }
2552
+
2553
+ [ Fact ]
2554
+ public void Should_throw_when_minimumThroughput_is_less_or_equals_than_one ( )
2555
+ {
2556
+ Action < Exception , TimeSpan , Context > onBreak = ( _ , timespan , _ ) => { _ = timespan ; } ;
2557
+ Action < Context > onReset = _ => { } ;
2558
+
2559
+ var time = 1 . January ( 2000 ) ;
2560
+ SystemClock . UtcNow = ( ) => time ;
2561
+
2562
+ Action action = ( ) => Policy
2563
+ . Handle < DivideByZeroException > ( )
2564
+ . AdvancedCircuitBreakerAsync (
2565
+ failureThreshold : 0.5 ,
2566
+ samplingDuration : TimeSpan . FromSeconds ( 10 ) ,
2567
+ minimumThroughput : 0 ,
2568
+ durationOfBreak : TimeSpan . FromMinutes ( 1 ) ,
2569
+ onBreak : onBreak ,
2570
+ onReset : onReset ) ;
2571
+
2572
+ action . Should ( ) . Throw < ArgumentOutOfRangeException > ( ) . And . ParamName . Should ( ) . Be ( "minimumThroughput" ) ;
2573
+ }
2574
+
2575
+ [ Fact ]
2576
+ public void Should_throw_when_durationOfBreak_is_negative_timespan ( )
2577
+ {
2578
+ Action < Exception , TimeSpan , Context > onBreak = ( _ , timespan , _ ) => { _ = timespan ; } ;
2579
+ Action < Context > onReset = _ => { } ;
2580
+
2581
+ var time = 1 . January ( 2000 ) ;
2582
+ SystemClock . UtcNow = ( ) => time ;
2583
+
2584
+ Action action = ( ) => Policy
2585
+ . Handle < DivideByZeroException > ( )
2586
+ . AdvancedCircuitBreakerAsync (
2587
+ failureThreshold : 0.5 ,
2588
+ samplingDuration : TimeSpan . FromSeconds ( 10 ) ,
2589
+ minimumThroughput : 4 ,
2590
+ durationOfBreak : TimeSpan . FromMinutes ( - 1 ) ,
2591
+ onBreak : onBreak ,
2592
+ onReset : onReset ) ;
2593
+
2594
+ action . Should ( ) . Throw < ArgumentOutOfRangeException > ( ) . And . ParamName . Should ( ) . Be ( "durationOfBreak" ) ;
2595
+ }
2596
+
2597
+ [ Fact ]
2598
+ public void Should_throw_when_onReset_is_null ( )
2599
+ {
2600
+ Action < Exception , TimeSpan , Context > onBreak = ( _ , timespan , _ ) => { _ = timespan ; } ;
2601
+
2602
+ var time = 1 . January ( 2000 ) ;
2603
+ SystemClock . UtcNow = ( ) => time ;
2604
+
2605
+ Action action = ( ) => Policy
2606
+ . Handle < DivideByZeroException > ( )
2607
+ . AdvancedCircuitBreakerAsync (
2608
+ failureThreshold : 0.5 ,
2609
+ samplingDuration : TimeSpan . FromSeconds ( 10 ) ,
2610
+ minimumThroughput : 4 ,
2611
+ durationOfBreak : TimeSpan . FromMinutes ( 1 ) ,
2612
+ onBreak : onBreak ,
2613
+ onReset : null ) ;
2614
+
2615
+ action . Should ( ) . Throw < ArgumentNullException > ( ) . And . ParamName . Should ( ) . Be ( "onReset" ) ;
2616
+ }
2617
+
2618
+ [ Fact ]
2619
+ public void Should_throw_when_onHalfOpen_is_null ( )
2620
+ {
2621
+ Action < Exception , TimeSpan , Context > onBreak = ( _ , timespan , _ ) => { _ = timespan ; } ;
2622
+ Action < Context > onReset = _ => { } ;
2623
+
2624
+ var time = 1 . January ( 2000 ) ;
2625
+ SystemClock . UtcNow = ( ) => time ;
2626
+
2627
+ Action action = ( ) => Policy
2628
+ . Handle < DivideByZeroException > ( )
2629
+ . AdvancedCircuitBreakerAsync (
2630
+ failureThreshold : 0.5 ,
2631
+ samplingDuration : TimeSpan . FromSeconds ( 10 ) ,
2632
+ minimumThroughput : 4 ,
2633
+ durationOfBreak : TimeSpan . FromMinutes ( 1 ) ,
2634
+ onBreak : onBreak ,
2635
+ onReset : onReset ,
2636
+ onHalfOpen : null ) ;
2637
+
2638
+ action . Should ( ) . Throw < ArgumentNullException > ( ) . And . ParamName . Should ( ) . Be ( "onHalfOpen" ) ;
2639
+ }
2640
+
2487
2641
#endregion
2488
2642
2489
2643
#region Tests that supplied context is passed to stage-change delegates
0 commit comments