public void GetReportsForFiscalYear( int year, int month, int day, int total ) { var reportDate = new DateTime(year, month, day); Organization organization; using (var context = new TestHedwigContextProvider().Context) { var dates = new List <DateTime> { new DateTime(2010, 1, 1), new DateTime(2010, 5, 1), new DateTime(2010, 7, 1), new DateTime(2011, 2, 1), new DateTime(2011, 7, 1), }; organization = OrganizationHelper.CreateOrganization(context); foreach (var date in dates) { var reportingPeriod = ReportingPeriodHelper.CreateReportingPeriod(context, period: date.ToString("yyyy-MM-dd")); ReportHelper.CreateCdcReport(context, organization: organization, reportingPeriod: reportingPeriod); } } using (var context = new TestHedwigContextProvider().Context) { var reportRepo = new ReportRepository(context); var result = reportRepo.GetReportsForOrganizationByFiscalYear(organization.Id, reportDate); Assert.Equal(total, result.Count()); } }
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)); } } }
public async Task Get_Report_For_Organization(bool submitted, string[] include) { using (var context = new TestHedwigContextProvider().Context) { // Set up test data var organization = OrganizationHelper.CreateOrganization(context); var reportingPeriod = ReportingPeriodHelper.CreateReportingPeriod(context); var report = ReportHelper.CreateCdcReport(context, organization: organization, reportingPeriod: reportingPeriod); var site = SiteHelper.CreateSite(context, organization: organization); var enrollment = EnrollmentHelper.CreateEnrollment(context, site: site, ageGroup: Age.Preschool); var funding = FundingHelper.CreateFunding(context, enrollment: enrollment, firstReportingPeriod: reportingPeriod); if (submitted) { Thread.Sleep(1000); report.SubmittedAt = DateTime.Now; context.SaveChanges(); Thread.Sleep(1000); } enrollment.AgeGroup = Age.SchoolAge; context.SaveChanges(); // When the repository is queried var repo = new ReportRepository(context); var result = await repo.GetReportForOrganizationAsync(report.Id, organization.Id, include) as CdcReport; // It returns the Report Assert.Equal(result.Id, report.Id); // It includes the Organization Assert.Equal(include.Contains("organizations"), result.Organization != null); // It includes the Sites Assert.Equal(include.Contains("sites"), result.Organization != null && result.Organization.Sites != null); // It includes the Enrollments (and Fundings too) Assert.Equal( include.Contains("enrollments"), result.Enrollments != null && result.Enrollments.FirstOrDefault().Fundings != null ); // When it includes enrollments if (include.Contains("enrollments")) { var enrollmentResult = result.Enrollments.FirstOrDefault(); var fundingResult = enrollmentResult.Fundings.FirstOrDefault(); // A submitted report should return the data as of when it was submitted Assert.Equal(submitted ? Age.Preschool : Age.SchoolAge, enrollmentResult.AgeGroup); } } }
public void UpdateEnrollment_UpdatesFundings() { Enrollment enrollment; Funding funding; ReportingPeriod reportingPeriod; using (var context = new TestHedwigContextProvider().Context) { enrollment = EnrollmentHelper.CreateEnrollment(context); funding = FundingHelper.CreateFunding(context, enrollment: enrollment); reportingPeriod = ReportingPeriodHelper.CreateReportingPeriod(context); } Assert.Null(funding.FirstReportingPeriodId); funding.FirstReportingPeriodId = reportingPeriod.Id; enrollment.Fundings = new List <Funding> { funding }; enrollment.Fundings.FirstOrDefault().Enrollment = null; using (var context = new TestHedwigContextProvider().Context) { var mapper = new MapperConfiguration(opts => { opts.AddProfile(new EnrollmentProfile()); opts.AddProfile(new FundingProfile()); opts.AddProfile(new FundingSpaceProfile()); opts.AddProfile(new ChildProfile()); opts.AddProfile(new FamilyProfile()); opts.AddProfile(new SiteProfile()); }).CreateMapper(); var enrollmentRepo = new EnrollmentRepository(context, mapper); var enrollmentDTO = mapper.Map <Enrollment, EnrollmentDTO>(enrollment); enrollmentRepo.UpdateEnrollment(enrollment, enrollmentDTO); context.SaveChanges(); } using (var context = new TestHedwigContextProvider().Context) { var retrievedEnrollment = context.Enrollments .Where(e => e.Id == enrollment.Id) .Include(e => e.Fundings) .FirstOrDefault(); var retrievedFunding = retrievedEnrollment.Fundings.FirstOrDefault(); Assert.NotNull(retrievedFunding.FirstReportingPeriodId); Assert.Equal(funding.FirstReportingPeriodId, retrievedFunding.FirstReportingPeriodId); } }
public async Task DoesNotCreateDuplicateReports() { int organizationId; using (var context = new TestHedwigContextProvider().Context) { var organization = OrganizationHelper.CreateOrganization(context); organizationId = organization.Id; var fundingSpace = FundingSpaceHelper.CreateFundingSpace(context, organizationId); organization.FundingSpaces = new List <FundingSpace> { fundingSpace }; var currentReportingPeriod = ReportingPeriodHelper.CreateReportingPeriod(context); } 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("2019-10-01")); var cdcReportGenerator = new CdcReportGeneratorScopedService( logger.Object, orgRepo, reportingPeriodRepo, reportRepo, dateTime.Object ); var previousReports = reportRepo.GetReportsForOrganization(organizationId); await cdcReportGenerator.TryGenerateReports(); await cdcReportGenerator.TryGenerateReports(); await cdcReportGenerator.TryGenerateReports(); var reports = reportRepo.GetReportsForOrganization(organizationId); Assert.Empty(previousReports); Assert.Single(reports); } }
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); } }
public async Task ReportControllerOrganizationsReportPut_IsSuccessfull_OrReturnsValidationError( int partTimeWeeksUsed, bool shouldSucceed ) { User user; Organization organization; FundingSpace fundingSpace; Site site; CdcReport report; using (var context = new TestHedwigContextProvider().Context) { organization = OrganizationHelper.CreateOrganization(context); var reportingPeriod = ReportingPeriodHelper.CreateReportingPeriod(context, period: "2010-01-01", periodStart: "2010-01-01", periodEnd: "2010-01-31"); fundingSpace = FundingSpaceHelper.CreateFundingSpace(context, organization.Id, time: FundingTime.Split); site = SiteHelper.CreateSite(context, organization: organization); report = ReportHelper.CreateCdcReport(context, organization: organization, reportingPeriod: reportingPeriod) as CdcReport; EnrollmentHelper.CreateEnrollment(context, site: site); user = UserHelper.CreateUser(context); PermissionHelper.CreateSitePermission(context, user, site); PermissionHelper.CreateOrganizationPermission(context, user, organization); } var timeSplitUtilization = new FundingTimeSplitUtilization { ReportId = report.Id, ReportingPeriodId = report.ReportingPeriodId, FundingSpaceId = fundingSpace.Id, PartTimeWeeksUsed = partTimeWeeksUsed, FullTimeWeeksUsed = 0, }; typeof(FundingTimeSplitUtilization).GetProperty(nameof(FundingTimeSplitUtilization.ReportingPeriod)).SetValue(timeSplitUtilization, report.ReportingPeriod); var reportForPut = new CdcReport { Id = report.Id, Accredited = report.Accredited, Comment = report.Comment, Enrollments = report.Enrollments, C4KRevenue = 0, FamilyFeesRevenue = 0, OrganizationId = report.OrganizationId, ReportingPeriodId = report.ReportingPeriodId, TimeSplitUtilizations = new List <FundingTimeSplitUtilization> { timeSplitUtilization }, }; typeof(Report).GetProperty(nameof(Report.ReportingPeriod)).SetValue(reportForPut, report.ReportingPeriod); var request = HedwigAPIRequests.OrganizationReportPut( user, organization, reportForPut ); var client = _factory.CreateClient(); var response = await client.SendAsync(request); if (shouldSucceed) { response.EnsureSuccessStatusCode(); } else { Assert.False(response.IsSuccessStatusCode); } }