public PastPaymentEventSuperficialValidator()
        {
            RuleFor(m => m.EmployerAccountId)
            .NotNull().NotEmpty()
            .GreaterThan(0);
            RuleFor(m => m.ApprenticeshipId).GreaterThan(0);
            RuleFor(m => m.FundingSource)
            .Must(v => v.Equals(FundingSourceConverter.ConvertToApiFundingSource(FundingSource.Levy)) ||
                  v.Equals(FundingSourceConverter.ConvertToApiFundingSource(FundingSource.Transfer)));

            RuleFor(m => m.Ukprn).GreaterThan(0);

            RuleFor(m => m.SendingEmployerAccountId)
            .NotEqual(m => m.EmployerAccountId)
            .When(m => m.FundingSource == FundingSourceConverter.ConvertToApiFundingSource(FundingSource.Transfer))
            .WithMessage(m => $"{nameof(m.SendingEmployerAccountId)} and {nameof(m.EmployerAccountId)} must not be equal if FundingSource is {FundingSource.Transfer}");

            RuleFor(m => m.SendingEmployerAccountId)
            .Equal(m => m.EmployerAccountId)
            .When(m => m.FundingSource == FundingSourceConverter.ConvertToApiFundingSource(FundingSource.Levy))
            .WithMessage(m => $"{nameof(m.SendingEmployerAccountId)} and {nameof(m.EmployerAccountId)} must be equal if FundingSource is {FundingSource.Levy}");

            RuleFor(m => m.SendingEmployerAccountId)
            .NotEqual(m => m.EmployerAccountId)
            .When(m => m.FundingSource == FundingSourceConverter.ConvertToApiFundingSource(FundingSource.Transfer))
            .WithMessage(m => $"{nameof(m.SendingEmployerAccountId)} and {nameof(m.EmployerAccountId)} must not be equal if FundingSource is {FundingSource.Transfer}");
        }
 public void SetUp()
 {
     PaymentCreatedMessage = new PaymentCreatedMessage
     {
         EmployerAccountId        = 1,
         SendingEmployerAccountId = 1,
         Amount           = 100,
         ApprenticeshipId = 1,
         CollectionPeriod = new Application.Payments.Messages.NamedCalendarPeriod
         {
             Id    = Guid.NewGuid().ToString("D"),
             Month = 1,
             Year  = 2018
         },
         EarningDetails = new EarningDetails
         {
             StartDate          = DateTime.Today,
             PlannedEndDate     = DateTime.Today.AddMonths(14),
             CompletionAmount   = 240,
             CompletionStatus   = 1,
             MonthlyInstallment = 87.27m,
             TotalInstallments  = 12,
             EndpointAssessorId = "EA-Id1",
             ActualEndDate      = DateTime.MinValue
         },
         ProviderName   = "test provider",
         ApprenticeName = "test apprentice",
         CourseName     = "test cource",
         CourseLevel    = 1,
         Id             = Guid.NewGuid().ToString("D"),
         Ukprn          = 2,
         FundingSource  = FundingSourceConverter.ConvertToApiFundingSource(FundingSource.Levy)
     };
 }
コード例 #3
0
        private Provider.Events.Api.Types.FundingSource GetFundingSource(TestPayment payment)
        {
            if (payment.FundingSource != FundingSource.Levy)
            {
                return(FundingSourceConverter.ConvertToApiFundingSource(payment.FundingSource));
            }

            return(payment.SendingEmployerAccountId == 0 || payment.SendingEmployerAccountId == EmployerAccountId?FundingSourceConverter.ConvertToApiFundingSource(FundingSource.Levy) : FundingSourceConverter.ConvertToApiFundingSource(FundingSource.Transfer));
        }
コード例 #4
0
        public void Fails_If_Funding_Source_Is_FullyFundedSfa(FundingSource fundingSource)
        {
            var validator = new PastPaymentEventSuperficialValidator();

            PaymentCreatedMessage.FundingSource = FundingSourceConverter.ConvertToApiFundingSource(fundingSource);
            var result = validator.Validate(PaymentCreatedMessage);

            result.IsValid.Should().BeFalse();
        }
