Skip to content

Commit

Permalink
Merge pull request #408 from SkillsFundingAgency/DPP-1338_Show_Fundin…
Browse files Browse the repository at this point in the history
…g_Cap_To_Transfer_Sender

Dpp 1338 show funding cap to transfer sender
  • Loading branch information
m-nagashree authored Sep 13, 2018
2 parents 45c3add + a1de4b0 commit d5eb876
Show file tree
Hide file tree
Showing 40 changed files with 782 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ public class TransferRequest
public string ApprovedOrRejectedByUserName { get; set; }
public string ApprovedOrRejectedByUserEmail { get; set; }
public DateTime? ApprovedOrRejectedOn { get; set; }
public int FundingCap { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public class TransferRequestSummary
public DateTime? ApprovedOrRejectedOn { get; set; }
public TransferType TransferType { get; set; }
public DateTime CreatedOn { get; set; }
public int FundingCap { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void ThenMappingTheSourceObjectReturnsTheApiObjectValuesCorrectly()
result.TrainingList.Count.Should().Be(_courses.Count);
result.TrainingList[0].ApprenticeshipCount.Should().Be(_courses[0].ApprenticeshipCount);
result.TrainingList[0].CourseTitle.Should().Be(_courses[0].CourseTitle);

result.FundingCap.Should().Be(_source.FundingCap);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public void ThenMappingToNewObjectMatches()
result.ApprovedOrRejectedByUserEmail.Should().Be(_source[0].ApprovedOrRejectedByUserEmail);
result.ApprovedOrRejectedOn.Should().Be(_source[0].ApprovedOrRejectedOn);
result.CreatedOn.Should().Be(_source[0].CreatedOn);
result.FundingCap.Should().Be(_source[0].FundingCap);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public TransferRequestSummary MapFrom(Domain.Entities.TransferRequestSummary sou
HashedCohortRef = _hashingService.HashValue(source.CommitmentId),
HashedSendingEmployerAccountId = _hashingService.HashValue(source.SendingEmployerAccountId),
TransferCost = source.TransferCost,
FundingCap = source.FundingCap,
Status = (TransferApprovalStatus) source.Status,
ApprovedOrRejectedByUserName = source.ApprovedOrRejectedByUserName,
ApprovedOrRejectedByUserEmail = source.ApprovedOrRejectedByUserEmail,
Expand Down Expand Up @@ -54,11 +55,12 @@ public TransferRequest MapFrom(Domain.Entities.TransferRequest source)
TransferSenderName = source.TransferSenderName,
LegalEntityName = source.LegalEntityName,
TransferCost = source.TransferCost,
TrainingList = JsonConvert.DeserializeObject<List<Types.Commitment.TrainingCourseSummary>>(source.TrainingCourses),
TrainingList = JsonConvert.DeserializeObject<List<TrainingCourseSummary>>(source.TrainingCourses),
Status = (TransferApprovalStatus)source.Status,
ApprovedOrRejectedByUserName = source.ApprovedOrRejectedByUserName,
ApprovedOrRejectedByUserEmail = source.ApprovedOrRejectedByUserEmail,
ApprovedOrRejectedOn = source.ApprovedOrRejectedOn
ApprovedOrRejectedOn = source.ApprovedOrRejectedOn,
FundingCap = source.FundingCap
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using SFA.DAS.Commitments.Application.Commands.ApproveTransferRequest;
using SFA.DAS.Commitments.Application.Commands.SetPaymentOrder;
using SFA.DAS.Commitments.Application.Exceptions;
using SFA.DAS.Commitments.Application.Interfaces;
using SFA.DAS.Commitments.Application.Interfaces.ApprenticeshipEvents;
using SFA.DAS.Commitments.Application.Rules;
using SFA.DAS.Commitments.Domain.Data;
Expand Down Expand Up @@ -66,7 +67,8 @@ public void SetUp()
_sut = new ApproveTransferRequestCommandHandler(_validator, _commitmentRepository.Object,
_apprenticeshipRepository.Object, _overlapRules.Object, _currentDateTime.Object,
_apprenticeshipEventsList.Object, _apprenticeshipEventsPublisher.Object, _mediator.Object,
_messagePublisher.Object, _historyRepository.Object, Mock.Of<ICommitmentsLogger>());
_messagePublisher.Object, _historyRepository.Object, Mock.Of<ICommitmentsLogger>(),
Mock.Of<IApprenticeshipInfoService>());
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Moq;
using NUnit.Framework;
using SFA.DAS.Commitments.Application.Exceptions;
using SFA.DAS.Commitments.Application.Interfaces;
using SFA.DAS.Commitments.Application.Interfaces.ApprenticeshipEvents;
using SFA.DAS.Commitments.Application.Rules;
using SFA.DAS.Commitments.Domain;
Expand All @@ -30,6 +31,7 @@ public abstract class ApproveCohortTestBase<T> where T : IAsyncRequest
protected Mock<IApprenticeshipEventsPublisher> ApprenticeshipEventsPublisher;
protected Mock<IMediator> Mediator;
protected Mock<IMessagePublisher> MessagePublisher;
protected Mock<IApprenticeshipInfoService> ApprenticeshipInfoService;
protected AsyncRequestHandler<T> Target;
protected T Command;
protected Commitment Commitment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using SFA.DAS.Commitments.Application.Commands.CohortApproval.EmployerApproveCohort;
using SFA.DAS.Commitments.Application.Commands.SetPaymentOrder;
using SFA.DAS.Commitments.Application.Exceptions;
using SFA.DAS.Commitments.Application.Interfaces;
using SFA.DAS.Commitments.Domain;
using SFA.DAS.Commitments.Domain.Entities;
using SFA.DAS.Commitments.Domain.Entities.History;
Expand All @@ -29,7 +30,18 @@ public void SetUp()
CommitmentRepository.Setup(x => x.GetCommitmentById(Command.CommitmentId)).ReturnsAsync(Commitment);
SetupSuccessfulOverlapCheck();

Target = new EmployerApproveCohortCommandHandler(Validator, CommitmentRepository.Object, ApprenticeshipRepository.Object, OverlapRules.Object, CurrentDateTime.Object, HistoryRepository.Object, ApprenticeshipEventsList.Object, ApprenticeshipEventsPublisher.Object, Mediator.Object, MessagePublisher.Object, Mock.Of<ICommitmentsLogger>());
Target = new EmployerApproveCohortCommandHandler(Validator,
CommitmentRepository.Object,
ApprenticeshipRepository.Object,
OverlapRules.Object,
CurrentDateTime.Object,
HistoryRepository.Object,
ApprenticeshipEventsList.Object,
ApprenticeshipEventsPublisher.Object,
Mediator.Object,
MessagePublisher.Object,
Mock.Of<ICommitmentsLogger>(),
Mock.Of<IApprenticeshipInfoService>());
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
using NUnit.Framework;
using SFA.DAS.Commitments.Application.Commands.CohortApproval.EmployerApproveCohort;
using SFA.DAS.Commitments.Application.Commands.SetPaymentOrder;
using SFA.DAS.Commitments.Application.Interfaces;
using SFA.DAS.Commitments.Domain;
using SFA.DAS.Commitments.Domain.Entities;
using SFA.DAS.Commitments.Domain.Entities.TrainingProgramme;
using SFA.DAS.Commitments.Domain.Interfaces;
using SFA.DAS.Commitments.Events;
using SFA.DAS.Messaging.Interfaces;
Expand All @@ -27,7 +29,7 @@ public void SetUp()
SetUpCommonMocks();
Commitment = CreateCommitment(Command.CommitmentId, Command.Caller.Id, 234587, 1000, "Nice Company");
CommitmentRepository.Setup(x => x.GetCommitmentById(Command.CommitmentId)).ReturnsAsync(Commitment);
CommitmentRepository.Setup(x => x.StartTransferRequestApproval(It.IsAny<long>(), It.IsAny<decimal>(),
CommitmentRepository.Setup(x => x.StartTransferRequestApproval(It.IsAny<long>(), It.IsAny<decimal>(), It.IsAny<int>(),
It.IsAny<List<TrainingCourseSummary>>())).ReturnsAsync(_transferRequestId);

Commitment.Apprenticeships.ForEach(x => x.AgreementStatus = AgreementStatus.ProviderAgreed);
Expand All @@ -36,7 +38,28 @@ public void SetUp()

_messagePublisher = new Mock<IMessagePublisher>();

Target = new EmployerApproveCohortCommandHandler(Validator, CommitmentRepository.Object, ApprenticeshipRepository.Object, OverlapRules.Object, CurrentDateTime.Object, HistoryRepository.Object, ApprenticeshipEventsList.Object, ApprenticeshipEventsPublisher.Object, Mediator.Object, _messagePublisher.Object, Mock.Of<ICommitmentsLogger>());
ApprenticeshipInfoService = new Mock<IApprenticeshipInfoService>();
ApprenticeshipInfoService.Setup(x => x.GetTrainingProgram(It.IsAny<string>()))
.ReturnsAsync(new Standard
{
FundingPeriods = new List<FundingPeriod>
{
new FundingPeriod {FundingCap = 1000}
}
});

Target = new EmployerApproveCohortCommandHandler(Validator,
CommitmentRepository.Object,
ApprenticeshipRepository.Object,
OverlapRules.Object,
CurrentDateTime.Object,
HistoryRepository.Object,
ApprenticeshipEventsList.Object,
ApprenticeshipEventsPublisher.Object,
Mediator.Object,
_messagePublisher.Object,
Mock.Of<ICommitmentsLogger>(),
ApprenticeshipInfoService.Object);
}

[Test]
Expand All @@ -47,8 +70,7 @@ public async Task ThenIfTheProviderHasAlreadyApprovedAMessageIsPublishedToTransf
_messagePublisher.Verify(x => x.PublishAsync(It.Is<CohortApprovalByTransferSenderRequested>(y =>
y.TransferRequestId == _transferRequestId &&
y.ReceivingEmployerAccountId == Commitment.EmployerAccountId &&
y.CommitmentId == Commitment.Id && y.SendingEmployerAccountId == Commitment.TransferSenderId &&
y.TransferCost == Commitment.Apprenticeships.Sum(a => a.Cost ?? 0))), Times.Once);
y.CommitmentId == Commitment.Id && y.SendingEmployerAccountId == Commitment.TransferSenderId)), Times.Once);
}

