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);
            }
        }
        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_DoesNotAddEnrollmentsToReport(bool reportHasEnrollmentsReference)
        {
            CdcReport report;

            using (var context = new TestHedwigContextProvider().Context)
            {
                report = ReportHelper.CreateCdcReport(context) as CdcReport;
                var site        = SiteHelper.CreateSite(context, organization: report.Organization);
                var enrollments = EnrollmentHelper.CreateEnrollments(context, 1, site: site);
                report.Enrollments = enrollments;
            }

            if (!reportHasEnrollmentsReference)
            {
                report.Enrollments = null;
            }

            using (var context = new TestHedwigContextProvider().Context)
            {
                context.Attach(report);

                var _serviceProvider = new Mock <IServiceProvider>();
                _serviceProvider.Setup(sp => sp.GetService(typeof(IEnumerable <IValidationRule <Enrollment> >)))
                .Returns(new List <IValidationRule <Enrollment> >());
                var _validator = new NonBlockingValidator(_serviceProvider.Object);
                var _reports   = new ReportRepository(context);

                // when
                var rule = new EnrollmentsAreValid(_validator, _reports);
                rule.Execute(report, new NonBlockingValidationContext());

                // then
                Assert.Equal(reportHasEnrollmentsReference, report.Enrollments != null);
            }
        }