Exemplo n.º 1
0
        public void GroupingByPaymentType()
        {
            var payments = new List <Payment>
            {
                new Payment {
                    LearnerReferenceNumber = "ABC", TransactionType = 4, LearningStartDate = new DateTime(2020, 01, 01), LearningAimProgrammeType = 1, LearningAimStandardCode = 2, LearningAimFrameworkCode = 3, LearningAimPathwayCode = 10
                },
                new Payment {
                    LearnerReferenceNumber = "ABC", TransactionType = 5, LearningStartDate = new DateTime(2020, 01, 01), LearningAimProgrammeType = 1, LearningAimStandardCode = 2, LearningAimFrameworkCode = 3, LearningAimPathwayCode = 11
                },
                new Payment {
                    LearnerReferenceNumber = "ABC", TransactionType = 6, LearningStartDate = new DateTime(2020, 01, 01), LearningAimProgrammeType = 1, LearningAimStandardCode = 2, LearningAimFrameworkCode = 3, LearningAimPathwayCode = 12
                },
                new Payment {
                    LearnerReferenceNumber = "ABC", TransactionType = 7, LearningStartDate = new DateTime(2020, 01, 01), LearningAimProgrammeType = 1, LearningAimStandardCode = 2, LearningAimFrameworkCode = 3, LearningAimPathwayCode = 13
                },
                new Payment {
                    LearnerReferenceNumber = "ABC", TransactionType = 16, LearningStartDate = new DateTime(2020, 01, 01), LearningAimProgrammeType = 1, LearningAimStandardCode = 2, LearningAimFrameworkCode = 3, LearningAimPathwayCode = 14
                },
            };

            var learners = new List <Learner>
            {
                new Learner {
                    LearnRefNumber = "ABC"
                }
            };


            var LearningDeliveries = new List <AecLearningDelivery>
            {
                new AecLearningDelivery {
                    LearnRefNumber = "ABC", LearnStartDate = new DateTime(2020, 01, 01), ProgType = 1, StdCode = 2, FworkCode = 3, PwayCode = 10, AimSequenceNumber = 1
                },
                new AecLearningDelivery {
                    LearnRefNumber = "ABC", LearnStartDate = new DateTime(2020, 01, 01), ProgType = 1, StdCode = 2, FworkCode = 3, PwayCode = 11, AimSequenceNumber = 2
                },
                new AecLearningDelivery {
                    LearnRefNumber = "ABC", LearnStartDate = new DateTime(2020, 01, 01), ProgType = 1, StdCode = 2, FworkCode = 3, PwayCode = 12, AimSequenceNumber = 3
                },
                new AecLearningDelivery {
                    LearnRefNumber = "ABC", LearnStartDate = new DateTime(2020, 01, 01), ProgType = 1, StdCode = 2, FworkCode = 3, PwayCode = 13, AimSequenceNumber = 4
                },
                new AecLearningDelivery {
                    LearnRefNumber = "ABC", LearnStartDate = new DateTime(2020, 01, 01), ProgType = 1, StdCode = 2, FworkCode = 3, PwayCode = 14, AimSequenceNumber = 5
                }
            };

            var periodisedValues = new List <ApprenticeshipPriceEpisodePeriodisedValues>();


            var paymentLineFormatter               = new PaymentLineFormatter() as IPaymentLineFormatter;
            var earningsAndPaymentsBuilder         = new EarningsAndPaymentsBuilder() as IEarningsAndPaymentsBuilder;
            var appsAdditionalPaymentsModelBuilder = new AppsAdditionalPaymentsModelBuilder(paymentLineFormatter, earningsAndPaymentsBuilder);

            var results = appsAdditionalPaymentsModelBuilder.Build(payments, learners, LearningDeliveries, periodisedValues);

            results.Count().Should().Be(3);
        }
