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");
        }