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 void UpdateEnrollment_AddsFundings() { Enrollment enrollment; FundingSpace fundingSpace; using (var context = new TestHedwigContextProvider().Context) { enrollment = EnrollmentHelper.CreateEnrollment(context); fundingSpace = FundingSpaceHelper.CreateFundingSpace( context, organizationId: enrollment.Site.OrganizationId, source: FundingSource.CDC, ageGroup: enrollment.AgeGroup.Value ); } Funding funding = new Funding { EnrollmentId = enrollment.Id, Source = FundingSource.CDC, FundingSpaceId = fundingSpace.Id }; Assert.Null(enrollment.Fundings); enrollment.Fundings = new List <Funding> { funding }; var mapper = new MapperConfiguration(opts => { opts.AddProfile(new EnrollmentProfile()); opts.AddProfile(new FundingProfile()); opts.AddProfile(new ChildProfile()); opts.AddProfile(new FamilyProfile()); opts.AddProfile(new SiteProfile()); }).CreateMapper(); using (var context = new TestHedwigContextProvider().Context) { 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 enrollmentRepo = new EnrollmentRepository(context, mapper); var retrievedEnrollment = enrollmentRepo.GetEnrollmentById(enrollment.Id); Assert.NotEmpty(retrievedEnrollment.Fundings); var retrievedFunding = retrievedEnrollment.Fundings.FirstOrDefault(); Assert.Equal(funding.Id, retrievedFunding.Id); } }
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 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); } }