public void Setup()
 {
     requiredCoInvestedAmount = new CalculatedRequiredCoInvestedAmount
     {
         AmountDue        = 1000.00m,
         CollectionPeriod = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 1),
         DeliveryPeriod   = 1,
         EventTime        = DateTime.UtcNow,
         JobId            = 1,
         Learner          = new Learner
         {
             ReferenceNumber = "001",
             Uln             = 1234567890
         },
         OnProgrammeEarningType = OnProgrammeEarningType.Learning,
         LearningAim            = new LearningAim
         {
             FrameworkCode = 403
         },
         PriceEpisodeIdentifier    = "1819-P01",
         SfaContributionPercentage = 0.9m,
         Ukprn        = 10000,
         AccountId    = 1000000,
         ContractType = ContractType.Act2,
         ApprenticeshipEmployerType = ApprenticeshipEmployerType.Levy,
     };
     mapperConfiguration     = AutoMapperConfigurationFactory.CreateMappingConfig();
     autoMapper              = mapperConfiguration.CreateMapper();
     coInvestedFundingMapper = new CoInvestedFundingSourcePaymentEventMapper(autoMapper);
 }
Beispiel #2
0
        public PeriodisedRequiredPaymentEvent Create(EarningType earningType, int transactionType)
        {
            PeriodisedRequiredPaymentEvent paymentEvent = null;

            switch (earningType)
            {
            case EarningType.CoInvested:
                if (IsValidPaymentType <OnProgrammeEarningType>(transactionType))
                {
                    paymentEvent = new CalculatedRequiredCoInvestedAmount
                    {
                        OnProgrammeEarningType = (OnProgrammeEarningType)transactionType,
                    };
                }

                break;

            case EarningType.Incentive:
                if (IsValidPaymentType <IncentivePaymentType>(transactionType))
                {
                    paymentEvent = new CalculatedRequiredIncentiveAmount
                    {
                        Type = (IncentivePaymentType)transactionType,
                    };
                }

                break;

            case EarningType.Levy:
                if (IsValidPaymentType <OnProgrammeEarningType>(transactionType))
                {
                    paymentEvent = new CalculatedRequiredLevyAmount
                    {
                        OnProgrammeEarningType = (OnProgrammeEarningType)transactionType,
                    };
                }

                break;

            default:
                throw new InvalidOperationException(
                          $"Unknown earning type found: {earningType:G}. Cannot create the PeriodisedRequiredPaymentEvent.");
            }

            if (paymentEvent == null)
            {
                logger.LogError(
                    $"Invalid EarningType and TransactionType combination: EarningType: {earningType:G}, TransactionType: {transactionType}");
            }

            return(paymentEvent);
        }
        public CoInvestedFundingSourcePaymentEvent MapToCoInvestedPaymentEvent(CalculatedRequiredCoInvestedAmount requiredPaymentsEvent, FundingSourcePayment payment)
        {
            switch (payment.Type)
            {
            case FundingSourceType.CoInvestedSfa:
                return(MapCommonCoInvestedPaymentEventData(payment, mapper.Map <SfaCoInvestedFundingSourcePaymentEvent>(requiredPaymentsEvent)));

            case FundingSourceType.CoInvestedEmployer:
                return(MapCommonCoInvestedPaymentEventData(payment, mapper.Map <EmployerCoInvestedFundingSourcePaymentEvent>(requiredPaymentsEvent)));

            default:
                throw new NotImplementedException(nameof(FundingSourceType));
            }
        }
Beispiel #4
0
        public IEnumerable <CoInvestedFundingSourcePaymentEvent> GetFundedPayments(CalculatedRequiredCoInvestedAmount message)
        {
            var coInvestedPaymentMessage = mapper.MapToRequiredCoInvestedPayment(message);

            var paymentEvents = new List <CoInvestedFundingSourcePaymentEvent>();

            foreach (var processor in processors)
            {
                var payment = processor.Process(coInvestedPaymentMessage);
                if (payment != null && payment.AmountDue != 0)
                {
                    paymentEvents.Add(mapper.MapToCoInvestedPaymentEvent(message, payment));
                }
            }

            return(paymentEvents);
        }
        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 RequiredCoInvestedPayment MapToRequiredCoInvestedPayment(CalculatedRequiredCoInvestedAmount requiredPaymentsEvent)
 {
     return(mapper.Map <RequiredCoInvestedPayment>(requiredPaymentsEvent));
 }