public async Task WhenAzureMessageQueueExists_ThenAzureMessageQueueIsHealthy() { A.CallTo(() => fakeSalesCatalogueStorageService.GetStorageAccountConnectionString(string.Empty, string.Empty)).Returns(GetStorageAccountConnectionStringAndContainerName().Item1); A.CallTo(() => fakeAzureMessageQueueHelperClient.CheckMessageQueueHealth(A <string> .Ignored, A <string> .Ignored)).Returns(new HealthCheckResult(HealthStatus.Healthy, "Azure message queue is healthy")); A.CallTo(() => fakeAzureBlobStorageService.GetInstanceCountBasedOnExchangeSetType(A <ExchangeSetType> .Ignored)).Returns(1); var response = await azureMessageQueueHealthCheck.CheckHealthAsync(new HealthCheckContext()); Assert.AreEqual(HealthStatus.Healthy, response.Status); }
private async Task <HealthCheckResult> CheckAllMessageQueuesHealth() { string[] exchangeSetTypes = essFulfilmentStorageConfiguration.Value.ExchangeSetTypes.Split(","); string storageAccountConnectionString, queueName = string.Empty; HealthCheckResult messageQueueHealthStatus = new HealthCheckResult(HealthStatus.Healthy, "Azure message queue is healthy"); foreach (string exchangeSetTypeName in exchangeSetTypes) { Enum.TryParse(exchangeSetTypeName, out ExchangeSetType exchangeSetType); for (int i = 1; i <= azureBlobStorageService.GetInstanceCountBasedOnExchangeSetType(exchangeSetType); i++) { queueName = string.Format(essFulfilmentStorageConfiguration.Value.DynamicQueueName, i); var storageAccountWithKey = azureBlobStorageService.GetStorageAccountNameAndKeyBasedOnExchangeSetType(exchangeSetType); storageAccountConnectionString = scsStorageService.GetStorageAccountConnectionString(storageAccountWithKey.Item1, storageAccountWithKey.Item2); messageQueueHealthStatus = await azureMessageQueueHelper.CheckMessageQueueHealth(storageAccountConnectionString, queueName); if (messageQueueHealthStatus.Status == HealthStatus.Unhealthy) { logger.LogError(EventIds.AzureMessageQueueIsUnhealthy.ToEventId(), messageQueueHealthStatus.Exception, "Azure message queue {queueName} is unhealthy", queueName); return(messageQueueHealthStatus); } } } logger.LogDebug(EventIds.AzureMessageQueueIsHealthy.ToEventId(), "Azure message queue is healthy"); return(messageQueueHealthStatus); }