Exemplo n.º 2
0
        public async Task TestAppsAdditionalPaymentsReportGeneration()
        {
            string   csv      = string.Empty;
            DateTime dateTime = DateTime.UtcNow;
            string   filename = $"10036143_1_Apps Additional Payments Report {dateTime:yyyyMMdd-HHmmss}";
            int      ukPrn    = 10036143;
            Mock <IReportServiceContext> reportServiceContextMock = new Mock <IReportServiceContext>();

            reportServiceContextMock.SetupGet(x => x.JobId).Returns(1);
            reportServiceContextMock.SetupGet(x => x.SubmissionDateTimeUtc).Returns(DateTime.UtcNow);
            reportServiceContextMock.SetupGet(x => x.Ukprn).Returns(ukPrn);

            Mock <ILogger>           logger = new Mock <ILogger>();
            Mock <IDateTimeProvider> dateTimeProviderMock              = new Mock <IDateTimeProvider>();
            Mock <IStreamableKeyValuePersistenceService> storage       = new Mock <IStreamableKeyValuePersistenceService>();
            Mock <IIlrProviderService>         ilrProviderServiceMock  = new Mock <IIlrProviderService>();
            Mock <IDASPaymentsProviderService> dasPaymentProviderMock  = new Mock <IDASPaymentsProviderService>();
            Mock <IFM36ProviderService>        fm36ProviderServiceMock = new Mock <IFM36ProviderService>();
            IValueProvider valueProvider = new ValueProvider();
            ITopicAndTaskSectionOptions topicsAndTasks = TestConfigurationHelper.GetTopicsAndTasks();

            storage.Setup(x => x.SaveAsync($"{filename}.csv", It.IsAny <string>(), It.IsAny <CancellationToken>())).Callback <string, string, CancellationToken>((key, value, ct) => csv = value).Returns(Task.CompletedTask);

            var appsAdditionalPaymentIlrInfo         = BuildILRModel(ukPrn);
            var appsAdditionalPaymentRulebaseInfo    = BuildFm36Model(ukPrn);
            var appsAdditionalPaymentDasPaymentsInfo = BuildDasPaymentsModel(ukPrn);

            ilrProviderServiceMock.Setup(x => x.GetILRInfoForAppsAdditionalPaymentsReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync(appsAdditionalPaymentIlrInfo);
            fm36ProviderServiceMock.Setup(x => x.GetFM36DataForAppsAdditionalPaymentReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync(appsAdditionalPaymentRulebaseInfo);
            dasPaymentProviderMock.Setup(x => x.GetPaymentsInfoForAppsAdditionalPaymentsReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync(appsAdditionalPaymentDasPaymentsInfo);

            dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(dateTime);
            dateTimeProviderMock.Setup(x => x.ConvertUtcToUk(It.IsAny <DateTime>())).Returns(dateTime);
            var appsAdditionalPaymentsModelBuilder = new AppsAdditionalPaymentsModelBuilder();

            var report = new ReportService.Service.Reports.PeriodEnd.AppsAdditionalPaymentsReport(logger.Object, storage.Object, ilrProviderServiceMock.Object, fm36ProviderServiceMock.Object, dateTimeProviderMock.Object, valueProvider, topicsAndTasks, dasPaymentProviderMock.Object, appsAdditionalPaymentsModelBuilder);

            await report.GenerateReport(reportServiceContextMock.Object, null, false, CancellationToken.None);

            csv.Should().NotBeNullOrEmpty();
            File.WriteAllText($"{filename}.csv", csv);
            TestCsvHelper.CheckCsv(csv, new CsvEntry(new AppsAdditionalPaymentsMapper(), 1));
        }
        public async Task TestAppsAdditionalPaymentsReportGeneration(
            string employerName,
            string employerNameExpected,
            string ilrLearnRefNumber,
            string ilrLearnAimRef,
            string dasLearnRefNumber,
            string dasLearnAimRef,
            string provSpecLearnMonOccurA,
            string provSpecLearnMonOccurB)
        {
            string   csv      = string.Empty;
            DateTime dateTime = DateTime.UtcNow;
            string   filename = $"R01_10036143_10036143 Apps Additional Payments Report {dateTime:yyyyMMdd-HHmmss}";
            int      ukPrn    = 10036143;
            Mock <IReportServiceContext> reportServiceContextMock = new Mock <IReportServiceContext>();

            reportServiceContextMock.SetupGet(x => x.JobId).Returns(1);
            reportServiceContextMock.SetupGet(x => x.SubmissionDateTimeUtc).Returns(DateTime.UtcNow);
            reportServiceContextMock.SetupGet(x => x.Ukprn).Returns(ukPrn);
            reportServiceContextMock.SetupGet(x => x.ReturnPeriod).Returns(1);
            reportServiceContextMock.SetupGet(x => x.ReturnPeriodName).Returns("R01");

            Mock <ILogger>           logger = new Mock <ILogger>();
            Mock <IDateTimeProvider> dateTimeProviderMock        = new Mock <IDateTimeProvider>();
            Mock <IStreamableKeyValuePersistenceService> storage = new Mock <IStreamableKeyValuePersistenceService>();
            Mock <IIlrPeriodEndProviderService>          ilrPeriodEndProviderServiceMock = new Mock <IIlrPeriodEndProviderService>();
            Mock <IDASPaymentsProviderService>           dasPaymentProviderMock          = new Mock <IDASPaymentsProviderService>();
            Mock <IFM36PeriodEndProviderService>         fm36ProviderServiceMock         = new Mock <IFM36PeriodEndProviderService>();

            storage.Setup(x => x.SaveAsync($"{filename}.csv", It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Callback <string, string, CancellationToken>((key, value, ct) => csv = value)
            .Returns(Task.CompletedTask);

            var appsAdditionalPaymentIlrInfo         = BuildILRModel(ukPrn, ilrLearnRefNumber, ilrLearnAimRef, provSpecLearnMonOccurA, provSpecLearnMonOccurB);
            var rulebaseLearningDeliveries           = BuildRulebaseLearningDeliveries();
            var rulebasePriceEpisodes                = BuildRulebasePriceEpisodes(ukPrn);
            var appsAdditionalPaymentDasPaymentsInfo = BuildDasPaymentsModel(ukPrn, employerName, dasLearnRefNumber, dasLearnAimRef);
            var legalEntityNameDictionary            = BuildLegalEntityNameDictionary(employerName);

            ilrPeriodEndProviderServiceMock.Setup(x => x.GetILRInfoForAppsAdditionalPaymentsReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(appsAdditionalPaymentIlrInfo);
            fm36ProviderServiceMock.Setup(x => x.GetLearningDeliveriesForAppsAdditionalPaymentReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(rulebaseLearningDeliveries);
            fm36ProviderServiceMock.Setup(x => x.GetApprenticeshipPriceEpisodesForAppsAdditionalPaymentsReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(rulebasePriceEpisodes);
            dasPaymentProviderMock.Setup(x => x.GetPaymentsInfoForAppsAdditionalPaymentsReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(appsAdditionalPaymentDasPaymentsInfo);
            dasPaymentProviderMock
            .Setup(x => x.GetLegalEntityNameApprenticeshipIdDictionaryAsync(It.IsAny <IEnumerable <long?> >(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(legalEntityNameDictionary);

            dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(dateTime);
            dateTimeProviderMock.Setup(x => x.ConvertUtcToUk(It.IsAny <DateTime>())).Returns(dateTime);
            var appsAdditionalPaymentsModelBuilder          = new AppsAdditionalPaymentsModelBuilder();
            Mock <IPersistReportData> persistReportDataMock = new Mock <IPersistReportData>();

            var report = new AppsAdditionalPaymentsReport(
                logger.Object,
                storage.Object,
                ilrPeriodEndProviderServiceMock.Object,
                fm36ProviderServiceMock.Object,
                dateTimeProviderMock.Object,
                dasPaymentProviderMock.Object,
                appsAdditionalPaymentsModelBuilder,
                persistReportDataMock.Object);

            await report.GenerateReport(reportServiceContextMock.Object, null, CancellationToken.None);

            csv.Should().NotBeNullOrEmpty();
            TestCsvHelper.CheckCsv(csv, new CsvEntry(new AppsAdditionalPaymentsMapper(), 1));
            IEnumerable <AppsAdditionalPaymentsModel> result;

            using (var csvReader = new CsvReader(new StringReader(csv)))
            {
                csvReader.Configuration.TypeConverterOptionsCache.GetOptions <DateTime>().Formats  = new[] { "dd/MM/yyyy" };
                csvReader.Configuration.TypeConverterOptionsCache.GetOptions <DateTime?>().Formats = new[] { "dd/MM/yyyy" };

                csvReader.Configuration.RegisterClassMap <AppsAdditionalPaymentsMapper>();
                result = csvReader.GetRecords <AppsAdditionalPaymentsModel>().ToList();
            }

            result.Should().NotBeNullOrEmpty();
            result.Count().Should().Be(1);
            result.First().AugustEarnings.Should().Be(10);
            result.First().JulyEarnings.Should().Be(120);
            result.First().TotalEarnings.Should().Be(780);
            result.First().TotalPaymentsYearToDate.Should().Be(20);
            result.First().UniqueLearnerNumber.Should().Be(12345);
            result.First().EmployerNameFromApprenticeshipService.Should().Be(employerNameExpected);
        }
        public async void TestAgainstRealDb()
        {
            var ilrConnectionString =
                "<ReplaceWithConnectionString>";
            var dasConnectionString =
                "<ReplaceWithConnectionString>";

            var collectionYear = 1920;
            var ukprn          = 10000055;

            SqlConnection ilrSqlFunc() => new SqlConnection(ilrConnectionString);
            SqlConnection dasSqlFunc() => new SqlConnection(dasConnectionString);

            var paymentsDataProvider            = new PaymentsDataProvider(dasSqlFunc) as IPaymentsDataProvider;
            var learnerDataProvider             = new LearnerDataProvider(ilrSqlFunc) as ILearnerDataProvider;
            var aecLearningDeliveryDataProvider = new AecLearningDeliveryDataProvider(ilrSqlFunc) as IAecLearningDeliveryDataProvider;
            var appsPriceEpisodePeriodisedValuesDataProvider = new AppsPriceEpisodePeriodisedValuesDataProvider(ilrSqlFunc) as IAppsPriceEpisodePeriodisedValuesDataProvider;

            var dataProvider = new AppsAdditionalPaymentsDataProvider(
                paymentsDataProvider,
                learnerDataProvider,
                aecLearningDeliveryDataProvider,
                appsPriceEpisodePeriodisedValuesDataProvider) as IAppsAdditionalPaymentsDataProvider;

            var cancellationToken    = new CancellationToken();
            var reportServiceContext = new Mock <IReportServiceContext>();

            reportServiceContext.Setup(rsc => rsc.CollectionYear).Returns(collectionYear);
            reportServiceContext.Setup(rsc => rsc.Ukprn).Returns(ukprn);

            var payments = await dataProvider.GetPaymentsAsync(reportServiceContext.Object, cancellationToken);

            payments.Should().NotBeNull();
            payments.Should().NotBeEmpty();

            var learners = await dataProvider.GetLearnersAsync(reportServiceContext.Object, cancellationToken);

            learners.Should().NotBeNull();
            learners.Should().NotBeEmpty();

            var aecLearningDeliveries = await dataProvider.GetAecLearningDeliveriesAsync(reportServiceContext.Object,
                                                                                         cancellationToken);

            aecLearningDeliveries.Should().NotBeNull();
            aecLearningDeliveries.Should().NotBeEmpty();

            var appPriceEpisodePeriodisedValues = await dataProvider.GetPriceEpisodesAsync(reportServiceContext.Object, cancellationToken);

            appPriceEpisodePeriodisedValues.Should().NotBeNull();
            appPriceEpisodePeriodisedValues.Should().NotBeEmpty();

            var paymentFundingLineFormatter = new PaymentLineFormatter() as IPaymentLineFormatter;
            var earningsAndPaymentsBuilder  = new EarningsAndPaymentsBuilder() as IEarningsAndPaymentsBuilder;

            var appsAdditionalPaymentsModelBuilder =
                new AppsAdditionalPaymentsModelBuilder(paymentFundingLineFormatter, earningsAndPaymentsBuilder) as IAppsAdditionalPaymentsModelBuilder;

            var results = appsAdditionalPaymentsModelBuilder.Build(payments, learners, aecLearningDeliveries, appPriceEpisodePeriodisedValues);

            results.Should().NotBeNull();
        }
        public async Task TestAppsAdditionalPaymentsReportGeneration()
        {
            string   csv      = string.Empty;
            DateTime dateTime = DateTime.UtcNow;
            string   filename = $"10036143_1_Apps Additional Payments Report {dateTime:yyyyMMdd-HHmmss}";
            int      ukPrn    = 10036143;
            Mock <IReportServiceContext> reportServiceContextMock = new Mock <IReportServiceContext>();

            reportServiceContextMock.SetupGet(x => x.JobId).Returns(1);
            reportServiceContextMock.SetupGet(x => x.SubmissionDateTimeUtc).Returns(DateTime.UtcNow);
            reportServiceContextMock.SetupGet(x => x.Ukprn).Returns(ukPrn);

            Mock <ILogger>           logger = new Mock <ILogger>();
            Mock <IDateTimeProvider> dateTimeProviderMock        = new Mock <IDateTimeProvider>();
            Mock <IStreamableKeyValuePersistenceService> storage = new Mock <IStreamableKeyValuePersistenceService>();
            Mock <IIlrPeriodEndProviderService>          IlrPeriodEndProviderServiceMock = new Mock <IIlrPeriodEndProviderService>();
            Mock <IDASPaymentsProviderService>           dasPaymentProviderMock          = new Mock <IDASPaymentsProviderService>();
            Mock <IFM36PeriodEndProviderService>         fm36ProviderServiceMock         = new Mock <IFM36PeriodEndProviderService>();
            IValueProvider valueProvider = new ValueProvider();

            storage.Setup(x => x.SaveAsync($"{filename}.csv", It.IsAny <string>(), It.IsAny <CancellationToken>())).Callback <string, string, CancellationToken>((key, value, ct) => csv = value).Returns(Task.CompletedTask);

            var appsAdditionalPaymentIlrInfo         = BuildILRModel(ukPrn);
            var appsAdditionalPaymentRulebaseInfo    = BuildFm36Model(ukPrn);
            var appsAdditionalPaymentDasPaymentsInfo = BuildDasPaymentsModel(ukPrn);

            IlrPeriodEndProviderServiceMock.Setup(x => x.GetILRInfoForAppsAdditionalPaymentsReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync(appsAdditionalPaymentIlrInfo);
            fm36ProviderServiceMock.Setup(x => x.GetFM36DataForAppsAdditionalPaymentReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync(appsAdditionalPaymentRulebaseInfo);
            dasPaymentProviderMock.Setup(x => x.GetPaymentsInfoForAppsAdditionalPaymentsReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync(appsAdditionalPaymentDasPaymentsInfo);

            dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(dateTime);
            dateTimeProviderMock.Setup(x => x.ConvertUtcToUk(It.IsAny <DateTime>())).Returns(dateTime);
            var appsAdditionalPaymentsModelBuilder = new AppsAdditionalPaymentsModelBuilder();

            var report = new ReportService.Service.Reports.PeriodEnd.AppsAdditionalPaymentsReport(
                logger.Object,
                storage.Object,
                IlrPeriodEndProviderServiceMock.Object,
                fm36ProviderServiceMock.Object,
                dateTimeProviderMock.Object,
                valueProvider,
                dasPaymentProviderMock.Object,
                appsAdditionalPaymentsModelBuilder);

            await report.GenerateReport(reportServiceContextMock.Object, null, false, CancellationToken.None);

            csv.Should().NotBeNullOrEmpty();
            File.WriteAllText($"{filename}.csv", csv);
            TestCsvHelper.CheckCsv(csv, new CsvEntry(new AppsAdditionalPaymentsMapper(), 1));
            IEnumerable <AppsAdditionalPaymentsModel> result;

            using (var reader = new StreamReader($"{filename}.csv"))
            {
                using (var csvReader = new CsvReader(reader))
                {
                    csvReader.Configuration.RegisterClassMap <AppsAdditionalPaymentsMapper>();
                    result = csvReader.GetRecords <AppsAdditionalPaymentsModel>().ToList();
                }
            }

            result.Should().NotBeNullOrEmpty();
            result.Count().Should().Be(1);
            result.First().AprilEarnings.Should().Be(180);
            result.First().JulyEarnings.Should().Be(240);
            result.First().DecemberEarnings.Should().Be(100);
            result.First().TotalEarnings.Should().Be(1560);
            result.First().TotalPaymentsYearToDate.Should().Be(20);
            result.First().UniqueLearnerNumber.Should().Be(12345);
        }