[Test]
Expand Down Expand Up @@ -80,15 +102,12 @@ public async Task ThenIfTheProviderHasAlreadyApprovedDoNotSetAStartDateForTheApp
[Test]
public async Task ThenEnsureTheStartATransferRequestInRepositoryIsCalled()
{
var expectedTotal = (decimal)Commitment.Apprenticeships.Sum(i => i.Cost);

await Target.Handle(Command);

CommitmentRepository.Verify(x => x.StartTransferRequestApproval(Commitment.Id,
expectedTotal, It.Is<List<TrainingCourseSummary>>(p =>
It.IsAny<decimal>(), It.IsAny<int>(), It.Is<List<TrainingCourseSummary>>(p =>
p.Count == 1 && p[0].ApprenticeshipCount == 2 &&
p[0].CourseTitle == Commitment.Apprenticeships[0].TrainingName)));

}

[Test]
Expand All @@ -104,6 +123,5 @@ public async Task ThenIfTheProviderHasAlreadyApprovedThenEventsEmittedShouldIndi
null
), Times.Exactly(Commitment.Apprenticeships.Count));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using SFA.DAS.Commitments.Application.Commands.CohortApproval.ProiderApproveCohort;
using SFA.DAS.Commitments.Application.Commands.SetPaymentOrder;
using SFA.DAS.Commitments.Application.Exceptions;
using SFA.DAS.Commitments.Application.Interfaces;
using SFA.DAS.Commitments.Domain;
using SFA.DAS.Commitments.Domain.Entities;
using SFA.DAS.Commitments.Domain.Entities.History;
Expand All @@ -32,7 +33,18 @@ public void SetUp()
CommitmentRepository.Setup(x => x.GetCommitmentById(Command.CommitmentId)).ReturnsAsync(Commitment);
SetupSuccessfulOverlapCheck();

