public async Task WhenAzureBlobStorageContainerExists_ThenAzureBlobStorageServiceIsHealthy() { A.CallTo(() => fakeSalesCatalogueStorageService.GetStorageAccountConnectionString(string.Empty, string.Empty)).Returns(GetStorageAccountConnectionStringAndContainerName().Item1); A.CallTo(() => fakeAzureBlobStorageClient.CheckBlobContainerHealth(A <string> .Ignored, A <string> .Ignored)).Returns(HealthCheckResult.Healthy("Azure blob storage is healthy")); var response = await azureBlobStorageHealthCheck.CheckHealthAsync(new HealthCheckContext()); Assert.AreEqual(HealthStatus.Healthy, response.Status); }
public async Task <HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) { try { string[] exchangeSetTypes = essFulfilmentStorageConfiguration.Value.ExchangeSetTypes.Split(","); string storageAccountConnectionString = string.Empty; HealthCheckResult azureBlobStorageHealthStatus = new HealthCheckResult(HealthStatus.Healthy, "Azure blob storage is healthy"); foreach (string exchangeSetType in exchangeSetTypes) { Enum.TryParse(exchangeSetType, out ExchangeSetType exchangeSetTypeName); var storageAccountWithKey = azureBlobStorageService.GetStorageAccountNameAndKeyBasedOnExchangeSetType(exchangeSetTypeName); storageAccountConnectionString = scsStorageService.GetStorageAccountConnectionString(storageAccountWithKey.Item1, storageAccountWithKey.Item2); azureBlobStorageHealthStatus = await azureBlobStorageClient.CheckBlobContainerHealth(storageAccountConnectionString, essFulfilmentStorageConfiguration.Value.StorageContainerName); if (azureBlobStorageHealthStatus.Status == HealthStatus.Unhealthy) { logger.LogError(EventIds.AzureBlobStorageIsUnhealthy.ToEventId(), azureBlobStorageHealthStatus.Exception, "Azure blob storage is unhealthy for exchangeSetType: {exchangeSetType} with error {Message}", exchangeSetType, azureBlobStorageHealthStatus.Exception.Message); azureBlobStorageHealthStatus = HealthCheckResult.Unhealthy("Azure blob storage is unhealthy", azureBlobStorageHealthStatus.Exception); return(azureBlobStorageHealthStatus); } } logger.LogDebug(EventIds.AzureBlobStorageIsHealthy.ToEventId(), "Azure blob storage is healthy"); return(azureBlobStorageHealthStatus); } catch (Exception ex) { logger.LogError(EventIds.AzureBlobStorageIsUnhealthy.ToEventId(), ex, "Azure blob storage is unhealthy with error {Message}", ex.Message); return(HealthCheckResult.Unhealthy("Azure blob storage is unhealthy", ex)); } }