public void Call_IgnoreUnauthorisedAccess_ClosesOnOtherException()
        {
            // Arrange
            var cb = new SimpleCircuitBreaker<TestClass>(new TestClass(),
                new SimpleCircuitBreakerConfig {RetryThreshold = 0},
                state: CircuitBreakerState.Closed);

            // Act
            cb.Call(tc => tc.DoNothing());

            // Assert
            cb.State.ShouldBe(CircuitBreakerState.Open);
        }
        public void Call_DoNothing_DoesNothing()
        {
            // Arrange
            SimpleCircuitBreaker<TestClass> cb = new SimpleCircuitBreaker<TestClass>(new TestClass(),
                new SimpleCircuitBreakerConfig {Threshold = 0});

            // Act
            cb.Call(tc => tc.DoNothing());

            // Assert
            cb.State.ShouldBe(CircuitBreakerState.Open);
            cb.LastException.ShouldBe(null);
        }
        public void Call_WithExceptionFilter_IgnoresException()
        {
            // Arrange
            SimpleCircuitBreaker<TestClass> cb = new SimpleCircuitBreaker<TestClass>(new TestClass(),
                new SimpleCircuitBreakerConfig {Threshold = 0}, exception => false);

            // Act
            try
            {
                cb.Call(tc => tc.ThrowException());
            }
            catch (Exception)
            {

            }

            // Assert
            cb.State.ShouldBe(CircuitBreakerState.Open);
            cb.LastException.ShouldBe(null);
        }
        public void Call_ThrowException_ClosesCircuit()
        {
            // Arrange
            SimpleCircuitBreaker<TestClass> cb = new SimpleCircuitBreaker<TestClass>(new TestClass(),
                new SimpleCircuitBreakerConfig {Threshold = 0});
            Exception exception = null;

            // Act
            try
            {
                cb.Call(tc => { tc.ThrowException(); });
            }
            catch (Exception e)
            {
                exception = e;
            }

            // Assert
            cb.State.ShouldBe(CircuitBreakerState.Closed);
            exception.ShouldNotBe(null);
            exception.Message.ShouldBe("fake exception");
        }
        public void Ctor_Nothing_IsOpenByDefault()
        {
            // Arrange
            SimpleCircuitBreaker<TestClass> cb = new SimpleCircuitBreaker<TestClass>(new TestClass(), new SimpleCircuitBreakerConfig());

            // Assert
            cb.State.ShouldBe(CircuitBreakerState.Open);
        }
 public void Ctor_NullTarget_ThrowsArgumentNull()
 {
     // Arrange
     SimpleCircuitBreaker<TestClass> cb = new SimpleCircuitBreaker<TestClass>(null, new SimpleCircuitBreakerConfig());
 }
 public void Ctor_NullConfig_ThrowsArgumentNull()
 {
     // Arrange
     SimpleCircuitBreaker<TestClass> cb = new SimpleCircuitBreaker<TestClass>(new TestClass(), null);
 }