Target = new ProviderApproveCohortCommandHandler(Validator, CommitmentRepository.Object, ApprenticeshipRepository.Object, OverlapRules.Object, CurrentDateTime.Object, HistoryRepository.Object, ApprenticeshipEventsList.Object, ApprenticeshipEventsPublisher.Object, Mediator.Object, MessagePublisher.Object, Mock.Of<ICommitmentsLogger>());
Target = new ProviderApproveCohortCommandHandler(Validator,
CommitmentRepository.Object,
ApprenticeshipRepository.Object,
OverlapRules.Object,
CurrentDateTime.Object,
HistoryRepository.Object,
ApprenticeshipEventsList.Object,
ApprenticeshipEventsPublisher.Object,
Mediator.Object,
MessagePublisher.Object,
Mock.Of<ICommitmentsLogger>(),
Mock.Of<IApprenticeshipInfoService>());
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
using NUnit.Framework;
using SFA.DAS.Commitments.Application.Commands.CohortApproval.ProiderApproveCohort;
using SFA.DAS.Commitments.Application.Commands.SetPaymentOrder;
using SFA.DAS.Commitments.Application.Interfaces;
using SFA.DAS.Commitments.Domain;
using SFA.DAS.Commitments.Domain.Entities;
using SFA.DAS.Commitments.Domain.Entities.TrainingProgramme;
using SFA.DAS.Commitments.Domain.Interfaces;
using SFA.DAS.Commitments.Events;
using SFA.DAS.Commitments.Infrastructure.Services;

