示例#1
0
        public async Task CreatesReportForOrganization(
            bool hasFundingSpace,
            string today,
            int numOfReportsGenerated
            )
        {
            int organizationId;
            int lastReportingPeriodId;

            using (var context = new TestHedwigContextProvider().Context)
            {
                var organization = OrganizationHelper.CreateOrganization(context);
                organizationId = organization.Id;
                if (hasFundingSpace)
                {
                    FundingSpaceHelper.CreateFundingSpace(context, organizationId);
                }

                var lastReportingPeriod = ReportingPeriodHelper.GetOrCreateReportingPeriodForPeriod(
                    context,
                    period: "2010-10-01",
                    periodStart: "2010-10-01",
                    periodEnd: "2010-10-31"
                    );
                lastReportingPeriodId = lastReportingPeriod.Id;
            }

            using (var context = new TestHedwigContextProvider().Context)
            {
                var logger              = new Mock <ILogger <CdcReportGeneratorScopedService> >();
                var orgRepo             = new OrganizationRepository(context);
                var reportingPeriodRepo = new ReportingPeriodRepository(context);
                var reportRepo          = new ReportRepository(context);
                var dateTime            = new Mock <IDateTime>();
                dateTime.Setup(dateTime => dateTime.UtcNow).Returns(DateTime.Parse(today));

                var cdcReportGenerator = new CdcReportGeneratorScopedService(
                    logger.Object,
                    orgRepo,
                    reportingPeriodRepo,
                    reportRepo,
                    dateTime.Object
                    );

                var previousReports = reportRepo.GetReportsForOrganization(organizationId);

                await cdcReportGenerator.TryGenerateReports();

                var reports = reportRepo.GetReportsForOrganization(organizationId);

                Assert.Empty(previousReports);
                Assert.Equal(numOfReportsGenerated, reports.Count());
                if (numOfReportsGenerated > 0)
                {
                    Assert.True(reports.All(report => report.ReportingPeriodId == lastReportingPeriodId));
                }
            }
        }
示例#2
0
        public void GetLastReportingPeriodBeforeDate_ReturnsMostRecentlyEndedReportingPeriod(
            string compareDateType
            )
        {
            using (var context = new TestHedwigContextProvider().Context)
            {
                var lastReportingPeriod = ReportingPeriodHelper.GetOrCreateReportingPeriodForPeriod(context, type: FundingSource.CDC, period: "2010-10-01", periodStart: "2010-10-01", periodEnd: "2010-10-31");
                // older reporting period
                ReportingPeriodHelper.GetOrCreateReportingPeriodForPeriod(context, type: FundingSource.CDC, period: "2010-09-01", periodStart: "2010-09-02", periodEnd: "2010-09-30");
                // next reporting period
                var nextReportingPeriod = ReportingPeriodHelper.GetOrCreateReportingPeriodForPeriod(context, type: FundingSource.CDC, period: "2010-11-01", periodStart: "2010-11-01", periodEnd: "2010-11-30");

                var reportingPeriodRepo = new ReportingPeriodRepository(context);
                var compareDate         = compareDateType == "lastReportingPeriodPeriodEnd"
                                        ? lastReportingPeriod.PeriodEnd
                                        : compareDateType == "nextReportingPeriodPeriodStart"
                                        ? nextReportingPeriod.PeriodStart
                                        : nextReportingPeriod.PeriodStart.AddDays(10);

                var res = reportingPeriodRepo.GetLastReportingPeriodBeforeDate(FundingSource.CDC, compareDate);

                Assert.Equal(lastReportingPeriod.Id, res.Id);
            }
        }