Skip to content

Commit

Permalink
rename GetXxxAsync -> GetXxx
Browse files Browse the repository at this point in the history
+ optimisation and tidy up
  • Loading branch information
lazcool committed Aug 28, 2018
1 parent 1e4cf98 commit 1e63858
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public async Task ShouldNotUpdateApprenticeshipIfApprenticeshipHasHadSuccessData
_dataLockRepository.Verify(m => m.ResolveDataLock(It.IsAny<IEnumerable<long>>()), Times.Once);


_apprenticeshipTrainingService.Verify(m => m.GetTrainingProgramAsync(It.IsAny<string>(), false), Times.Never);
_apprenticeshipTrainingService.Verify(m => m.GetTrainingProgram(It.IsAny<string>()), Times.Never);
_apprenticeshipRepository.Verify(m => m.UpdateApprenticeship(It.IsAny<Apprenticeship>(), new Caller()), Times.Never);
}

Expand All @@ -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;
Expand All @@ -293,7 +293,7 @@ public async Task ShouldUpdateApprenticeshipIfCourseHasChanged()

_dataLockRepository.Verify(m => m.ResolveDataLock(It.IsAny<IEnumerable<long>>()), 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<Apprenticeship>(), It.IsAny<Caller>()), Times.Once);

updatedApprenticeship.TrainingCode.Should().Be(standard.Code.ToString());
Expand All @@ -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<IEnumerable<long>>()), Times.Once);

_apprenticeshipTrainingService.Verify(m => m.GetTrainingProgramAsync(It.IsAny<string>(), false), Times.Never);
_apprenticeshipTrainingService.Verify(m => m.GetTrainingProgram(It.IsAny<string>()), Times.Never);
_apprenticeshipRepository.Verify(m => m.UpdateApprenticeship(It.IsAny<Apprenticeship>(), It.IsAny<Caller>()), Times.Never);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}");

Expand Down
Original file line number Diff line number Diff line change
@@ -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<StandardsView> GetStandardsAsync(bool refreshCache = false);
Task<FrameworksView> GetFrameworksAsync(bool refreshCache = false);
Task<ITrainingProgramme> GetTrainingProgramAsync(string id, bool refreshCache = false);
Task<StandardsView> GetStandards(bool refreshCache = false);
Task<FrameworksView> GetFrameworks(bool refreshCache = false);
Task<ITrainingProgramme> GetTrainingProgram(string id);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -26,7 +25,7 @@ public ApprenticeshipInfoService(ICache cache,
_mapper = mapper;
}

public async Task<StandardsView> GetStandardsAsync(bool refreshCache = false)
public async Task<StandardsView> GetStandards(bool refreshCache = false)
{
if (!await _cache.ExistsAsync(StandardsKey) || refreshCache)
{
Expand All @@ -40,7 +39,7 @@ public async Task<StandardsView> GetStandardsAsync(bool refreshCache = false)
return await _cache.GetCustomValueAsync<StandardsView>(StandardsKey);
}

public async Task<FrameworksView> GetFrameworksAsync(bool refreshCache = false)
public async Task<FrameworksView> GetFrameworks(bool refreshCache = false)
{
if (!await _cache.ExistsAsync(FrameworksKey) || refreshCache)
{
Expand All @@ -54,18 +53,16 @@ public async Task<FrameworksView> GetFrameworksAsync(bool refreshCache = false)
return await _cache.GetCustomValueAsync<FrameworksView>(FrameworksKey);
}

public async Task<ITrainingProgramme> GetTrainingProgramAsync(string id, bool refreshCache = false)
public async Task<ITrainingProgramme> 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<ITrainingProgramme>())
.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);
}
}
}

0 comments on commit 1e63858

Please sign in to comment.