namespace SFA.DAS.Commitments.Application.UnitTests.Commands.CohortApproval.ProviderApproveCohort
{
Expand All @@ -28,26 +31,45 @@ public void SetUp()
Commitment = CreateCommitment(Command.CommitmentId, 11234, Command.Caller.Id, 1000, "Nice Company");
Commitment.EditStatus = EditStatus.ProviderOnly;
Commitment.Apprenticeships.ForEach(x => x.AgreementStatus = AgreementStatus.EmployerAgreed);
CommitmentRepository.Setup(x => x.StartTransferRequestApproval(It.IsAny<long>(), It.IsAny<decimal>(),
CommitmentRepository.Setup(x => x.StartTransferRequestApproval(It.IsAny<long>(), It.IsAny<decimal>(), It.IsAny<int>(),
It.IsAny<List<TrainingCourseSummary>>())).ReturnsAsync(_transferRequestId);

CommitmentRepository.Setup(x => x.GetCommitmentById(Command.CommitmentId)).ReturnsAsync(Commitment);
SetupSuccessfulOverlapCheck();

Target = new ProviderApproveCohortCommandHandler(Validator, CommitmentRepository.Object, ApprenticeshipRepository.Object, OverlapRules.Object, CurrentDateTime.Object, HistoryRepository.Object, ApprenticeshipEventsList.Object, ApprenticeshipEventsPublisher.Object, Mediator.Object, MessagePublisher.Object, Mock.Of<ICommitmentsLogger>());
ApprenticeshipInfoService = new Mock<IApprenticeshipInfoService>();
ApprenticeshipInfoService.Setup(x => x.GetTrainingProgram(It.IsAny<string>()))
.ReturnsAsync(new Standard
{
FundingPeriods = new List<FundingPeriod>
{
new FundingPeriod {FundingCap = 1000}
}
});

Target = new ProviderApproveCohortCommandHandler(Validator,
CommitmentRepository.Object,
ApprenticeshipRepository.Object,
OverlapRules.Object,
CurrentDateTime.Object,
HistoryRepository.Object,
ApprenticeshipEventsList.Object,
ApprenticeshipEventsPublisher.Object,
Mediator.Object,
MessagePublisher.Object,
Mock.Of<ICommitmentsLogger>(),
ApprenticeshipInfoService.Object);
}

[Test]
public async Task ThenIfTheEmployerHasAlreadyApprovedAMessageIsPublishedToTransferSender()
{

await Target.Handle(Command);

MessagePublisher.Verify(x => x.PublishAsync(It.Is<CohortApprovalByTransferSenderRequested>(y =>
y.TransferRequestId == _transferRequestId &&
y.ReceivingEmployerAccountId == Commitment.EmployerAccountId &&
y.CommitmentId == Commitment.Id && y.SendingEmployerAccountId == Commitment.TransferSenderId &&
y.TransferCost == Commitment.Apprenticeships.Sum(a => a.Cost ?? 0))), Times.Once);
y.CommitmentId == Commitment.Id && y.SendingEmployerAccountId == Commitment.TransferSenderId)), Times.Once);
}

