public void Execute_DoesNotAddFundingsToEnrollment(bool enrollmentHasFundingsReference)
        {
            Enrollment enrollment;

            using (var context = new TestHedwigContextProvider().Context)
            {
                enrollment = EnrollmentHelper.CreateEnrollment(context);
                FundingHelper.CreateFunding(context, enrollment: enrollment);
            }

            if (!enrollmentHasFundingsReference)
            {
                enrollment.Fundings = null;
            }

            using (var context = new TestHedwigContextProvider().Context)
            {
                // Only attach found entity to avoid attaching the entire object graph
                // (which would find & attach the fundings navigation property)
                context.Attach(context.Find(enrollment.GetType(), enrollment.Id));
                var _serviceProvider = new Mock <IServiceProvider>();
                _serviceProvider.Setup(sp => sp.GetService(typeof(IEnumerable <IValidationRule <Funding> >)))
                .Returns(new List <IValidationRule <Funding> >());
                var _validator = new NonBlockingValidator(_serviceProvider.Object);
                var _fundings  = new FundingRepository(context);

                // when
                var rule = new FundingsAreValid(_validator, _fundings);
                rule.Execute(enrollment, new NonBlockingValidationContext());

                // then
                Assert.Equal(enrollmentHasFundingsReference, enrollment.Fundings != null);
            }
        }
        public void Execute_DoesNotAddEnrollmentToFunding(bool fundingHasEnrollmentReference)
        {
            Funding funding;

            using (var context = new TestHedwigContextProvider().Context)
            {
                funding = FundingHelper.CreateFunding(context);
            }

            if (!fundingHasEnrollmentReference)
            {
                funding.Enrollment = null;
            }

            using (var context = new TestHedwigContextProvider().Context)
            {
                // Only attach found entity to avoid attaching the entire object graph
                // (which would find & attach the enrollment navigation property)
                context.Attach(context.Find(funding.GetType(), funding.Id));

                var _serviceProvider  = new Mock <IServiceProvider>();
                var _validator        = new NonBlockingValidator(_serviceProvider.Object);
                var _fundings         = new FundingRepository(context);
                var _enrollments      = new EnrollmentRepository(context);
                var _reportingPeriods = new ReportingPeriodRepository(context);

                // when
                var rule = new FundingTimelinesAreValid(_fundings, _enrollments, _reportingPeriods);
                rule.Execute(funding, new NonBlockingValidationContext());

                // then
                Assert.Equal(fundingHasEnrollmentReference, funding.Enrollment != null);
            }
        }
Exemple #3
0
        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);
                }
            }
        }
Exemple #4
0
        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);
            }
        }
Exemple #5
0
        public void UpdateEnrollment_RemovesFundings()
        {
            Enrollment enrollment;

            using (var context = new TestHedwigContextProvider().Context)
            {
                enrollment = EnrollmentHelper.CreateEnrollment(context);
                FundingHelper.CreateFunding(context, enrollment: enrollment);
            }

            Assert.NotEmpty(enrollment.Fundings);
            enrollment.Fundings = new List <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.Empty(retrievedEnrollment.Fundings);
            }
        }