generated from DFE-Digital/govuk-dotnet-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into firewall-logs
- Loading branch information
Showing
38 changed files
with
1,246 additions
and
92 deletions.
There are no files selected for viewing
165 changes: 165 additions & 0 deletions
165
Childrens-Social-Care-CPD-Tests/ConfigurationHealthCheckTests.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 |
---|---|---|
@@ -0,0 +1,165 @@ | ||
using Castle.Core.Logging; | ||
using Childrens_Social_Care_CPD; | ||
using Childrens_Social_Care_CPD.Configuration; | ||
using FluentAssertions; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
using Microsoft.Extensions.Logging; | ||
using NSubstitute; | ||
using NSubstitute.Extensions; | ||
using NUnit.Framework; | ||
using System.Threading.Tasks; | ||
|
||
namespace Childrens_Social_Care_CPD_Tests; | ||
|
||
public class ConfigurationHealthCheckTests | ||
{ | ||
private ILogger<ConfigurationHealthCheck> _logger; | ||
private IApplicationConfiguration _applicationConfiguration; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
_logger = Substitute.For<ILogger<ConfigurationHealthCheck>>(); | ||
_applicationConfiguration = Substitute.For<IApplicationConfiguration>(); | ||
_applicationConfiguration.ReturnsForAll("foo"); | ||
} | ||
|
||
[Test] | ||
public async Task Passes_When_All_Values_Set_And_Cookies_Are_Secured() | ||
{ | ||
// arrange | ||
var sut = new ConfigurationHealthCheck(_logger, _applicationConfiguration); | ||
|
||
// act | ||
var result = await sut.CheckHealthAsync(null, default); | ||
|
||
// assert | ||
result.Status.Should().Be(HealthStatus.Healthy); | ||
} | ||
|
||
[Test] | ||
public async Task Fails_When_Disable_Cookies_Is_True() | ||
{ | ||
// arrange | ||
_applicationConfiguration.DisableSecureCookies.Returns(true); | ||
var sut = new ConfigurationHealthCheck(_logger, _applicationConfiguration); | ||
|
||
// act | ||
var result = await sut.CheckHealthAsync(null, default); | ||
|
||
// assert | ||
result.Status.Should().Be(HealthStatus.Unhealthy); | ||
} | ||
|
||
[Test] | ||
public async Task Fails_When_AppInsightsConnectionString_Is_Not_Set() | ||
{ | ||
// arrange | ||
_applicationConfiguration.AppInsightsConnectionString.Returns(string.Empty); | ||
var sut = new ConfigurationHealthCheck(_logger, _applicationConfiguration); | ||
|
||
// act | ||
var result = await sut.CheckHealthAsync(null, default); | ||
|
||
// assert | ||
result.Status.Should().Be(HealthStatus.Unhealthy); | ||
} | ||
|
||
[Test] | ||
public async Task Fails_When_AppVersion_Is_Not_Set() | ||
{ | ||
// arrange | ||
_applicationConfiguration.AppVersion.Returns(string.Empty); | ||
var sut = new ConfigurationHealthCheck(_logger, _applicationConfiguration); | ||
|
||
// act | ||
var result = await sut.CheckHealthAsync(null, default); | ||
|
||
// assert | ||
result.Status.Should().Be(HealthStatus.Unhealthy); | ||
} | ||
|
||
[Test] | ||
public async Task Fails_When_AzureEnvironment_Is_Not_Set() | ||
{ | ||
// arrange | ||
_applicationConfiguration.AzureEnvironment.Returns(string.Empty); | ||
var sut = new ConfigurationHealthCheck(_logger, _applicationConfiguration); | ||
|
||
// act | ||
var result = await sut.CheckHealthAsync(null, default); | ||
|
||
// assert | ||
result.Status.Should().Be(HealthStatus.Unhealthy); | ||
} | ||
|
||
[Test] | ||
public async Task Fails_When_ClarityProjectId_Is_Not_Set() | ||
{ | ||
// arrange | ||
_applicationConfiguration.ClarityProjectId.Returns(string.Empty); | ||
var sut = new ConfigurationHealthCheck(_logger, _applicationConfiguration); | ||
|
||
// act | ||
var result = await sut.CheckHealthAsync(null, default); | ||
|
||
// assert | ||
result.Status.Should().Be(HealthStatus.Unhealthy); | ||
} | ||
|
||
[Test] | ||
public async Task Fails_When_ContentfulDeliveryApiKey_Is_Not_Set() | ||
{ | ||
// arrange | ||
_applicationConfiguration.ContentfulDeliveryApiKey.Returns(string.Empty); | ||
var sut = new ConfigurationHealthCheck(_logger, _applicationConfiguration); | ||
|
||
// act | ||
var result = await sut.CheckHealthAsync(null, default); | ||
|
||
// assert | ||
result.Status.Should().Be(HealthStatus.Unhealthy); | ||
} | ||
|
||
[Test] | ||
public async Task Fails_When_ContentfulEnvironment_Is_Not_Set() | ||
{ | ||
// arrange | ||
_applicationConfiguration.ContentfulEnvironment.Returns(string.Empty); | ||
var sut = new ConfigurationHealthCheck(_logger, _applicationConfiguration); | ||
|
||
// act | ||
var result = await sut.CheckHealthAsync(null, default); | ||
|
||
// assert | ||
result.Status.Should().Be(HealthStatus.Unhealthy); | ||
} | ||
|
||
[Test] | ||
public async Task Fails_When_ContentfulSpaceId_Is_Not_Set() | ||
{ | ||
// arrange | ||
_applicationConfiguration.ContentfulSpaceId.Returns(string.Empty); | ||
var sut = new ConfigurationHealthCheck(_logger, _applicationConfiguration); | ||
|
||
// act | ||
var result = await sut.CheckHealthAsync(null, default); | ||
|
||
// assert | ||
result.Status.Should().Be(HealthStatus.Unhealthy); | ||
} | ||
|
||
[Test] | ||
public async Task Fails_When_GoogleTagManagerKey_Is_Not_Set() | ||
{ | ||
// arrange | ||
_applicationConfiguration.GoogleTagManagerKey.Returns(string.Empty); | ||
var sut = new ConfigurationHealthCheck(_logger, _applicationConfiguration); | ||
|
||
// act | ||
var result = await sut.CheckHealthAsync(null, default); | ||
|
||
// assert | ||
result.Status.Should().Be(HealthStatus.Unhealthy); | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.