Пример #1
0
        public async Task TestAppsMonthlyPaymentReportGeneration()
        {
            string   csv      = string.Empty;
            DateTime dateTime = DateTime.UtcNow;
            string   filename = $"10036143_1_Apps Monthly Payment Report {dateTime:yyyyMMdd-HHmmss}";

            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(10036143);

            Mock <ILogger>           logger = new Mock <ILogger>();
            Mock <IDateTimeProvider> dateTimeProviderMock        = new Mock <IDateTimeProvider>();
            Mock <IStreamableKeyValuePersistenceService> storage = new Mock <IStreamableKeyValuePersistenceService>();
            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);

            IIntUtilitiesService      intUtilitiesService      = new IntUtilitiesService();
            IJsonSerializationService jsonSerializationService = new JsonSerializationService();
            IXmlSerializationService  xmlSerializationService  = new XmlSerializationService();

            DataStoreConfiguration dataStoreConfiguration = new DataStoreConfiguration()
            {
                ILRDataStoreConnectionString      = new TestConfigurationHelper().GetSectionValues <DataStoreConfiguration>("DataStoreSection").ILRDataStoreConnectionString,
                ILRDataStoreValidConnectionString = new TestConfigurationHelper().GetSectionValues <DataStoreConfiguration>("DataStoreSection").ILRDataStoreValidConnectionString
            };

            IIlr1819ValidContext IlrValidContextFactory()
            {
                var options = new DbContextOptionsBuilder <ILR1819_DataStoreEntitiesValid>().UseSqlServer(dataStoreConfiguration.ILRDataStoreValidConnectionString).Options;

                return(new ILR1819_DataStoreEntitiesValid(options));
            }

            IIlr1819RulebaseContext IlrRulebaseValidContextFactory()
            {
                var options = new DbContextOptionsBuilder <ILR1819_DataStoreEntities>().UseSqlServer(dataStoreConfiguration.ILRDataStoreConnectionString).Options;

                return(new ILR1819_DataStoreEntities(options));
            }

            IIlrProviderService     ilrProviderService     = new IlrProviderService(logger.Object, storage.Object, xmlSerializationService, dateTimeProviderMock.Object, intUtilitiesService, IlrValidContextFactory, IlrRulebaseValidContextFactory);
            IFM36ProviderService    fm36ProviderService    = new FM36ProviderService(logger.Object, storage.Object, jsonSerializationService, intUtilitiesService, IlrRulebaseValidContextFactory);
            IStringUtilitiesService stringUtilitiesService = new StringUtilitiesService();

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

            var report = new ReportService.Service.Reports.PeriodEnd.AppsMonthlyPaymentReport(logger.Object, storage.Object, ilrProviderService, fm36ProviderService, stringUtilitiesService, dateTimeProviderMock.Object, valueProvider, topicsAndTasks, appsMonthlyPaymentModelBuilder);

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

            csv.Should().NotBeNullOrEmpty();
            File.WriteAllText($"{filename}.csv", csv);
            TestCsvHelper.CheckCsv(csv, new CsvEntry(new AppsMonthlyPaymentMapper(), 1));
        }
        public async Task TestAppsMonthlyPaymentReportGeneration()
        {
            string   csv      = string.Empty;
            DateTime dateTime = DateTime.UtcNow;
            int      ukPrn    = 10036143;
            string   filename = $"10036143_1_Apps Monthly Payment Report {dateTime:yyyyMMdd-HHmmss}";

            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(10036143);

            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>();
            Mock <ILarsProviderService> larsProviderServiceMock = new Mock <ILarsProviderService>();
            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 appsMonthlyPaymentIlrInfo      = BuildILRModel(ukPrn);
            var appsMonthlyPaymentRulebaseInfo = BuildFm36Model(ukPrn);
            var appsMonthlyPaymentDasInfo      = BuildDasPaymentsModel(ukPrn);
            var larsDeliveryInfoModel          = BuildLarsDeliveryInfoModel();

            IlrPeriodEndProviderServiceMock.Setup(x => x.GetILRInfoForAppsMonthlyPaymentReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync(appsMonthlyPaymentIlrInfo);
            fm36ProviderServiceMock.Setup(x => x.GetFM36DataForAppsMonthlyPaymentReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync(appsMonthlyPaymentRulebaseInfo);
            dasPaymentProviderMock.Setup(x => x.GetPaymentsInfoForAppsMonthlyPaymentReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync(appsMonthlyPaymentDasInfo);
            larsProviderServiceMock.Setup(x => x.GetLarsLearningDeliveryInfoForAppsMonthlyPaymentReportAsync(It.IsAny <string[]>(), It.IsAny <CancellationToken>())).ReturnsAsync(larsDeliveryInfoModel);

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

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

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

            csv.Should().NotBeNullOrEmpty();
            File.WriteAllText($"{filename}.csv", csv);
            IEnumerable <AppsMonthlyPaymentModel> result;

            TestCsvHelper.CheckCsv(csv, new CsvEntry(new AppsMonthlyPaymentMapper(), 1));
            using (var reader = new StreamReader($"{filename}.csv"))
            {
                using (var csvReader = new CsvReader(reader))
                {
                    csvReader.Configuration.RegisterClassMap <AppsMonthlyPaymentMapper>();
                    result = csvReader.GetRecords <AppsMonthlyPaymentModel>().ToList();
                }
            }

            result.Should().NotBeNullOrEmpty();
            result.Count().Should().Be(1);
            result.First().LearnerReferenceNumber.Should().Be("A12345");
            result.First().UniqueLearnerNumber.Should().Be(12345);
            result.First().CampusIdentifier.Should().Be("camp101");
            result.First().AimSeqNumber.Should().Be(1);
            result.First().LearningAimReference.Should().Be("50117889");
            result.First().LearningStartDate.Should().Be("28/06/2017");
            result.First().LearningAimProgrammeType.Should().Be(1);
            result.First().LearningAimStandardCode.Should().Be(1);
            result.First().LearningAimFrameworkCode.Should().Be(1);
            result.First().LearningAimPathwayCode.Should().Be(1);
            result.First().AimType.Should().Be(3);
            result.First().FundingLineType.Should().Be("16-18 Apprenticeship Non-Levy");
            result.First().LearningDeliveryFAMTypeApprenticeshipContractType.Should().Be(2);
            result.First().AugustLevyPayments.Should().Be(11);
            result.First().AugustCoInvestmentPayments.Should().Be(12);
            result.First().AugustTotalPayments.Should().Be(116);
            result.First().TotalLevyPayments.Should().Be(143);
            result.First().TotalCoInvestmentPayments.Should().Be(156);
            result.First().TotalCoInvestmentDueFromEmployerPayments.Should().Be(169);
            result.First().TotalEmployerAdditionalPayments.Should().Be(182);
            result.First().TotalProviderAdditionalPayments.Should().Be(195);
            result.First().TotalApprenticeAdditionalPayments.Should().Be(208);
            result.First().TotalEnglishAndMathsPayments.Should().Be(221);
            result.First().TotalPaymentsForLearningSupport.Should().Be(234);
            result.First().TotalPayments.Should().Be(1508);
            result.First().LearningAimTitle.Should().Be("Maths & English");
        }