public void ShouldMapToValidRequiredCoInvestedPayment()
        {
            var expectedRequiredCoInvestedPayment = new RequiredCoInvestedPayment
            {
                AmountDue = requiredCoInvestedAmount.AmountDue,
                SfaContributionPercentage = requiredCoInvestedAmount.SfaContributionPercentage
            };

            var actual = coInvestedFundingMapper.MapToRequiredCoInvestedPayment(requiredCoInvestedAmount);

            actual.Should().BeEquivalentTo(expectedRequiredCoInvestedPayment);
        }
        public void ShouldGenerateValidationResultForInvalidEvent()
        {
            var message = new RequiredCoInvestedPayment
            {
                SfaContributionPercentage = 0
            };

            var validator = new ValidateRequiredPaymentEvent();
            var results   = validator.Validate(message);

            Assert.IsNotNull(results);
            Assert.AreEqual((int)RequiredPaymentEventValidationRules.ZeroSfaContributionPercentage, (int)results.First().Rule);
        }
        public void GivenValidSfaContributionAndAmountDueShouldReturnValidPayment(decimal sfaContribution,
                                                                                  decimal amountDue,
                                                                                  decimal expectedAmount)
        {
            var message = new RequiredCoInvestedPayment
            {
                SfaContributionPercentage = sfaContribution,
                AmountDue = amountDue
            };

            validator = new Mock <IValidateRequiredPaymentEvent>();
            validator.Setup(o => o.Validate(message)).Returns(new List <RequiredCoInvestedPaymentValidationResult>());
            processor = new SfaCoInvestedPaymentProcessor(validator.Object);

            var payment = processor.Process(message);

            Assert.AreEqual(expectedAmount, payment.AmountDue);
        }
        public void GetFundedPaymentsShouldCallAllPaymentProcessors()
        {
            // Arrange
            var message = new CalculatedRequiredCoInvestedAmount();
            var requiredCoInvestedPayment = new RequiredCoInvestedPayment();
            var fundingSourcePayment      = new EmployerCoInvestedPayment();

            var sfaPaymentProcessor      = new Mock <ICoInvestedPaymentProcessorOld>(MockBehavior.Strict);
            var employerPaymentProcessor = new Mock <ICoInvestedPaymentProcessorOld>(MockBehavior.Strict);

            var sfaPaymentEvent = new SfaCoInvestedFundingSourcePaymentEvent();

            var mapper = new Mock <ICoInvestedFundingSourcePaymentEventMapper>(MockBehavior.Strict);

            mapper.Setup(o => o.MapToRequiredCoInvestedPayment(message)).Returns(requiredCoInvestedPayment);
            mapper.Setup(o => o.MapToCoInvestedPaymentEvent(message, fundingSourcePayment)).Returns(sfaPaymentEvent);

            sfaPaymentProcessor
            .Setup(o => o.Process(requiredCoInvestedPayment)).Returns(fundingSourcePayment)
            .Verifiable();

            employerPaymentProcessor
            .Setup(o => o.Process(requiredCoInvestedPayment)).Returns(fundingSourcePayment)
            .Verifiable();

            var paymentProcessors = new List <ICoInvestedPaymentProcessorOld>
            {
                sfaPaymentProcessor.Object,
                employerPaymentProcessor.Object
            };

            // Act
            var handler = new CoInvestedFundingSourceService(paymentProcessors, mapper.Object);

            handler.GetFundedPayments(message);

            //Assert
            sfaPaymentProcessor.Verify();
            employerPaymentProcessor.Verify();
        }
        public void ShouldThrowExceptionIfValidationResultIsNotNull()
        {
            var message = new RequiredCoInvestedPayment
            {
                SfaContributionPercentage = 0
            };

            var validationResults = new List <RequiredCoInvestedPaymentValidationResult>
            {
                new RequiredCoInvestedPaymentValidationResult
                {
                    RequiredCoInvestedPayment = message,
                    Rule = RequiredPaymentEventValidationRules.ZeroSfaContributionPercentage
                }
            };

            validator = new Mock <IValidateRequiredPaymentEvent>();
            validator.Setup(o => o.Validate(message)).Returns(validationResults);

            processor = new SfaCoInvestedPaymentProcessor(validator.Object);

            Assert.That(() => processor.Process(message), Throws.InstanceOf <FundingSourceRequiredPaymentValidationException>());
        }