コード例 #5
0
        public void Should_have_different_EmployerId_if_transfer()
        {
            var validator = new PastPaymentEventSuperficialValidator();

            PaymentCreatedMessage.SendingEmployerAccountId = PaymentCreatedMessage.EmployerAccountId + 1;
            PaymentCreatedMessage.FundingSource            = FundingSourceConverter.ConvertToApiFundingSource(FundingSource.Transfer);
            var result = validator.Validate(PaymentCreatedMessage);

            result.IsValid.Should().BeTrue();
        }
コード例 #6
0
        public void Fails_If_Ids_are_not_equal_and_FundingSource_Levy()
        {
            var validator = new PastPaymentEventSuperficialValidator();

            PaymentCreatedMessage.SendingEmployerAccountId = PaymentCreatedMessage.EmployerAccountId + 1;
            PaymentCreatedMessage.FundingSource            = FundingSourceConverter.ConvertToApiFundingSource(FundingSource.Levy);
            var result = validator.Validate(PaymentCreatedMessage);

            result.IsValid.Should().BeFalse();
        }
        public void Should_have_same_employerid_if_Levy()
        {
            var validator = new PaymentEventSuperficialValidator();

            PaymentCreatedMessage.SendingEmployerAccountId = PaymentCreatedMessage.EmployerAccountId;
            PaymentCreatedMessage.FundingSource            = FundingSourceConverter.ConvertToApiFundingSource(FundingSource.Levy);
            var result = validator.Validate(PaymentCreatedMessage);

            result.IsValid.Should().BeTrue();
        }
コード例 #8
0
        public PaymentEventSuperficialValidator()
        {
            RuleFor(m => m.EmployerAccountId)
            .NotNull().NotEmpty()
            .GreaterThan(0);
            RuleFor(m => m.ApprenticeshipId).GreaterThan(0);
            RuleFor(m => m.FundingSource)
            .Must(v => v.Equals(FundingSourceConverter.ConvertToApiFundingSource(FundingSource.Levy)) ||
                  v.Equals(FundingSourceConverter.ConvertToApiFundingSource(FundingSource.Transfer)) ||
                  v.Equals(FundingSourceConverter.ConvertToApiFundingSource(FundingSource.CoInvestedSfa)));
            When(payment => (payment.EarningDetails?.ActualEndDate ?? DateTime.MinValue) == DateTime.MinValue, () => {
                RuleFor(m => m.Ukprn).GreaterThan(0);
                RuleFor(m => m.ProviderName).NotNull().NotEmpty();
                RuleFor(m => m.ApprenticeName).NotNull().NotEmpty();

                RuleFor(m => m.CourseName).NotNull().NotEmpty();

                RuleFor(m => m.SendingEmployerAccountId)
                .NotEqual(m => m.EmployerAccountId)
                .When(m => m.FundingSource == FundingSourceConverter.ConvertToApiFundingSource(FundingSource.Transfer))
                .WithMessage(m => $"{nameof(m.SendingEmployerAccountId)} and {nameof(m.EmployerAccountId)} must not be equal if FundingSource is {FundingSource.Transfer}");

                RuleFor(m => m.SendingEmployerAccountId)
                .Equal(m => m.EmployerAccountId)
                .When(m => m.FundingSource == FundingSourceConverter.ConvertToApiFundingSource(FundingSource.Levy))
                .WithMessage(m => $"{nameof(m.SendingEmployerAccountId)} and {nameof(m.EmployerAccountId)} must be equal if FundingSource is {FundingSource.Levy}");

                RuleFor(m => m.SendingEmployerAccountId)
                .NotEqual(m => m.EmployerAccountId)
                .When(m => m.FundingSource == FundingSourceConverter.ConvertToApiFundingSource(FundingSource.Transfer))
                .WithMessage(m => $"{nameof(m.SendingEmployerAccountId)} and {nameof(m.EmployerAccountId)} must not be equal if FundingSource is {FundingSource.Transfer}");

                RuleFor(m => m.EarningDetails)
                .NotNull()
                .SetValidator(new EarningDetailsSuperficialValidator());

                RuleFor(m => m.CollectionPeriod)
                .NotNull()
                .SetValidator(new CollectionPeriodSuperficialValidator());

                RuleFor(m => m.FundingSource).Must(v => v.HasFlag(FundingSourceConverter.ConvertToApiFundingSource(FundingSource.Levy)) ||
                                                   v.HasFlag(FundingSourceConverter.ConvertToApiFundingSource(FundingSource.Transfer)));

                RuleFor(m => m.SendingEmployerAccountId)
                .NotEqual(m => m.EmployerAccountId)
                .When(m => m.FundingSource == FundingSourceConverter.ConvertToApiFundingSource(FundingSource.Transfer))
                .WithMessage(m => $"{nameof(m.SendingEmployerAccountId)} and {nameof(m.SendingEmployerAccountId)} must not be equal if FundingSource is {FundingSource.Transfer}");
            });
        }
