From 34a52e9abaa888117784bc51a5eb151ad493ec86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20St=C3=BChmer?= Date: Mon, 19 Feb 2024 09:54:50 +0100 Subject: [PATCH] chore: Polished xml summaries --- .../BlobContainerAvailableHealthCheck.cs | 12 +++++-- .../BlobContainerAvailableOptions.cs | 31 ++++++++++++++----- .../BlobServiceAvailableHealthCheck.cs | 9 ++++-- .../BlobServiceAvailableOptions.cs | 24 ++++++++++---- ...obHealthCheckBase.cs => ClientCreation.cs} | 19 +++--------- .../IBlobOptions.cs | 4 ++- .../AzuriteAccess.cs | 9 ------ .../BlobContainerAvailableHealthCheckTests.cs | 6 ---- .../BlobServiceAvailableHealthCheckTests.cs | 6 ---- .../BlobContainerAvailableHealthCheckTests.cs | 23 ++++++++++++++ 10 files changed, 88 insertions(+), 55 deletions(-) rename src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/{BlobHealthCheckBase.cs => ClientCreation.cs} (81%) create mode 100644 src/HealthChecks.Azure.Blobs/tests/NetEvolve.HealthChecks.Azure.Blobs.Tests.Unit/BlobContainerAvailableHealthCheckTests.cs diff --git a/src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/BlobContainerAvailableHealthCheck.cs b/src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/BlobContainerAvailableHealthCheck.cs index 5cbca0be..33c5c258 100644 --- a/src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/BlobContainerAvailableHealthCheck.cs +++ b/src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/BlobContainerAvailableHealthCheck.cs @@ -6,15 +6,21 @@ using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Options; using NetEvolve.Extensions.Tasks; +using NetEvolve.HealthChecks.Abstractions; internal sealed class BlobContainerAvailableHealthCheck - : BlobHealthCheckBase + : ConfigurableHealthCheckBase { + private readonly IServiceProvider _serviceProvider; + public BlobContainerAvailableHealthCheck( IServiceProvider serviceProvider, IOptionsMonitor optionsMonitor ) - : base(serviceProvider, optionsMonitor) { } + : base(optionsMonitor) + { + _serviceProvider = serviceProvider; + } protected override async ValueTask ExecuteHealthCheckAsync( string name, @@ -23,7 +29,7 @@ protected override async ValueTask ExecuteHealthCheckAsync( CancellationToken cancellationToken ) { - var blobClient = GetBlobServiceClient(name, options, _serviceProvider); + var blobClient = ClientCreation.GetBlobServiceClient(name, options, _serviceProvider); var blobTask = blobClient .GetBlobContainersAsync(cancellationToken: cancellationToken) diff --git a/src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/BlobContainerAvailableOptions.cs b/src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/BlobContainerAvailableOptions.cs index 234f5ed6..bc4eeea9 100644 --- a/src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/BlobContainerAvailableOptions.cs +++ b/src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/BlobContainerAvailableOptions.cs @@ -8,26 +8,43 @@ /// public sealed class BlobContainerAvailableOptions : IBlobOptions { - /// + /// + /// Gets or sets the connection string. + /// public string? ConnectionString { get; set; } - /// + /// + /// Gets or sets the mode to create the client. + /// public ClientCreationMode Mode { get; set; } + /// + /// The timeout to use when connecting and executing tasks against database. + /// public int Timeout { get; set; } = 100; - /// + /// + /// Gets or sets the name of the container. + /// public string? ContainerName { get; set; } - /// + /// + /// Gets or sets the service uri. + /// public Uri? ServiceUri { get; set; } - /// + /// + /// Gets or sets the account name. + /// public string? AccountName { get; set; } - /// + /// + /// Gets or sets the account key. + /// public string? AccountKey { get; set; } - /// + /// + /// Gets or sets the lambda to configure the . + /// public Action? ConfigureClientOptions { get; set; } } diff --git a/src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/BlobServiceAvailableHealthCheck.cs b/src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/BlobServiceAvailableHealthCheck.cs index 7d607f93..6ba73cf2 100644 --- a/src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/BlobServiceAvailableHealthCheck.cs +++ b/src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/BlobServiceAvailableHealthCheck.cs @@ -6,15 +6,18 @@ using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Options; using NetEvolve.Extensions.Tasks; +using NetEvolve.HealthChecks.Abstractions; internal sealed class BlobServiceAvailableHealthCheck - : BlobHealthCheckBase + : ConfigurableHealthCheckBase { + private readonly IServiceProvider _serviceProvider; + public BlobServiceAvailableHealthCheck( IServiceProvider serviceProvider, IOptionsMonitor optionsMonitor ) - : base(serviceProvider, optionsMonitor) { } + : base(optionsMonitor) => _serviceProvider = serviceProvider; protected override async ValueTask ExecuteHealthCheckAsync( string name, @@ -23,7 +26,7 @@ protected override async ValueTask ExecuteHealthCheckAsync( CancellationToken cancellationToken ) { - var blobClient = GetBlobServiceClient(name, options, _serviceProvider); + var blobClient = ClientCreation.GetBlobServiceClient(name, options, _serviceProvider); var blobTask = blobClient .GetBlobContainersAsync(cancellationToken: cancellationToken) diff --git a/src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/BlobServiceAvailableOptions.cs b/src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/BlobServiceAvailableOptions.cs index ddbffc75..fc041b84 100644 --- a/src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/BlobServiceAvailableOptions.cs +++ b/src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/BlobServiceAvailableOptions.cs @@ -8,10 +8,14 @@ /// public sealed class BlobServiceAvailableOptions : IBlobOptions { - /// + /// + /// Gets or sets the connection string. + /// public string? ConnectionString { get; set; } - /// + /// + /// Gets or sets the mode to create the client. + /// public ClientCreationMode Mode { get; set; } /// @@ -19,15 +23,23 @@ public sealed class BlobServiceAvailableOptions : IBlobOptions /// public int Timeout { get; set; } = 100; - /// + /// + /// Gets or sets the service uri. + /// public Uri? ServiceUri { get; set; } - /// + /// + /// Gets or sets the account name. + /// public string? AccountName { get; set; } - /// + /// + /// Gets or sets the account key. + /// public string? AccountKey { get; set; } - /// + /// + /// Gets or sets the lambda to configure the . + /// public Action? ConfigureClientOptions { get; set; } } diff --git a/src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/BlobHealthCheckBase.cs b/src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/ClientCreation.cs similarity index 81% rename from src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/BlobHealthCheckBase.cs rename to src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/ClientCreation.cs index 5a14b628..2845b865 100644 --- a/src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/BlobHealthCheckBase.cs +++ b/src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/ClientCreation.cs @@ -9,27 +9,17 @@ using global::Azure.Storage; using global::Azure.Storage.Blobs; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; -using NetEvolve.HealthChecks.Abstractions; -internal abstract class BlobHealthCheckBase : ConfigurableHealthCheckBase - where TOptions : class, IBlobOptions +internal static class ClientCreation { - protected readonly IServiceProvider _serviceProvider; private static ConcurrentDictionary? _blobServiceClients; - /// - protected BlobHealthCheckBase( - IServiceProvider serviceProvider, - IOptionsMonitor optionsMonitor - ) - : base(optionsMonitor) => _serviceProvider = serviceProvider; - - internal static BlobServiceClient GetBlobServiceClient( + internal static BlobServiceClient GetBlobServiceClient( string name, TOptions options, IServiceProvider serviceProvider ) + where TOptions : class, IBlobOptions { if (options.Mode == ClientCreationMode.ServiceProvider) { @@ -49,10 +39,11 @@ IServiceProvider serviceProvider ); } - internal static BlobServiceClient CreateBlobServiceClient( + internal static BlobServiceClient CreateBlobServiceClient( TOptions options, IServiceProvider serviceProvider ) + where TOptions : class, IBlobOptions { BlobClientOptions? clientOptions = null; if (options.ConfigureClientOptions is not null) diff --git a/src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/IBlobOptions.cs b/src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/IBlobOptions.cs index 38a33f6f..cc5b3f81 100644 --- a/src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/IBlobOptions.cs +++ b/src/HealthChecks.Azure.Blobs/src/NetEvolve.HealthChecks.Azure.Blobs/IBlobOptions.cs @@ -15,5 +15,7 @@ internal interface IBlobOptions ClientCreationMode Mode { get; } - Action? ConfigureClientOptions { get; set; } + Action? ConfigureClientOptions { get; } + + int Timeout { get; } } diff --git a/src/HealthChecks.Azure.Blobs/tests/NetEvolve.HealthChecks.Azure.Blobs.Tests.Integration/AzuriteAccess.cs b/src/HealthChecks.Azure.Blobs/tests/NetEvolve.HealthChecks.Azure.Blobs.Tests.Integration/AzuriteAccess.cs index 71381ac1..313af33d 100644 --- a/src/HealthChecks.Azure.Blobs/tests/NetEvolve.HealthChecks.Azure.Blobs.Tests.Integration/AzuriteAccess.cs +++ b/src/HealthChecks.Azure.Blobs/tests/NetEvolve.HealthChecks.Azure.Blobs.Tests.Integration/AzuriteAccess.cs @@ -9,24 +9,15 @@ [ExcludeFromCodeCoverage] public sealed class AzuriteAccess : IAsyncLifetime, IAsyncDisposable { - // TODO: Change when Testcontainers is supporting this - //public const string AccountName = "testaccount1"; - //public const string AccountKey = "SGVsbG8gV29ybGQ="; public const string AccountName = "devstoreaccount1"; public const string AccountKey = "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="; private readonly AzuriteContainer _container = new AzuriteBuilder() - // TODO: Change when Testcontainers is supporting this - // .WithAccountCredentials(AccountName, AccountKey) .Build(); public string ConnectionString => _container.GetConnectionString(); - //public Uri BlobEndpoint => new Uri(_container.GetBlobEndpoint(), UriKind.Absolute); - //public Uri QueueEndpoint => new Uri(_container.GetQueueEndpoint(), UriKind.Absolute); - //public Uri TableEndpoint => new Uri(_container.GetTableEndpoint(), UriKind.Absolute); - public async Task DisposeAsync() => await _container.DisposeAsync().ConfigureAwait(false); public async Task InitializeAsync() => await _container.StartAsync().ConfigureAwait(false); diff --git a/src/HealthChecks.Azure.Blobs/tests/NetEvolve.HealthChecks.Azure.Blobs.Tests.Integration/BlobContainerAvailableHealthCheckTests.cs b/src/HealthChecks.Azure.Blobs/tests/NetEvolve.HealthChecks.Azure.Blobs.Tests.Integration/BlobContainerAvailableHealthCheckTests.cs index 3a21d3f0..4f7f988f 100644 --- a/src/HealthChecks.Azure.Blobs/tests/NetEvolve.HealthChecks.Azure.Blobs.Tests.Integration/BlobContainerAvailableHealthCheckTests.cs +++ b/src/HealthChecks.Azure.Blobs/tests/NetEvolve.HealthChecks.Azure.Blobs.Tests.Integration/BlobContainerAvailableHealthCheckTests.cs @@ -21,8 +21,6 @@ public class BlobContainerAvailableHealthCheckTests { private readonly AzuriteAccess _container; private readonly Uri _accountSasUri; - - // TODO: Remove when TestContainers is providing this settíng private readonly Uri _uriBlobStorage; public BlobContainerAvailableHealthCheckTests(AzuriteAccess container) @@ -183,8 +181,6 @@ await RunAndVerify(healthChecks => options.AccountKey = AzuriteAccess.AccountKey; options.AccountName = AzuriteAccess.AccountName; options.Mode = ClientCreationMode.SharedKey; - // TODO: Change when TestContainers is providing this settíng - // options.ServiceUri = _container.BlobEndpoint; options.ServiceUri = _uriBlobStorage; options.ConfigureClientOptions = clientOptions => { @@ -207,8 +203,6 @@ await RunAndVerify(healthChecks => options.AccountName = AzuriteAccess.AccountName; options.Mode = ClientCreationMode.SharedKey; options.Timeout = 0; - // TODO: Change when TestContainers is providing this settíng - // options.ServiceUri = _container.BlobEndpoint; options.ServiceUri = _uriBlobStorage; } ); diff --git a/src/HealthChecks.Azure.Blobs/tests/NetEvolve.HealthChecks.Azure.Blobs.Tests.Integration/BlobServiceAvailableHealthCheckTests.cs b/src/HealthChecks.Azure.Blobs/tests/NetEvolve.HealthChecks.Azure.Blobs.Tests.Integration/BlobServiceAvailableHealthCheckTests.cs index cdfc5e8d..d17a9791 100644 --- a/src/HealthChecks.Azure.Blobs/tests/NetEvolve.HealthChecks.Azure.Blobs.Tests.Integration/BlobServiceAvailableHealthCheckTests.cs +++ b/src/HealthChecks.Azure.Blobs/tests/NetEvolve.HealthChecks.Azure.Blobs.Tests.Integration/BlobServiceAvailableHealthCheckTests.cs @@ -21,8 +21,6 @@ public class BlobServiceAvailableHealthCheckTests { private readonly AzuriteAccess _container; private readonly Uri _accountSasUri; - - // TODO: Remove when TestContainers is providing this settíng private readonly Uri _uriBlobStorage; public BlobServiceAvailableHealthCheckTests(AzuriteAccess container) @@ -147,8 +145,6 @@ await RunAndVerify(healthChecks => options.AccountKey = AzuriteAccess.AccountKey; options.AccountName = AzuriteAccess.AccountName; options.Mode = ClientCreationMode.SharedKey; - // TODO: Change when TestContainers is providing this settíng - // options.ServiceUri = _container.BlobEndpoint; options.ServiceUri = _uriBlobStorage; options.ConfigureClientOptions = clientOptions => { @@ -170,8 +166,6 @@ await RunAndVerify(healthChecks => options.AccountName = AzuriteAccess.AccountName; options.Mode = ClientCreationMode.SharedKey; options.Timeout = 0; - // TODO: Change when TestContainers is providing this settíng - // options.ServiceUri = _container.BlobEndpoint; options.ServiceUri = _uriBlobStorage; } ); diff --git a/src/HealthChecks.Azure.Blobs/tests/NetEvolve.HealthChecks.Azure.Blobs.Tests.Unit/BlobContainerAvailableHealthCheckTests.cs b/src/HealthChecks.Azure.Blobs/tests/NetEvolve.HealthChecks.Azure.Blobs.Tests.Unit/BlobContainerAvailableHealthCheckTests.cs new file mode 100644 index 00000000..566110a5 --- /dev/null +++ b/src/HealthChecks.Azure.Blobs/tests/NetEvolve.HealthChecks.Azure.Blobs.Tests.Unit/BlobContainerAvailableHealthCheckTests.cs @@ -0,0 +1,23 @@ +namespace NetEvolve.HealthChecks.Azure.Blobs.Tests.Unit; + +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using Microsoft.Extensions.DependencyInjection; +using NetEvolve.Extensions.XUnit; +using Xunit; + +[ExcludeFromCodeCoverage] +[UnitTest] +public class ClientCreationTests +{ + [Fact] + public void CreateBlobServiceClient_InvalidMode_ThrowUnreachableException() + { + var options = new BlobContainerAvailableOptions { Mode = (ClientCreationMode)13 }; + var serviceProvider = new ServiceCollection().BuildServiceProvider(); + + _ = Assert.Throws( + () => ClientCreation.CreateBlobServiceClient(options, serviceProvider) + ); + } +}