public void GivenCircuitBreakerClose_WhenManuallyOpen_ThenOpen() { // Arrange const int THRESHOLD = 2; var circuitBreaker = new BaseCircuitBreaker.CircuitBreaker(THRESHOLD, TimeSpan.FromMinutes(5)); Assert.True(circuitBreaker.IsClosed); // Act circuitBreaker.Open(); // Assert Assert.True(circuitBreaker.IsOpen); }
public void GivenCircuitBreakerClose_WhenOpenAndStateChangeSubscribed_ThenCallEventStateChangeOnce() { // Arrange int changeStateCount = 0; const int THRESHOLD = 2; var circuitBreaker = new BaseCircuitBreaker.CircuitBreaker(THRESHOLD, TimeSpan.FromMinutes(5)); circuitBreaker.OnStateChange += (o, state) => { changeStateCount++; }; Assert.True(circuitBreaker.IsClosed); // Act circuitBreaker.Open(); // Assert Assert.Equal(1, changeStateCount); }