private void CreateCommitmentModel(decimal monthlyInstallment, decimal completionAmount) { _commitment = new CommitmentModel { EmployerAccountId = 1, ApprenticeshipId = 2, LearnerId = 3, StartDate = DateTime.Today.AddMonths(-1), PlannedEndDate = DateTime.Today.AddMonths(25), MonthlyInstallment = monthlyInstallment, NumberOfInstallments = 4, CompletionAmount = completionAmount, FundingSource = Models.Payments.FundingSource.Levy }; _commitments = new EmployerCommitmentsModel { LevyFundedCommitments = new List <CommitmentModel> { _commitment } }; var employerCommitments = new EmployerCommitments(1, _commitments); Moqer.SetInstance(employerCommitments); }
public async Task <IAccountEstimationProjection> Get(AccountEstimation accountEstimation, bool showExpiredFunds = false) { var balance = await _currentBalanceRepository.Get(accountEstimation.EmployerAccountId); var commitments = _commitmentModelListBuilder.Build(accountEstimation.EmployerAccountId, accountEstimation.Apprenticeships); var actualProjections = await _accountProjectionRepository.Get(accountEstimation.EmployerAccountId); var employerCommitmentsModel = new EmployerCommitmentsModel { SendingEmployerTransferCommitments = commitments .Where(m => m.FundingSource == Models.Payments.FundingSource.Transfer || m.FundingSource == 0) .ToList(), LevyFundedCommitments = commitments .Where(m => m.FundingSource == Models.Payments.FundingSource.Levy) .ToList() }; var levyFundsIn = actualProjections?.FirstOrDefault()?.LevyFundsIn ?? 0; var employerCommitments = new EmployerCommitments(accountEstimation.EmployerAccountId, employerCommitmentsModel); var accountEstimationProjectionCommitments = new AccountEstimationProjectionCommitments(employerCommitments, actualProjections); return(new AccountEstimationProjection(new Account(accountEstimation.EmployerAccountId, balance.Amount, levyFundsIn, balance.TransferAllowance, balance.RemainingTransferBalance), accountEstimationProjectionCommitments, _dateTimeService, showExpiredFunds)); }
public void Then_When_You_Are_A_Sending_Employer_Your_Balance_First_Month_Does_not_Include_Transfer_Out_Payments_For_First_Month_For_Levy_Run() { //Arrange _account = new Account(1, 2000, 100, 0, 0); Moqer.SetInstance(_account); _commitments.LevyFundedCommitments = new List <CommitmentModel>(); _commitments.ReceivingEmployerTransferCommitments = new List <CommitmentModel>(); _commitments.SendingEmployerTransferCommitments = new List <CommitmentModel> { new CommitmentModel { EmployerAccountId = 1, SendingEmployerAccountId = 999, ApprenticeshipId = 23, LearnerId = 33, StartDate = DateTime.Today.AddMonths(-1), PlannedEndDate = DateTime.Today.GetStartOfMonth().AddMonths(5), MonthlyInstallment = 100, NumberOfInstallments = 6, CompletionAmount = 400, FundingSource = Models.Payments.FundingSource.Transfer } }; var employerCommitments = new EmployerCommitments(1, _commitments); Moqer.SetInstance(employerCommitments); var accountProjection = Moqer.Resolve <Projections.AccountProjection>(); accountProjection.BuildLevyTriggeredProjections(DateTime.Today, 12); //Assert Assert.AreEqual(2000m, accountProjection.Projections[0].FutureFunds); }
public void SetUp() { Moqer = new AutoMoqer(); _account = new Account(1, 12000, 300, 0, 0); Moqer.SetInstance(_account); _commitment = new CommitmentModel { EmployerAccountId = 1, ApprenticeshipId = 2, LearnerId = 3, StartDate = DateTime.Today.AddMonths(-1), PlannedEndDate = DateTime.Today.AddMonths(25), MonthlyInstallment = 2100, NumberOfInstallments = 24, CompletionAmount = 3000, FundingSource = Models.Payments.FundingSource.Levy }; _commitments = new EmployerCommitmentsModel { LevyFundedCommitments = new List <CommitmentModel> { _commitment } }; var employerCommitments = new EmployerCommitments(1, _commitments); Moqer.SetInstance(employerCommitments); }
public void Then_If_I_Am_A_Receiving_Employer_My_Balance_Is_Equal_To_My_Current_Balance_For_All_Months_For_A_Levy_Run() { //Arrange _account = new Account(1, 2000, 0, 0, 0); Moqer.SetInstance(_account); _commitments.LevyFundedCommitments = new List <CommitmentModel>(); _commitments.SendingEmployerTransferCommitments = new List <CommitmentModel>(); _commitments.ReceivingEmployerTransferCommitments = new List <CommitmentModel> { new CommitmentModel { EmployerAccountId = 1, SendingEmployerAccountId = 999, ApprenticeshipId = 23, LearnerId = 33, StartDate = DateTime.Today.AddMonths(-2), PlannedEndDate = DateTime.Today.GetStartOfMonth().AddMonths(6), MonthlyInstallment = 2000, NumberOfInstallments = 6, CompletionAmount = 1200, FundingSource = Models.Payments.FundingSource.Transfer } }; var employerCommitments = new EmployerCommitments(1, _commitments); Moqer.SetInstance(employerCommitments); var accountProjection = Moqer.Resolve <Projections.AccountProjection>(); accountProjection.BuildLevyTriggeredProjections(DateTime.Today, 12); //Assert Assert.IsTrue(accountProjection.Projections.All(c => c.FutureFunds.Equals(2000m))); }
public CurrentBalance( Models.Balance.BalanceModel balance, IAccountBalanceService accountBalanceService, EmployerCommitments employerCommitments) { Model = balance ?? throw new ArgumentNullException(nameof(balance)); _accountBalanceService = accountBalanceService ?? throw new ArgumentNullException(nameof(accountBalanceService)); EmployerCommitments = employerCommitments ?? throw new ArgumentNullException(nameof(employerCommitments)); }
public void Then_Transfer_Funds_In_Are_Reflected_In_My_Balance() { //Arrange _accountProjection = new List <AccountProjectionModel> { new AccountProjectionModel { EmployerAccountId = 54321, Month = 1, Year = DateTime.Now.Year, LevyFundsIn = 100, TransferOutCostOfTraining = 10, TransferInCostOfTraining = 10, TransferOutCompletionPayments = 0, LevyFundedCompletionPayments = 50, LevyFundedCostOfTraining = 50, FutureFunds = 500, FutureFundsNoExpiry = 550, }, new AccountProjectionModel { EmployerAccountId = 54321, Month = 2, Year = DateTime.Now.Year, LevyFundsIn = 100, TransferOutCostOfTraining = 10, TransferInCostOfTraining = 10, TransferOutCompletionPayments = 0, LevyFundedCompletionPayments = 0, LevyFundedCostOfTraining = 50, FutureFunds = 540, FutureFundsNoExpiry = 590 } }; _moqer.GetMock <IApplicationConfiguration>().Setup( x => x.FeatureExpiredFunds).Returns(true); _moqer.GetMock <IDateTimeService>() .Setup(x => x.GetCurrentDateTime()).Returns(new DateTime(DateTime.Now.Year, 1, 1)); var employerCommitments = new EmployerCommitments(EmployerAccountId, _commitments); var accountEstimationProjectionCommitments = new AccountEstimationProjectionCommitments(employerCommitments, _accountProjection.AsReadOnly()); _moqer.SetInstance(accountEstimationProjectionCommitments); _estimationProjection = new AccountEstimationProjection(_moqer.Resolve <Account>(), _moqer.Resolve <AccountEstimationProjectionCommitments>(), _moqer.Resolve <IDateTimeService>(), false); //Act _estimationProjection.BuildProjections(); //Assert var actual = _estimationProjection.Projections.OrderBy(c => c.Year).ThenBy(c => c.Month).Skip(1).FirstOrDefault(); Assert.IsNotNull(actual); Assert.AreEqual(400, actual.EstimatedProjectionBalance); }
public AccountEstimationProjection(Account account, AccountEstimationProjectionCommitments accountEstimationProjectionCommitments, IDateTimeService dateTimeService, bool showExpiredFunds) { _dateTimeService = dateTimeService; _showExpiredFunds = showExpiredFunds; _account = account ?? throw new ArgumentNullException(nameof(account)); if (accountEstimationProjectionCommitments == null) { throw new ArgumentNullException(nameof(accountEstimationProjectionCommitments)); } _virtualEmployerCommitments = accountEstimationProjectionCommitments.VirtualEmployerCommitments ?? throw new ArgumentNullException(nameof(accountEstimationProjectionCommitments.VirtualEmployerCommitments)); _actualAccountProjections = accountEstimationProjectionCommitments.ActualAccountProjections.ToList().AsReadOnly() ?? throw new ArgumentNullException(nameof(accountEstimationProjectionCommitments.ActualAccountProjections)); _estimatedProjections = new List <AccountEstimationProjectionModel>(); }
public void SetUp() { _moqer = new AutoMoqer(); var currentBalanceRepo = _moqer.GetMock <ICurrentBalanceRepository>(); var mockBalance = _moqer.GetMock <CurrentBalance>(); var balance = new BalanceModel { EmployerAccountId = 12345, BalancePeriod = DateTime.Today, Amount = 10000, TransferAllowance = 1000, RemainingTransferBalance = 1000 }; var commitments = new EmployerCommitments(12345, new EmployerCommitmentsModel { LevyFundedCommitments = new List <CommitmentModel> { new CommitmentModel { EmployerAccountId = 12345, PlannedEndDate = DateTime.Today.AddMonths(-2), StartDate = DateTime.Today.AddMonths(-3), NumberOfInstallments = 1, CompletionAmount = 1000, MonthlyInstallment = 80, FundingSource = FundingSource.Levy } } }); mockBalance.Setup(x => x.EmployerAccountId).Returns(12345); mockBalance.Setup(x => x.Amount).Returns(10000); mockBalance.Setup(x => x.RefreshBalance(It.IsAny <bool>(), false)) .ReturnsAsync(true); currentBalanceRepo.Setup(x => x.Get(It.IsAny <long>())) .ReturnsAsync(new CurrentBalance(balance, _moqer.GetMock <IAccountBalanceService>().Object, commitments)); var levyDataSession = _moqer.GetMock <ILevyDataSession>(); levyDataSession.Setup(s => s.GetLatestLevyAmount(12345)).ReturnsAsync(0); levyDataSession.Setup(s => s.GetLatestLevyAmount(12345)).ReturnsAsync(-400); }
public void Then_The_Estimation_Only_Includes_Modelled_Transfer_Estimates_And_Not_Projection_Estimates() { //Arrange var commitments = new EmployerCommitmentsModel { SendingEmployerTransferCommitments = { new CommitmentModel { CompletionAmount = 100, EmployerAccountId = EmployerAccountId, MonthlyInstallment = 50, PlannedEndDate = new DateTime(DateTime.Now.Year, 5, 1), StartDate = new DateTime(DateTime.Now.Year, 1, 1), NumberOfInstallments = 5, FundingSource = Models.Payments.FundingSource.Levy } } }; var employerCommitments = new EmployerCommitments(EmployerAccountId, commitments); var accountEstimationProjectionCommitments = new AccountEstimationProjectionCommitments(employerCommitments, _accountProjection.AsReadOnly()); _moqer.SetInstance(accountEstimationProjectionCommitments); _estimationProjection = new AccountEstimationProjection(_moqer.Resolve <Account>(), _moqer.Resolve <AccountEstimationProjectionCommitments>(), _moqer.Resolve <IDateTimeService>(), false); //Act _estimationProjection.BuildProjections(); //Assert var actual = _estimationProjection.Projections.OrderBy(c => c.Year).ThenBy(c => c.Month).FirstOrDefault(); Assert.IsNotNull(actual); Assert.AreEqual(9990, actual.AvailableTransferFundsBalance); }
public void ShouldDetermineBalanceForCoInvestmentAfterTransferCosts(decimal lastBalance, decimal completionPaymentsTransferOut, decimal trainingCostTransferOut, bool isSendingEmployer, decimal expected) { //Arrange if (isSendingEmployer) { _commitments.LevyFundedCommitments = new List <CommitmentModel>(); _commitments.ReceivingEmployerTransferCommitments = new List <CommitmentModel>(); _commitments.SendingEmployerTransferCommitments = new List <CommitmentModel> { new CommitmentModel { EmployerAccountId = 1, SendingEmployerAccountId = 999, ApprenticeshipId = 23, LearnerId = 33, StartDate = DateTime.Today.AddMonths(-2), PlannedEndDate = DateTime.Today.GetStartOfMonth().AddMonths(6), MonthlyInstallment = 2000, NumberOfInstallments = 6, CompletionAmount = 1200, FundingSource = Models.Payments.FundingSource.Transfer } }; var employerCommitments = new EmployerCommitments(1, _commitments); Moqer.SetInstance(employerCommitments); } var accountProjection = Moqer.Resolve <Projections.AccountProjection>(); //Act var balance = accountProjection.GetCurrentBalance(lastBalance, completionPaymentsTransferOut, trainingCostTransferOut, false); //Assert Assert.AreEqual(expected, balance); }
public void Then_When_You_Are_A_Sending_Employer_Your_FutureFunds_Are_Updated() { //Arrange _account = new Account(1, 2000, 0, 0, 0); Moqer.SetInstance(_account); _commitments.LevyFundedCommitments = new List <CommitmentModel>(); _commitments.ReceivingEmployerTransferCommitments = new List <CommitmentModel>(); _commitments.SendingEmployerTransferCommitments = new List <CommitmentModel> { new CommitmentModel { EmployerAccountId = 1, SendingEmployerAccountId = 999, ApprenticeshipId = 23, LearnerId = 33, StartDate = DateTime.Today, PlannedEndDate = DateTime.Today.GetStartOfMonth().AddMonths(6), MonthlyInstallment = 100, NumberOfInstallments = 6, CompletionAmount = 400, FundingSource = Models.Payments.FundingSource.Transfer } }; var employerCommitments = new EmployerCommitments(1, _commitments); Moqer.SetInstance(employerCommitments); var accountProjection = Moqer.Resolve <Projections.AccountProjection>(); accountProjection.BuildPayrollPeriodEndTriggeredProjections(DateTime.Today, 12); //Assert Assert.AreEqual(1000m, accountProjection.Projections[7].FutureFunds); Assert.AreEqual(1000m, accountProjection.Projections.Last().FutureFunds); }
public void SetUp() { _moqer = new AutoMoqer(); _commitments = new EmployerCommitmentsModel { SendingEmployerTransferCommitments = { new CommitmentModel { CompletionAmount = 100, EmployerAccountId = EmployerAccountId, MonthlyInstallment = 50, PlannedEndDate = new DateTime(DateTime.Now.Year, 5, 1), StartDate = new DateTime(DateTime.Now.Year, 1, 1), NumberOfInstallments = 5, FundingSource = Models.Payments.FundingSource.Levy }, new CommitmentModel { CompletionAmount = 100, EmployerAccountId = EmployerAccountId, MonthlyInstallment = 50, PlannedEndDate = new DateTime(DateTime.Now.Year + 1, 9, 1), StartDate = new DateTime(DateTime.Now.Year + 1, 3, 1), NumberOfInstallments = 5, FundingSource = Models.Payments.FundingSource.Levy }, new CommitmentModel { CompletionAmount = 100, EmployerAccountId = EmployerAccountId, MonthlyInstallment = 50, PlannedEndDate = new DateTime(DateTime.Now.Year, 5, 1), StartDate = new DateTime(DateTime.Now.Year, 1, 1), NumberOfInstallments = 5, FundingSource = Models.Payments.FundingSource.Transfer }, } }; var employerCommitments = new EmployerCommitments(EmployerAccountId, _commitments); _accountProjection = new List <AccountProjectionModel> { new AccountProjectionModel { EmployerAccountId = 54321, Month = 1, Year = DateTime.Now.Year, LevyFundsIn = 100, TransferOutCostOfTraining = 10, TransferOutCompletionPayments = 0, LevyFundedCompletionPayments = 50, LevyFundedCostOfTraining = 50, FutureFunds = 500, FutureFundsNoExpiry = 100 }, new AccountProjectionModel { EmployerAccountId = 54321, Month = 2, Year = DateTime.Now.Year, LevyFundsIn = 100, TransferOutCostOfTraining = 10, TransferOutCompletionPayments = 0, LevyFundedCompletionPayments = 0, LevyFundedCostOfTraining = 50, FutureFunds = 540, FutureFundsNoExpiry = 140 }, new AccountProjectionModel { EmployerAccountId = 54321, Month = 3, Year = DateTime.Now.Year, LevyFundsIn = 100, TransferOutCostOfTraining = 10, TransferOutCompletionPayments = 0, LevyFundedCompletionPayments = 0, LevyFundedCostOfTraining = 50, FutureFunds = 580, FutureFundsNoExpiry = 180 }, new AccountProjectionModel { EmployerAccountId = 54321, Month = 4, Year = DateTime.Now.Year, LevyFundsIn = 100, TransferOutCostOfTraining = 10, TransferOutCompletionPayments = 0, LevyFundedCompletionPayments = 0, LevyFundedCostOfTraining = 50, FutureFunds = 620, FutureFundsNoExpiry = 220 }, new AccountProjectionModel { EmployerAccountId = 54321, Month = 5, Year = DateTime.Now.Year, LevyFundsIn = 100, TransferOutCostOfTraining = 10, TransferOutCompletionPayments = 0, LevyFundedCompletionPayments = 0, LevyFundedCostOfTraining = 50, FutureFunds = 660, FutureFundsNoExpiry = 260 }, new AccountProjectionModel { EmployerAccountId = 54321, Month = 6, Year = DateTime.Now.Year, LevyFundsIn = 100, TransferOutCostOfTraining = 0, TransferOutCompletionPayments = 20, LevyFundedCompletionPayments = 0, LevyFundedCostOfTraining = 50, FutureFunds = 690, FutureFundsNoExpiry = 290 } }; var accountEstimationProjectionCommitments = new AccountEstimationProjectionCommitments(employerCommitments, _accountProjection.AsReadOnly()); _moqer.GetMock <IDateTimeService>() .Setup(x => x.GetCurrentDateTime()).Returns(new DateTime(DateTime.Now.Year, 2, 1)); _moqer.SetInstance(accountEstimationProjectionCommitments); _account = new Account(EmployerAccountId, 10000, 0, TransferAllowance, 10000); _moqer.SetInstance(_account); _estimationProjection = new AccountEstimationProjection(_moqer.Resolve <Account>(), _moqer.Resolve <AccountEstimationProjectionCommitments>(), _moqer.Resolve <IDateTimeService>(), false); }
public void Receiving_employer_account_has_transfers_in() { _commitments.LevyFundedCommitments = new List <CommitmentModel> { new CommitmentModel { EmployerAccountId = 1, SendingEmployerAccountId = 1, ApprenticeshipId = 21, LearnerId = 31, StartDate = DateTime.Today, PlannedEndDate = DateTime.Today.GetStartOfMonth().AddMonths(6), MonthlyInstallment = 2000, NumberOfInstallments = 6, CompletionAmount = 1200, FundingSource = Models.Payments.FundingSource.Levy }, new CommitmentModel { EmployerAccountId = 1, SendingEmployerAccountId = 1, ApprenticeshipId = 22, LearnerId = 32, StartDate = DateTime.Today, PlannedEndDate = DateTime.Today.GetStartOfMonth().AddMonths(6), MonthlyInstallment = 2000, NumberOfInstallments = 6, CompletionAmount = 1200, FundingSource = Models.Payments.FundingSource.Levy } }; _commitments.SendingEmployerTransferCommitments = new List <CommitmentModel> { new CommitmentModel { EmployerAccountId = 1, SendingEmployerAccountId = 999, ApprenticeshipId = 23, LearnerId = 33, StartDate = DateTime.Today, PlannedEndDate = DateTime.Today.GetStartOfMonth().AddMonths(6), MonthlyInstallment = 2000, NumberOfInstallments = 6, CompletionAmount = 1200, FundingSource = Models.Payments.FundingSource.Transfer } }; _commitments.ReceivingEmployerTransferCommitments = new List <CommitmentModel> { new CommitmentModel { EmployerAccountId = 999, SendingEmployerAccountId = 1, ApprenticeshipId = 34, LearnerId = 34, StartDate = DateTime.Today, PlannedEndDate = DateTime.Today.GetStartOfMonth().AddMonths(6), MonthlyInstallment = 2000, NumberOfInstallments = 6, CompletionAmount = 1200, FundingSource = Models.Payments.FundingSource.Transfer } }; var employerCommitments = new EmployerCommitments(1, _commitments); Moqer.SetInstance(employerCommitments); var accountProjection = Moqer.Resolve <Projections.AccountProjection>(); accountProjection.BuildLevyTriggeredProjections(DateTime.Today, 12); var projections = accountProjection.Projections.ToArray(); projections[6].LevyFundedCostOfTraining.Should().Be(4000); projections[6].TransferInCostOfTraining.Should().Be(2000); projections[6].TransferOutCostOfTraining.Should().Be(4000); projections[7].LevyFundedCostOfTraining.Should().Be(0); projections[7].LevyFundedCompletionPayments.Should().Be(2400); projections[7].TransferInCompletionPayments.Should().Be(1200); projections[7].TransferOutCompletionPayments.Should().Be(2400); projections[8].LevyFundedCostOfTraining.Should().Be(0); projections[8].LevyFundedCompletionPayments.Should().Be(0); }
public AccountProjection(Account account, EmployerCommitments employerCommitments) { _account = account ?? throw new ArgumentNullException(nameof(account)); _employerCommitments = employerCommitments ?? throw new ArgumentNullException(nameof(employerCommitments)); _projections = new List <AccountProjectionModel>(49); }
public AccountProjection(Account account, EmployerCommitments employerCommitments, IList <AccountProjectionModel> accountProjectionModels) { _account = account ?? throw new ArgumentNullException(nameof(account)); _employerCommitments = employerCommitments ?? throw new ArgumentNullException(nameof(employerCommitments)); _projections = accountProjectionModels != null?accountProjectionModels.ToList() : throw new ArgumentNullException(nameof(accountProjectionModels)); }
public AccountEstimationProjectionCommitments(EmployerCommitments virtualEmployerCommitments, IReadOnlyCollection <AccountProjectionModel> actualAccountProjections) { VirtualEmployerCommitments = virtualEmployerCommitments; ActualAccountProjections = actualAccountProjections; }