-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into CV-251-add-reservations-to-bulk-upload
# Conflicts: # src/CommitmentsV2/SFA.DAS.ReservationsV2.Api.Client.UnitTests/WhenCallingTheValidateReservationEndpoint.cs # src/CommitmentsV2/SFA.DAS.ReservationsV2.Api.Client/ReservationsApiClient.cs # src/SFA.DAS.Reservations.API.Types/IReservationsApiClient.cs # src/SFA.DAS.Reservations.Api.Client/HttpHelper.cs # src/SFA.DAS.Reservations.Api.Types.UnitTests/ReservationsHelper/WhenCallingTheValidateReservationEndpoint.cs # src/SFA.DAS.Reservations.Api.Types/IReservationHelper.cs # src/SFA.DAS.Reservations.Api.Types/ReservationsHelper.cs
- Loading branch information
Showing
18 changed files
with
286 additions
and
25 deletions.
There are no files selected for viewing
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
83 changes: 83 additions & 0 deletions
83
...DAS.CommitmentsV2.Api.UnitTests/HealthChecks/ApprenticeshipInfoServiceHealthCheckTests.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,83 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
using Moq; | ||
using NUnit.Framework; | ||
using SFA.DAS.Apprenticeships.Api.Types.Providers; | ||
using SFA.DAS.CommitmentsV2.Api.HealthChecks; | ||
using SFA.DAS.Providers.Api.Client; | ||
|
||
namespace SFA.DAS.CommitmentsV2.Api.UnitTests.HealthChecks | ||
{ | ||
[TestFixture] | ||
[Parallelizable] | ||
public class ApprenticeshipInfoServiceHealthCheckTests | ||
{ | ||
private ApprenticeshipInfoServiceHealthCheckTestsFixture _fixture; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_fixture = new ApprenticeshipInfoServiceHealthCheckTestsFixture(); | ||
} | ||
|
||
[Test] | ||
public async Task CheckHealthAsync_WhenFindAllAsyncSucceeds_ThenShouldReturnHealthyStatus() | ||
{ | ||
var healthCheckResult = await _fixture.SetFindAllAsyncSuccess().CheckHealthAsync(); | ||
|
||
Assert.AreEqual(HealthStatus.Healthy, healthCheckResult.Status); | ||
} | ||
|
||
[Test] | ||
public async Task CheckHealthAsync_WhenFindAllAsyncFails_ThenShouldReturnDegradedStatus() | ||
{ | ||
var healthCheckResult = await _fixture.SetFindAllAsyncFailure().CheckHealthAsync(); | ||
|
||
Assert.AreEqual(HealthStatus.Degraded, healthCheckResult.Status); | ||
Assert.AreEqual(_fixture.Exception.Message, healthCheckResult.Description); | ||
} | ||
|
||
private class ApprenticeshipInfoServiceHealthCheckTestsFixture | ||
{ | ||
public HealthCheckContext HealthCheckContext { get; set; } | ||
public CancellationToken CancellationToken { get; set; } | ||
public Mock<IProviderApiClient> ProviderApiClient { get; set; } | ||
public ApprenticeshipInfoServiceApiHealthCheck HealthCheck { get; set; } | ||
public Exception Exception { get; set; } | ||
|
||
public ApprenticeshipInfoServiceHealthCheckTestsFixture() | ||
{ | ||
HealthCheckContext = new HealthCheckContext | ||
{ | ||
Registration = new HealthCheckRegistration("Foo", Mock.Of<IHealthCheck>(), null, null) | ||
}; | ||
|
||
ProviderApiClient = new Mock<IProviderApiClient>(); | ||
HealthCheck = new ApprenticeshipInfoServiceApiHealthCheck(ProviderApiClient.Object); | ||
Exception = new Exception("Foobar"); | ||
} | ||
|
||
public Task<HealthCheckResult> CheckHealthAsync() | ||
{ | ||
return HealthCheck.CheckHealthAsync(HealthCheckContext, CancellationToken); | ||
} | ||
|
||
public ApprenticeshipInfoServiceHealthCheckTestsFixture SetFindAllAsyncSuccess() | ||
{ | ||
ProviderApiClient.Setup(c => c.FindAllAsync()).ReturnsAsync(new List<ProviderSummary>()); | ||
|
||
return this; | ||
} | ||
|
||
public ApprenticeshipInfoServiceHealthCheckTestsFixture SetFindAllAsyncFailure() | ||
{ | ||
ProviderApiClient.Setup(c => c.FindAllAsync()).ThrowsAsync(Exception); | ||
|
||
return this; | ||
} | ||
} | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...ntsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/HealthChecks/ReservationsApiHealthCheckTests.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,81 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
using Moq; | ||
using NUnit.Framework; | ||
using SFA.DAS.CommitmentsV2.Api.HealthChecks; | ||
using SFA.DAS.Reservations.Api.Types; | ||
|
||
namespace SFA.DAS.CommitmentsV2.Api.UnitTests.HealthChecks | ||
{ | ||
[TestFixture] | ||
[Parallelizable] | ||
public class ReservationsApiHealthCheckTests | ||
{ | ||
private ReservationsApiHealthCheckTestsFixture _fixture; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_fixture = new ReservationsApiHealthCheckTestsFixture(); | ||
} | ||
|
||
[Test] | ||
public async Task CheckHealthAsync_WhenPingSucceeds_ThenShouldReturnHealthyStatus() | ||
{ | ||
var healthCheckResult = await _fixture.SetPingSuccess().CheckHealthAsync(); | ||
|
||
Assert.AreEqual(HealthStatus.Healthy, healthCheckResult.Status); | ||
} | ||
|
||
[Test] | ||
public async Task CheckHealthAsync_WhenPingFails_ThenShouldReturnDegradedStatus() | ||
{ | ||
var healthCheckResult = await _fixture.SetPingFailure().CheckHealthAsync(); | ||
|
||
Assert.AreEqual(HealthStatus.Degraded, healthCheckResult.Status); | ||
Assert.AreEqual(_fixture.Exception.Message, healthCheckResult.Description); | ||
} | ||
|
||
private class ReservationsApiHealthCheckTestsFixture | ||
{ | ||
public HealthCheckContext HealthCheckContext { get; set; } | ||
public CancellationToken CancellationToken { get; set; } | ||
public Mock<IReservationsApiClient> ReservationsApiClient { get; set; } | ||
public ReservationsApiHealthCheck HealthCheck { get; set; } | ||
public Exception Exception { get; set; } | ||
|
||
public ReservationsApiHealthCheckTestsFixture() | ||
{ | ||
HealthCheckContext = new HealthCheckContext | ||
{ | ||
Registration = new HealthCheckRegistration("Foo", Mock.Of<IHealthCheck>(), null, null) | ||
}; | ||
|
||
ReservationsApiClient = new Mock<IReservationsApiClient>(); | ||
HealthCheck = new ReservationsApiHealthCheck(ReservationsApiClient.Object); | ||
Exception = new Exception("Foobar"); | ||
} | ||
|
||
public Task<HealthCheckResult> CheckHealthAsync() | ||
{ | ||
return HealthCheck.CheckHealthAsync(HealthCheckContext, CancellationToken); | ||
} | ||
|
||
public ReservationsApiHealthCheckTestsFixture SetPingSuccess() | ||
{ | ||
ReservationsApiClient.Setup(c => c.Ping(CancellationToken)).Returns(Task.CompletedTask); | ||
|
||
return this; | ||
} | ||
|
||
public ReservationsApiHealthCheckTestsFixture SetPingFailure() | ||
{ | ||
ReservationsApiClient.Setup(c => c.Ping(CancellationToken)).ThrowsAsync(Exception); | ||
|
||
return this; | ||
} | ||
} | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
...mentsV2/SFA.DAS.CommitmentsV2.Api/HealthChecks/ApprenticeshipInfoServiceApiHealthCheck.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,32 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
using SFA.DAS.Providers.Api.Client; | ||
|
||
namespace SFA.DAS.CommitmentsV2.Api.HealthChecks | ||
{ | ||
public class ApprenticeshipInfoServiceApiHealthCheck : IHealthCheck | ||
{ | ||
private readonly IProviderApiClient _providerApiClient; | ||
|
||
public ApprenticeshipInfoServiceApiHealthCheck(IProviderApiClient providerApiClient) | ||
{ | ||
_providerApiClient = providerApiClient; | ||
} | ||
|
||
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) | ||
{ | ||
try | ||
{ | ||
await _providerApiClient.FindAllAsync(); | ||
|
||
return HealthCheckResult.Healthy(); | ||
} | ||
catch (Exception exception) | ||
{ | ||
return HealthCheckResult.Degraded(exception.Message); | ||
} | ||
} | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api/HealthChecks/ReservationsApiHealthCheck.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,32 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
using SFA.DAS.Reservations.Api.Types; | ||
|
||
namespace SFA.DAS.CommitmentsV2.Api.HealthChecks | ||
{ | ||
public class ReservationsApiHealthCheck : IHealthCheck | ||
{ | ||
private readonly IReservationsApiClient _reservationsApiClient; | ||
|
||
public ReservationsApiHealthCheck(IReservationsApiClient reservationsApiClient) | ||
{ | ||
_reservationsApiClient = reservationsApiClient; | ||
} | ||
|
||
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) | ||
{ | ||
try | ||
{ | ||
await _reservationsApiClient.Ping(cancellationToken); | ||
|
||
return HealthCheckResult.Healthy(); | ||
} | ||
catch (Exception exception) | ||
{ | ||
return HealthCheckResult.Degraded(exception.Message); | ||
} | ||
} | ||
} | ||
} |
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
17 changes: 6 additions & 11 deletions
17
...cyResolution/TrainingProgrammeRegistry.cs → ...tion/ApprenticeshipInfoServiceRegistry.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
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
2 changes: 1 addition & 1 deletion
2
...AS.ReservationsV2.Api.Client.UnitTests/SFA.DAS.ReservationsV2.Api.Client.UnitTests.csproj
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.