Ejemplo n.º 1
0
        public IReadOnlyList <FundingSourcePayment> Process(RequiredPayment requiredPayment)
        {
            var fundingSourcePayments = new List <FundingSourcePayment>();

            if (requiredPayment.IsTransfer)
            {
                fundingSourcePayments.AddRange(transferPaymentProcessor.Process(requiredPayment));
                var remainingTransferAmount = requiredPayment.AmountDue - fundingSourcePayments.Sum(transfer => transfer.AmountDue);
                if (remainingTransferAmount > 0)
                {
                    fundingSourcePayments.Add(new UnableToFundTransferPayment
                    {
                        AmountDue = remainingTransferAmount,
                        Type      = FundingSourceType.Transfer
                    });
                }
                return(fundingSourcePayments);
            }

            fundingSourcePayments.AddRange(levyPaymentProcessor.Process(requiredPayment));

            var amountDue = requiredPayment.AmountDue - fundingSourcePayments.Select(p => p.AmountDue).Sum();

            if (amountDue != 0m)
            {
                var partFundedRequiredPayment = new RequiredPayment
                {
                    AmountDue = amountDue,
                    SfaContributionPercentage = requiredPayment.SfaContributionPercentage
                };

                fundingSourcePayments.AddRange(coInvestedPaymentProcessor.Process(partFundedRequiredPayment));
            }

            return(fundingSourcePayments);
        }
        public void TestProcessPaymentWithEnoughLevyBalance()
        {
            // arrange
            var requiredPayment = new RequiredPayment
            {
                SfaContributionPercentage = .9m,
                AmountDue = 100
            };

            levyBalanceServiceMock.Setup(s => s.TryFund(100)).Returns(100).Verifiable();

            // act
            var payments = processor.Process(requiredPayment);

            // assert
            payments.Should().HaveCount(1);
            payments[0].AmountDue.Should().Be(100);
            payments[0].Type.Should().Be(FundingSourceType.Levy);
        }