diff --git a/src/SFA.DAS.Commitments.Application.UnitTests/Commands/ApproveDataLockTriage/WhenApprovingDataLockTriage.cs b/src/SFA.DAS.Commitments.Application.UnitTests/Commands/ApproveDataLockTriage/WhenApprovingDataLockTriage.cs index 6c62dc77e7..bad3cfa6b2 100644 --- a/src/SFA.DAS.Commitments.Application.UnitTests/Commands/ApproveDataLockTriage/WhenApprovingDataLockTriage.cs +++ b/src/SFA.DAS.Commitments.Application.UnitTests/Commands/ApproveDataLockTriage/WhenApprovingDataLockTriage.cs @@ -257,7 +257,7 @@ public async Task ShouldNotUpdateApprenticeshipIfApprenticeshipHasHadSuccessData _dataLockRepository.Verify(m => m.ResolveDataLock(It.IsAny>()), Times.Once); - _apprenticeshipTrainingService.Verify(m => m.GetTrainingProgramAsync(It.IsAny(), false), Times.Never); + _apprenticeshipTrainingService.Verify(m => m.GetTrainingProgram(It.IsAny()), Times.Never); _apprenticeshipRepository.Verify(m => m.UpdateApprenticeship(It.IsAny(), new Caller()), Times.Never); } @@ -280,7 +280,7 @@ public async Task ShouldUpdateApprenticeshipIfCourseHasChanged() _apprenticeshipRepository.Setup(m => m.GetApprenticeship(_command.ApprenticeshipId)) .ReturnsAsync(new Apprenticeship { CommitmentId = 123456L, HasHadDataLockSuccess = false, EmployerAccountId = 12345 }); - _apprenticeshipTrainingService.Setup(m => m.GetTrainingProgramAsync($"{trainingCode}", false)) + _apprenticeshipTrainingService.Setup(m => m.GetTrainingProgram($"{trainingCode}")) .ReturnsAsync(standard); Apprenticeship updatedApprenticeship = null; @@ -293,7 +293,7 @@ public async Task ShouldUpdateApprenticeshipIfCourseHasChanged() _dataLockRepository.Verify(m => m.ResolveDataLock(It.IsAny>()), Times.Once); - _apprenticeshipTrainingService.Verify(m => m.GetTrainingProgramAsync(standard.Code.ToString(), false), Times.Once); + _apprenticeshipTrainingService.Verify(m => m.GetTrainingProgram(standard.Code.ToString()), Times.Once); _apprenticeshipRepository.Verify(m => m.UpdateApprenticeship(It.IsAny(), It.IsAny()), Times.Once); updatedApprenticeship.TrainingCode.Should().Be(standard.Code.ToString()); @@ -320,14 +320,14 @@ public async Task ShouldNotUpdateApprenticeshipIfCourseIsTheSame() _apprenticeshipRepository.Setup(m => m.GetApprenticeship(_command.ApprenticeshipId)) .ReturnsAsync(new Apprenticeship { CommitmentId = 123456L, HasHadDataLockSuccess = false, EmployerAccountId = 12345, TrainingCode = $"{trainingCode}"}); - _apprenticeshipTrainingService.Setup(m => m.GetTrainingProgramAsync($"{trainingCode}", false)) + _apprenticeshipTrainingService.Setup(m => m.GetTrainingProgram($"{trainingCode}")) .ReturnsAsync(standard); await _sut.Handle(_command); _dataLockRepository.Verify(m => m.ResolveDataLock(It.IsAny>()), Times.Once); - _apprenticeshipTrainingService.Verify(m => m.GetTrainingProgramAsync(It.IsAny(), false), Times.Never); + _apprenticeshipTrainingService.Verify(m => m.GetTrainingProgram(It.IsAny()), Times.Never); _apprenticeshipRepository.Verify(m => m.UpdateApprenticeship(It.IsAny(), It.IsAny()), Times.Never); } diff --git a/src/SFA.DAS.Commitments.Application/Commands/ApproveDataLockTriage/ApproveDataLockTriageCommandHandler.cs b/src/SFA.DAS.Commitments.Application/Commands/ApproveDataLockTriage/ApproveDataLockTriageCommandHandler.cs index 906b9e715b..31c938ce14 100644 --- a/src/SFA.DAS.Commitments.Application/Commands/ApproveDataLockTriage/ApproveDataLockTriageCommandHandler.cs +++ b/src/SFA.DAS.Commitments.Application/Commands/ApproveDataLockTriage/ApproveDataLockTriageCommandHandler.cs @@ -83,7 +83,7 @@ protected override async Task HandleCore(ApproveDataLockTriageCommand command) if (dataLockWithUpdatedTraining != null) { var training = await - _apprenticeshipTrainingService.GetTrainingProgramAsync(dataLockWithUpdatedTraining.IlrTrainingCourseCode); + _apprenticeshipTrainingService.GetTrainingProgram(dataLockWithUpdatedTraining.IlrTrainingCourseCode); _logger.Info($"Updating course for apprenticeship {apprenticeship.Id} from training code {apprenticeship.TrainingCode} to {dataLockWithUpdatedTraining.IlrTrainingCourseCode}"); diff --git a/src/SFA.DAS.Commitments.Application/Interfaces/IApprenticeshipInfoService.cs b/src/SFA.DAS.Commitments.Application/Interfaces/IApprenticeshipInfoService.cs index 98fb168508..197d2c49b7 100644 --- a/src/SFA.DAS.Commitments.Application/Interfaces/IApprenticeshipInfoService.cs +++ b/src/SFA.DAS.Commitments.Application/Interfaces/IApprenticeshipInfoService.cs @@ -1,13 +1,12 @@ using System.Threading.Tasks; - using SFA.DAS.Commitments.Domain.Entities.TrainingProgramme; namespace SFA.DAS.Commitments.Application.Interfaces { public interface IApprenticeshipInfoService { - Task GetStandardsAsync(bool refreshCache = false); - Task GetFrameworksAsync(bool refreshCache = false); - Task GetTrainingProgramAsync(string id, bool refreshCache = false); + Task GetStandards(bool refreshCache = false); + Task GetFrameworks(bool refreshCache = false); + Task GetTrainingProgram(string id); } } diff --git a/src/SFA.DAS.Commitments.Infrastructure/Services/ApprenticeshipInfoService.cs b/src/SFA.DAS.Commitments.Infrastructure/Services/ApprenticeshipInfoService.cs index 5685979d9e..a3874d8452 100644 --- a/src/SFA.DAS.Commitments.Infrastructure/Services/ApprenticeshipInfoService.cs +++ b/src/SFA.DAS.Commitments.Infrastructure/Services/ApprenticeshipInfoService.cs @@ -1,6 +1,5 @@ using System.Linq; using System.Threading.Tasks; - using SFA.DAS.Apprenticeships.Api.Client; using SFA.DAS.Commitments.Application.Interfaces; using SFA.DAS.Commitments.Domain.Entities.TrainingProgramme; @@ -26,7 +25,7 @@ public ApprenticeshipInfoService(ICache cache, _mapper = mapper; } - public async Task GetStandardsAsync(bool refreshCache = false) + public async Task GetStandards(bool refreshCache = false) { if (!await _cache.ExistsAsync(StandardsKey) || refreshCache) { @@ -40,7 +39,7 @@ public async Task GetStandardsAsync(bool refreshCache = false) return await _cache.GetCustomValueAsync(StandardsKey); } - public async Task GetFrameworksAsync(bool refreshCache = false) + public async Task GetFrameworks(bool refreshCache = false) { if (!await _cache.ExistsAsync(FrameworksKey) || refreshCache) { @@ -54,18 +53,16 @@ public async Task GetFrameworksAsync(bool refreshCache = false) return await _cache.GetCustomValueAsync(FrameworksKey); } - public async Task GetTrainingProgramAsync(string id, bool refreshCache = false) + public async Task GetTrainingProgram(string id) { - var standardsTask = GetStandardsAsync(); - var frameworksTask = GetFrameworksAsync(); - - await Task.WhenAll(standardsTask, frameworksTask); + var standardsTask = GetStandards(); + var frameworksTask = GetFrameworks(); - var programmes = standardsTask.Result.Standards.Union(frameworksTask.Result.Frameworks.Cast()) - .OrderBy(m => m.Title) - .ToList(); + var program = (await standardsTask).Standards.FirstOrDefault(m => m.Id == id); + if (program != null) + return program; - return programmes.FirstOrDefault(m => m.Id == id); + return (await frameworksTask).Frameworks.FirstOrDefault(m => m.Id == id); } } } \ No newline at end of file