public void GetCircuitBreakerStatusAsyncDoesNotExistTest() { // Arrange SetupCalls(); A.CallTo(() => fakeCircuitBreakerQueryRepository.GetBreakerDetails()).Returns(null); A.CallTo(() => fakeCircuitBreakerCommandRepository.Add(A <CircuitBreakerDetails> ._)).DoesNothing(); // Act var accountService = new AccountsService(fakeApplicationLogger, fakeConfiguration, fakeAccountQueryRepository, fakeAuditCommandRepository, fakeCircuitBreakerQueryRepository, fakeCircuitBreakerCommandRepository); var result = accountService.GetCircuitBreakerStatusAsync().Result; // Assert A.CallTo(() => fakeCircuitBreakerCommandRepository.Add(A <CircuitBreakerDetails> ._)).MustHaveHappenedOnceExactly(); result.CircuitBreakerStatus.Should().Be(CircuitBreakerStatus.Closed); result.HalfOpenRetryCount.Should().Be(0); result.LastCircuitOpenDate.Should().BeCloseTo(DateTime.Now, 1000); }
public async Task <CircuitBreakerDetails> GetCircuitBreakerStatusAsync() { var circuitBreakerDetails = circuitBreakerQueryRepository.GetBreakerDetails(); if (circuitBreakerDetails == null) { applicationLogger.Trace("Adding default circuit breaker record on get as one does not exist"); return(AddDefaultCircuitBreaker()); } else if (circuitBreakerDetails.CircuitBreakerStatus == CircuitBreakerStatus.Open && circuitBreakerDetails.LastCircuitOpenDate.AddHours(24) < DateTime.Now) { circuitBreakerDetails.CircuitBreakerStatus = CircuitBreakerStatus.Closed; circuitBreakerDetails.HalfOpenRetryCount = 0; circuitBreakerDetails.LastCircuitOpenDate = DateTime.Now; await UpdateCircuitBreakerAsync(circuitBreakerDetails); } return(circuitBreakerDetails); }