Skip to content

Commit

Permalink
chore: Polished xml summaries
Browse files Browse the repository at this point in the history
  • Loading branch information
samtrion committed Feb 19, 2024
1 parent 3f6860c commit 7fff442
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlobContainerAvailableOptions>
: ConfigurableHealthCheckBase<BlobContainerAvailableOptions>
{
private readonly IServiceProvider _serviceProvider;

public BlobContainerAvailableHealthCheck(
IServiceProvider serviceProvider,
IOptionsMonitor<BlobContainerAvailableOptions> optionsMonitor
)
: base(serviceProvider, optionsMonitor) { }
: base(optionsMonitor)
{
_serviceProvider = serviceProvider;
}

protected override async ValueTask<HealthCheckResult> ExecuteHealthCheckAsync(
string name,
Expand All @@ -23,7 +29,7 @@ protected override async ValueTask<HealthCheckResult> ExecuteHealthCheckAsync(
CancellationToken cancellationToken
)
{
var blobClient = GetBlobServiceClient(name, options, _serviceProvider);
var blobClient = ClientCreation.GetBlobServiceClient(name, options, _serviceProvider);

var blobTask = blobClient
.GetBlobContainersAsync(cancellationToken: cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,43 @@
/// </summary>
public sealed class BlobContainerAvailableOptions : IBlobOptions
{
/// <inheritdoc/>
/// <summary>
/// Gets or sets the connection string.
/// </summary>
public string? ConnectionString { get; set; }

/// <inheritdoc/>
/// <summary>
/// Gets or sets the mode to create the client.
/// </summary>
public ClientCreationMode Mode { get; set; }

/// <summary>
/// The timeout to use when connecting and executing tasks against database.
/// </summary>
public int Timeout { get; set; } = 100;

/// <inheritdoc/>
/// <summary>
/// Gets or sets the name of the container.
/// </summary>
public string? ContainerName { get; set; }

/// <inheritdoc/>
/// <summary>
/// Gets or sets the service uri.
/// </summary>
public Uri? ServiceUri { get; set; }

/// <inheritdoc/>
/// <summary>
/// Gets or sets the account name.
/// </summary>
public string? AccountName { get; set; }

/// <inheritdoc/>
/// <summary>
/// Gets or sets the account key.
/// </summary>
public string? AccountKey { get; set; }

/// <inheritdoc/>
/// <summary>
/// Gets or sets the lambda to configure the <see cref="BlobClientOptions"/>.
/// </summary>
public Action<BlobClientOptions>? ConfigureClientOptions { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlobServiceAvailableOptions>
: ConfigurableHealthCheckBase<BlobServiceAvailableOptions>
{
private readonly IServiceProvider _serviceProvider;

public BlobServiceAvailableHealthCheck(
IServiceProvider serviceProvider,
IOptionsMonitor<BlobServiceAvailableOptions> optionsMonitor
)
: base(serviceProvider, optionsMonitor) { }
: base(optionsMonitor) => _serviceProvider = serviceProvider;

protected override async ValueTask<HealthCheckResult> ExecuteHealthCheckAsync(
string name,
Expand All @@ -23,7 +26,7 @@ protected override async ValueTask<HealthCheckResult> ExecuteHealthCheckAsync(
CancellationToken cancellationToken
)
{
var blobClient = GetBlobServiceClient(name, options, _serviceProvider);
var blobClient = ClientCreation.GetBlobServiceClient(name, options, _serviceProvider);

var blobTask = blobClient
.GetBlobContainersAsync(cancellationToken: cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,38 @@
/// </summary>
public sealed class BlobServiceAvailableOptions : IBlobOptions
{
/// <inheritdoc/>
/// <summary>
/// Gets or sets the connection string.
/// </summary>
public string? ConnectionString { get; set; }

/// <inheritdoc/>
/// <summary>
/// Gets or sets the mode to create the client.
/// </summary>
public ClientCreationMode Mode { get; set; }

/// <summary>
/// Gets or sets the timeout in milliseconds for executing the healthcheck.
/// </summary>
public int Timeout { get; set; } = 100;

/// <inheritdoc/>
/// <summary>
/// Gets or sets the service uri.
/// </summary>
public Uri? ServiceUri { get; set; }

/// <inheritdoc/>
/// <summary>
/// Gets or sets the account name.
/// </summary>
public string? AccountName { get; set; }

/// <inheritdoc/>
/// <summary>
/// Gets or sets the account key.
/// </summary>
public string? AccountKey { get; set; }

/// <inheritdoc/>
/// <summary>
/// Gets or sets the lambda to configure the <see cref="BlobClientOptions"/>.
/// </summary>
public Action<BlobClientOptions>? ConfigureClientOptions { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<TOptions> : ConfigurableHealthCheckBase<TOptions>
where TOptions : class, IBlobOptions
internal static class ClientCreation
{
protected readonly IServiceProvider _serviceProvider;
private static ConcurrentDictionary<string, BlobServiceClient>? _blobServiceClients;

/// <inheritdoc/>
protected BlobHealthCheckBase(
IServiceProvider serviceProvider,
IOptionsMonitor<TOptions> optionsMonitor
)
: base(optionsMonitor) => _serviceProvider = serviceProvider;

internal static BlobServiceClient GetBlobServiceClient(
internal static BlobServiceClient GetBlobServiceClient<TOptions>(
string name,
TOptions options,
IServiceProvider serviceProvider
)
where TOptions : class, IBlobOptions
{
if (options.Mode == ClientCreationMode.ServiceProvider)
{
Expand All @@ -49,10 +39,11 @@ IServiceProvider serviceProvider
);
}

internal static BlobServiceClient CreateBlobServiceClient(
internal static BlobServiceClient CreateBlobServiceClient<TOptions>(
TOptions options,
IServiceProvider serviceProvider
)
where TOptions : class, IBlobOptions
{
BlobClientOptions? clientOptions = null;
if (options.ConfigureClientOptions is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ internal interface IBlobOptions

ClientCreationMode Mode { get; }

Action<BlobClientOptions>? ConfigureClientOptions { get; set; }
Action<BlobClientOptions>? ConfigureClientOptions { get; }

int Timeout { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 =>
{
Expand All @@ -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;
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 =>
{
Expand All @@ -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;
}
);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<UnreachableException>(
() => ClientCreation.CreateBlobServiceClient(options, serviceProvider)
);
}
}

0 comments on commit 7fff442

Please sign in to comment.