public void Breaker_IsClosed_OnCircuitWithoutException() { var aCircuit = new MyDatabaseCircuit(null); var aCommand = new TestExceptionCommand(aCircuit); Assert.IsTrue(aCommand.Breaker.IsClosed); }
public void CircuitBreakerOpenException_IsThrown_AfterExecuteActionThrows() { var testCircuit = new MyWebServerCircuit(null); var testCommand = new TestExceptionCommand(testCircuit); Assert.IsTrue(testCommand.Breaker.IsClosed); try { var result = testCommand.ExecuteAction().Result; } catch (AggregateException ex) { ex.Handle((x) => { Assert.IsTrue(x is CircuitBreakerOpenException); if (x is CircuitBreakerOpenException) { return(true); // don't throw, we'll handle open circuit in our code } return(false); // throw, we didn't expect this exception! }); } Assert.IsTrue(testCommand.Breaker.IsOpen); }