コード例 #9
0
 public void Arrange()
 {
     PaymentCreatedMessage = new PaymentCreatedMessage
     {
         EmployerAccountId        = 1,
         SendingEmployerAccountId = 1,
         Amount           = 100,
         ApprenticeshipId = 1,
         CollectionPeriod = new Application.Payments.Messages.NamedCalendarPeriod
         {
             Id    = Guid.NewGuid().ToString("D"),
             Month = 1,
             Year  = 2018
         },
         ProviderName   = "test provider",
         ApprenticeName = "test apprentice",
         CourseName     = "test course",
         CourseLevel    = 1,
         Id             = Guid.NewGuid().ToString("D"),
         Ukprn          = 2,
         FundingSource  = FundingSourceConverter.ConvertToApiFundingSource(FundingSource.Levy)
     };
 }
コード例 #10
0
        public async Task <List <EmployerPayment> > GetPastEmployerPayments(long accountId, int year, int month)
        {
            const string sql = @"SELECT
	                            [PaymentId], 
	                            tl.AccountId,
                                tl.TransactionDate,
	                            acct.[SenderAccountId] ,
	                            tl.Ukprn,
	                            p.[ApprenticeshipId] ,
	                            p.Amount,
	                            [Uln],  
	                            [CollectionPeriodId],
	                            [CollectionPeriodMonth],[CollectionPeriodYear],
	                            [DeliveryPeriodMonth],
	                            [DeliveryPeriodYear]
	                            ,[ProviderName] ,[StandardCode],[FrameworkCode],[ProgrammeType],[PathwayCode],[PathwayName] 
	                            ,[ApprenticeshipCourseName],[ApprenticeshipCourseStartDate],[ApprenticeshipCourseLevel],[ApprenticeName], [FundingSource], acct.[SenderAccountId] 
                            from [employer_financial].[Payment] p 
                            left join [employer_financial].[Accounttransfers] acct on p.AccountId = acct.ReceiverAccountId and p.ApprenticeshipId = acct.ApprenticeshipId and p.PeriodEnd = acct.PeriodEnd 
                            inner join [employer_financial].[PaymentMetaData] pmd on p.PaymentMetaDataId = pmd.Id 
                            inner join [employer_financial].TransactionLine tl on tl.PeriodEnd = p.PeriodEnd and tl.AccountId = p.AccountId and tl.Ukprn = p.Ukprn
                             where p.AccountId = @employerAccountId 
                               and CollectionPeriodYear = @year 
                               and CollectionPeriodMonth = @month";

            try
            {
                return(await WithConnection(async cnn =>
                {
                    var parameters = new DynamicParameters();
                    parameters.Add("@employerAccountId", accountId, DbType.Int64);
                    parameters.Add("@year", year, DbType.Int32);
                    parameters.Add("@month", month, DbType.Int32);

                    var payments = (await cnn.QueryAsync <EmployerPayment>(
                                        sql,
                                        parameters,
                                        commandType: CommandType.Text)).ToList();
                    payments.ForEach(payment => payment.FundingSource = (int)payment.FundingSource == (int)FundingSourceConverter.ConvertToApiFundingSource(FundingSource.Transfer) ? FundingSourceConverter.ConvertToApiFundingSource(FundingSource.Transfer) : payment.FundingSource);
                    return payments;
                }));
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Failed to get past employer payments");
                throw;
            }
        }