[Test]
Expand Down Expand Up @@ -81,12 +103,10 @@ public async Task ThenIfTheEmployerHasAlreadyApprovedDoNotSetAStartDateForTheApp
[Test]
public async Task ThenEnsureTheStartATransferRequestInRepositoryIsCalled()
{
var expectedTotal = (decimal)Commitment.Apprenticeships.Sum(i => i.Cost);

await Target.Handle(Command);

CommitmentRepository.Verify(x => x.StartTransferRequestApproval(Commitment.Id,
expectedTotal, It.Is<List<TrainingCourseSummary>>(p =>
It.IsAny<decimal>(), It.IsAny<int>(), It.Is<List<TrainingCourseSummary>>(p =>
p.Count == 1 && p[0].ApprenticeshipCount == 2 &&
p[0].CourseTitle == Commitment.Apprenticeships[0].TrainingName)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using NUnit.Framework;
using SFA.DAS.Commitments.Application.Commands.RejectTransferRequest;
using SFA.DAS.Commitments.Application.Exceptions;
using SFA.DAS.Commitments.Application.Interfaces;
using SFA.DAS.Commitments.Application.Interfaces.ApprenticeshipEvents;
using SFA.DAS.Commitments.Application.Rules;
using SFA.DAS.Commitments.Domain.Data;
Expand Down Expand Up @@ -71,7 +72,8 @@ public void SetUp()
_sut = new RejectTransferRequestCommandHandler(_validator, _commitmentRepository.Object,
_apprenticeshipRepository.Object, _overlapRules.Object, _currentDateTime.Object,
_apprenticeshipEventsList.Object, _apprenticeshipEventsPublisher.Object, _mediator.Object,
_messagePublisher.Object, _historyRepository.Object, Mock.Of<ICommitmentsLogger>());
_messagePublisher.Object, _historyRepository.Object, Mock.Of<ICommitmentsLogger>(),
Mock.Of<IApprenticeshipInfoService>());
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using NUnit.Framework;
using SFA.DAS.Commitments.Application.Extensions;

namespace SFA.DAS.Commitments.Application.UnitTests.Extensions.DateTimeExtensions
{
[TestFixture]
public class WhenGettingFirstOfMonth
{
[TestCase("2018-06-15", "2018-06-01 00:00:00")]
[TestCase("2018-06-01 18:35:14", "2018-06-01 00:00:00")]
public void ThenTheFirstDayOfTheMonthIsReturned(DateTime value, DateTime expectResult)
{
Assert.AreEqual(expectResult, value.FirstOfMonth());
}
}
}
Loading

0 comments on commit d5eb876

Please sign in to comment.