Skip to content

Commit

Permalink
Update from merge on ConfirmDetailsAndSendViewModelMapper
Browse files Browse the repository at this point in the history
  • Loading branch information
dashton82 committed Feb 2, 2021
1 parent 83bcfad commit 468c91c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,22 +9,22 @@
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
{
public class ConfirmDetailsAndSendViewModelMapperTests
{
private Mock<ICommitmentsApiClient> _mockCommitmentsApiClient;
private Mock<ITrainingProgrammeApiClient> _mockTrainingProgrammeApiClient;

private ChangeOfProviderRequest _request;

private GetApprenticeshipResponse _apprenticeshipResponse;
private GetPriceEpisodesResponse _priceEpisodeResponse;
private StandardSummary _standardSummary;


private ConfirmDetailsAndSendViewModelMapper _mapper;
private TrainingProgramme _standardSummary;

[SetUp]
public void Arrange()
Expand All @@ -50,30 +48,32 @@ public void Arrange()
new PriceEpisode { Cost = 2000, ToDate = null } })
.Create();

_standardSummary = autoFixture.Create<StandardSummary>();
_standardSummary = autoFixture.Create<TrainingProgramme>();
_standardSummary.EffectiveFrom = new DateTime(2018, 1, 1);
_standardSummary.EffectiveTo = new DateTime(2022, 1, 1);
_standardSummary.FundingPeriods = SetPriceBand(1000);

_mockCommitmentsApiClient = new Mock<ICommitmentsApiClient>();
_mockTrainingProgrammeApiClient = new Mock<ITrainingProgrammeApiClient>();

_mockCommitmentsApiClient.Setup(c => c.GetApprenticeship(It.IsAny<long>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(_apprenticeshipResponse);
_mockCommitmentsApiClient.Setup(c => c.GetPriceEpisodes(It.IsAny<long>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(_priceEpisodeResponse);
_mockTrainingProgrammeApiClient.Setup(t => t.GetTrainingProgramme(_apprenticeshipResponse.CourseCode))
.ReturnsAsync(_standardSummary);
_mockCommitmentsApiClient.Setup(t => t.GetTrainingProgramme(_apprenticeshipResponse.CourseCode, It.IsAny<CancellationToken>()))
.ReturnsAsync(new GetTrainingProgrammeResponse
{
TrainingProgramme = _standardSummary
});

_mapper = new ConfirmDetailsAndSendViewModelMapper(_mockCommitmentsApiClient.Object, _mockTrainingProgrammeApiClient.Object);
_mapper = new ConfirmDetailsAndSendViewModelMapper(_mockCommitmentsApiClient.Object);
}

[Test]
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<CancellationToken>()), Times.Once());
}

[Test]
Expand Down Expand Up @@ -119,11 +119,11 @@ public async Task ExceedsMaxFunding_IsMapped(int newPrice, bool expectsExceedsMa
Assert.AreEqual(expectsExceedsMaxFunding, result.ExceedsMaxFunding);
}

public List<FundingPeriod> SetPriceBand(int fundingCap)
public List<TrainingProgrammeFundingPeriod> SetPriceBand(int fundingCap)
{
return new List<FundingPeriod>
return new List<TrainingProgrammeFundingPeriod>
{
new FundingPeriod
new TrainingProgrammeFundingPeriod
{
EffectiveFrom = new DateTime(2019, 1, 1),
EffectiveTo = DateTime.Now.AddMonths(1),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
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<ChangeOfProviderRequest, ConfirmDetailsAndSendViewModel>
{
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<ConfirmDetailsAndSendViewModel> Map(ChangeOfProviderRequest source)
{
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
Expand All @@ -45,13 +42,13 @@ public async Task<ConfirmDetailsAndSendViewModel> 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)
{
Expand Down

0 comments on commit 468c91c

Please sign in to comment.