From 468c91c74be6b811026d60f387e893bfb8641259 Mon Sep 17 00:00:00 2001 From: Daniel Ashton Date: Tue, 2 Feb 2021 22:25:58 +0000 Subject: [PATCH] Update from merge on ConfirmDetailsAndSendViewModelMapper --- ...nfirmDetailsAndSendViewModelMapperTests.cs | 28 +++++++++---------- .../ConfirmDetailsAndSendViewModelMapper.cs | 15 ++++------ 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/ConfirmDetailsAndSendViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/ConfirmDetailsAndSendViewModelMapperTests.cs index 1785d2ec1..14ee2ad5b 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/ConfirmDetailsAndSendViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/ConfirmDetailsAndSendViewModelMapperTests.cs @@ -1,8 +1,6 @@ using AutoFixture; using Moq; using NUnit.Framework; -using SFA.DAS.Apprenticeships.Api.Client; -using SFA.DAS.Apprenticeships.Api.Types; using SFA.DAS.CommitmentsV2.Api.Client; using SFA.DAS.CommitmentsV2.Api.Types.Responses; using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Apprentice; @@ -11,6 +9,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using SFA.DAS.CommitmentsV2.Types; using static SFA.DAS.CommitmentsV2.Api.Types.Responses.GetPriceEpisodesResponse; namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Mappers.Apprentice @@ -18,15 +17,14 @@ namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Mappers.Apprentice public class ConfirmDetailsAndSendViewModelMapperTests { private Mock _mockCommitmentsApiClient; - private Mock _mockTrainingProgrammeApiClient; private ChangeOfProviderRequest _request; private GetApprenticeshipResponse _apprenticeshipResponse; private GetPriceEpisodesResponse _priceEpisodeResponse; - private StandardSummary _standardSummary; - + private ConfirmDetailsAndSendViewModelMapper _mapper; + private TrainingProgramme _standardSummary; [SetUp] public void Arrange() @@ -50,22 +48,24 @@ public void Arrange() new PriceEpisode { Cost = 2000, ToDate = null } }) .Create(); - _standardSummary = autoFixture.Create(); + _standardSummary = autoFixture.Create(); _standardSummary.EffectiveFrom = new DateTime(2018, 1, 1); _standardSummary.EffectiveTo = new DateTime(2022, 1, 1); _standardSummary.FundingPeriods = SetPriceBand(1000); _mockCommitmentsApiClient = new Mock(); - _mockTrainingProgrammeApiClient = new Mock(); _mockCommitmentsApiClient.Setup(c => c.GetApprenticeship(It.IsAny(), It.IsAny())) .ReturnsAsync(_apprenticeshipResponse); _mockCommitmentsApiClient.Setup(c => c.GetPriceEpisodes(It.IsAny(), It.IsAny())) .ReturnsAsync(_priceEpisodeResponse); - _mockTrainingProgrammeApiClient.Setup(t => t.GetTrainingProgramme(_apprenticeshipResponse.CourseCode)) - .ReturnsAsync(_standardSummary); + _mockCommitmentsApiClient.Setup(t => t.GetTrainingProgramme(_apprenticeshipResponse.CourseCode, It.IsAny())) + .ReturnsAsync(new GetTrainingProgrammeResponse + { + TrainingProgramme = _standardSummary + }); - _mapper = new ConfirmDetailsAndSendViewModelMapper(_mockCommitmentsApiClient.Object, _mockTrainingProgrammeApiClient.Object); + _mapper = new ConfirmDetailsAndSendViewModelMapper(_mockCommitmentsApiClient.Object); } [Test] @@ -73,7 +73,7 @@ public async Task GetFundingCapIsCalled() { var result = await _mapper.Map(_request); - _mockTrainingProgrammeApiClient.Verify(t => t.GetTrainingProgramme(_apprenticeshipResponse.CourseCode), Times.Once()); + _mockCommitmentsApiClient.Verify(t => t.GetTrainingProgramme(_apprenticeshipResponse.CourseCode, It.IsAny()), Times.Once()); } [Test] @@ -119,11 +119,11 @@ public async Task ExceedsMaxFunding_IsMapped(int newPrice, bool expectsExceedsMa Assert.AreEqual(expectsExceedsMaxFunding, result.ExceedsMaxFunding); } - public List SetPriceBand(int fundingCap) + public List SetPriceBand(int fundingCap) { - return new List + return new List { - new FundingPeriod + new TrainingProgrammeFundingPeriod { EffectiveFrom = new DateTime(2019, 1, 1), EffectiveTo = DateTime.Now.AddMonths(1), diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Apprentice/ConfirmDetailsAndSendViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Apprentice/ConfirmDetailsAndSendViewModelMapper.cs index 24332cd3f..ac931bbe5 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Apprentice/ConfirmDetailsAndSendViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Apprentice/ConfirmDetailsAndSendViewModelMapper.cs @@ -1,24 +1,21 @@ -using SFA.DAS.Apprenticeships.Api.Client; -using SFA.DAS.Apprenticeships.Api.Types; -using SFA.DAS.CommitmentsV2.Api.Client; +using SFA.DAS.CommitmentsV2.Api.Client; using SFA.DAS.CommitmentsV2.Shared.Interfaces; using SFA.DAS.EmployerCommitmentsV2.Web.Extensions; using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice; using System; using System.Threading; using System.Threading.Tasks; +using SFA.DAS.CommitmentsV2.Types; namespace SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Apprentice { public class ConfirmDetailsAndSendViewModelMapper : IMapper { private readonly ICommitmentsApiClient _commitmentsApiClient; - private readonly ITrainingProgrammeApiClient _trainingProgrammeApiClient; - public ConfirmDetailsAndSendViewModelMapper(ICommitmentsApiClient commitmentsApiClient, ITrainingProgrammeApiClient trainingProgrammeApiClient) + public ConfirmDetailsAndSendViewModelMapper(ICommitmentsApiClient commitmentsApiClient) { _commitmentsApiClient = commitmentsApiClient; - _trainingProgrammeApiClient = trainingProgrammeApiClient; } public async Task Map(ChangeOfProviderRequest source) @@ -26,7 +23,7 @@ public async Task Map(ChangeOfProviderRequest so var apprenticeship = await _commitmentsApiClient.GetApprenticeship(source.ApprenticeshipId.Value, CancellationToken.None); var priceHistory = await _commitmentsApiClient.GetPriceEpisodes(source.ApprenticeshipId.Value, CancellationToken.None); - var course = await _trainingProgrammeApiClient.GetTrainingProgramme(apprenticeship.CourseCode); + var course = await _commitmentsApiClient.GetTrainingProgramme(apprenticeship.CourseCode); var newStartDate = new DateTime(source.NewStartYear.Value, source.NewStartMonth.Value, 1); var result = new ConfirmDetailsAndSendViewModel @@ -45,13 +42,13 @@ public async Task Map(ChangeOfProviderRequest so CurrentEndDate = apprenticeship.EndDate, CurrentPrice = decimal.ToInt32(priceHistory.PriceEpisodes.GetPrice()), EmployerWillAdd = source.EmployerWillAdd, - MaxFunding = GetFundingBandCap(course, newStartDate), + MaxFunding = GetFundingBandCap(course.TrainingProgramme, newStartDate), }; return result; } - private int? GetFundingBandCap(ITrainingProgramme course, DateTime? startDate) + private int? GetFundingBandCap(TrainingProgramme course, DateTime? startDate) { if (course == null) {