-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from LBHackney-IT/feature/let-multiple-dynamod…
…b-healthchecks Let APIs have multiple DynamoDB healthchecks
- Loading branch information
Showing
2 changed files
with
79 additions
and
79 deletions.
There are no files selected for viewing
90 changes: 45 additions & 45 deletions
90
....Core.Tests/Hackney.Core.Tests.DynamoDb/HealthCheck/DynamoDbHealthCheckExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,45 @@ | ||
using FluentAssertions; | ||
using Hackney.Core.DynamoDb.HealthCheck; | ||
using Hackney.Core.Testing.Shared; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace Hackney.Core.Tests.DynamoDb.HealthCheck | ||
{ | ||
public class DynamoDbHealthCheckExtensionsTests | ||
{ | ||
|
||
[Fact] | ||
public void RegisterDynamoDbHealthCheckTest() | ||
{ | ||
var services = new ServiceCollection(); | ||
_ = services.RegisterDynamoDbHealthCheck<TestModelDb>(); | ||
|
||
services.IsServiceRegistered<IHealthCheck, DynamoDbHealthCheck<TestModelDb>>().Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void ServiceCollectionAddDynamoDbHealthCheckTest() | ||
{ | ||
var services = new ServiceCollection(); | ||
_ = services.AddDynamoDbHealthCheck<TestModelDb>(); | ||
|
||
services.IsServiceRegistered<IHealthCheck, DynamoDbHealthCheck<TestModelDb>>().Should().BeTrue(); | ||
|
||
// We can't explicitly verify the Healthcheck builder reigstration here as it is not accessible. | ||
// We have to reply on the test below to do that for us. | ||
} | ||
|
||
[Fact] | ||
public void HealthChecksBuilderAddDynamoDbHealthCheckTest() | ||
{ | ||
var mockBuilder = new Mock<IHealthChecksBuilder>(); | ||
_ = mockBuilder.Object.AddDynamoDbHealthCheck<TestModelDb>(); | ||
|
||
mockBuilder.Verify(x => x.Add(It.Is<HealthCheckRegistration>(hcr => hcr.Name == "DynamoDb" | ||
&& hcr.Factory != null)), Times.Once); | ||
} | ||
} | ||
} | ||
using FluentAssertions; | ||
using Hackney.Core.DynamoDb.HealthCheck; | ||
using Hackney.Core.Testing.Shared; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace Hackney.Core.Tests.DynamoDb.HealthCheck | ||
{ | ||
public class DynamoDbHealthCheckExtensionsTests | ||
{ | ||
|
||
[Fact] | ||
public void RegisterDynamoDbHealthCheckTest() | ||
{ | ||
var services = new ServiceCollection(); | ||
_ = services.RegisterDynamoDbHealthCheck<TestModelDb>(); | ||
|
||
services.IsServiceRegistered<IHealthCheck, DynamoDbHealthCheck<TestModelDb>>().Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void ServiceCollectionAddDynamoDbHealthCheckTest() | ||
{ | ||
var services = new ServiceCollection(); | ||
_ = services.AddDynamoDbHealthCheck<TestModelDb>(); | ||
|
||
services.IsServiceRegistered<IHealthCheck, DynamoDbHealthCheck<TestModelDb>>().Should().BeTrue(); | ||
|
||
// We can't explicitly verify the Healthcheck builder reigstration here as it is not accessible. | ||
// We have to reply on the test below to do that for us. | ||
} | ||
|
||
[Fact] | ||
public void HealthChecksBuilderAddDynamoDbHealthCheckTest() | ||
{ | ||
var mockBuilder = new Mock<IHealthChecksBuilder>(); | ||
_ = mockBuilder.Object.AddDynamoDbHealthCheck<TestModelDb>(); | ||
|
||
mockBuilder.Verify(x => x.Add(It.Is<HealthCheckRegistration>(hcr => hcr.Name == "DynamoDb_" + typeof(TestModelDb).Name | ||
&& hcr.Factory != null)), Times.Once); | ||
} | ||
} | ||
} |
68 changes: 34 additions & 34 deletions
68
Hackney.Core/Hackney.Core.DynamoDb/HealthCheck/DynamoDbHealthCheckExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
|
||
namespace Hackney.Core.DynamoDb.HealthCheck | ||
{ | ||
public static class DynamoDbHealthCheckExtensions | ||
{ | ||
private const string Name = "DynamoDb"; | ||
|
||
public static IServiceCollection RegisterDynamoDbHealthCheck<T>(this IServiceCollection services) where T : class | ||
{ | ||
return services.AddSingleton<IHealthCheck, DynamoDbHealthCheck<T>>(); | ||
} | ||
|
||
public static IHealthChecksBuilder AddDynamoDbHealthCheck<T>(this IHealthChecksBuilder builder) where T : class | ||
{ | ||
return builder.AddCheck<DynamoDbHealthCheck<T>>(Name); | ||
} | ||
|
||
/// <summary> | ||
/// Adds a health check to verify connectivity to the DynamoDb table used by T. | ||
/// </summary> | ||
/// <typeparam name="T">The database model class used to determine the DynamoDb table name.</typeparam> | ||
/// <param name="services">The <see cref="IServiceCollection"/>.</param> | ||
/// <returns>The <see cref="IServiceCollection"/>.</returns> | ||
public static IServiceCollection AddDynamoDbHealthCheck<T>(this IServiceCollection services) where T : class | ||
{ | ||
services.RegisterDynamoDbHealthCheck<T>(); | ||
services.AddHealthChecks() | ||
.AddDynamoDbHealthCheck<T>(); | ||
return services; | ||
} | ||
} | ||
} | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
|
||
namespace Hackney.Core.DynamoDb.HealthCheck | ||
{ | ||
public static class DynamoDbHealthCheckExtensions | ||
{ | ||
private const string Name = "DynamoDb_"; | ||
|
||
public static IServiceCollection RegisterDynamoDbHealthCheck<T>(this IServiceCollection services) where T : class | ||
{ | ||
return services.AddSingleton<IHealthCheck, DynamoDbHealthCheck<T>>(); | ||
} | ||
|
||
public static IHealthChecksBuilder AddDynamoDbHealthCheck<T>(this IHealthChecksBuilder builder) where T : class | ||
{ | ||
return builder.AddCheck<DynamoDbHealthCheck<T>>(Name + typeof(T).Name); | ||
} | ||
|
||
/// <summary> | ||
/// Adds a health check to verify connectivity to the DynamoDb table used by T. | ||
/// </summary> | ||
/// <typeparam name="T">The database model class used to determine the DynamoDb table name.</typeparam> | ||
/// <param name="services">The <see cref="IServiceCollection"/>.</param> | ||
/// <returns>The <see cref="IServiceCollection"/>.</returns> | ||
public static IServiceCollection AddDynamoDbHealthCheck<T>(this IServiceCollection services) where T : class | ||
{ | ||
services.RegisterDynamoDbHealthCheck<T>(); | ||
services.AddHealthChecks() | ||
.AddDynamoDbHealthCheck<T>(); | ||
return services; | ||
} | ||
} | ||
} |