Пример #1
0
        public async Task ReportControllerOrganizationsReportsGet_ReturnsCorrectResponseShape()
        {
            User         user;
            Organization organization;

            Site[] sites;
            Report report;

            using (var context = new TestHedwigContextProvider().Context)
            {
                organization = OrganizationHelper.CreateOrganization(context);
                var site1 = SiteHelper.CreateSite(context, organization: organization);
                var site2 = SiteHelper.CreateSite(context, organization: organization);
                report = ReportHelper.CreateCdcReport(context, organization: organization);
                sites  = new Site[] { site1, site2 };
                EnrollmentHelper.CreateEnrollment(context, site: site1);
                user = UserHelper.CreateUser(context);
                PermissionHelper.CreateSitePermission(context, user, site1);
                PermissionHelper.CreateSitePermission(context, user, site2);
                PermissionHelper.CreateOrganizationPermission(context, user, organization);
            }

            var client = _factory.CreateClient();

            var request = HedwigAPIRequests.OrganizationReports(
                user,
                organization
                );

            var response = await client.SendAsync(request);

            response.EnsureSuccessStatusCode();

            var responseString = await response.Content.ReadAsStringAsync();

            var responseReports = JsonConvert.DeserializeObject <List <CdcReport> >(responseString);

            Assert.NotEmpty(responseReports);

            var responseReport = responseReports.First();

            Assert.NotNull(responseReport);
            Assert.Equal(report.Id, responseReport.Id);
            Assert.NotNull(responseReport.Organization);
            Assert.Null(responseReport.Organization.FundingSpaces);
            Assert.Null(responseReport.Organization.Sites);
            Assert.NotNull(responseReport.ReportingPeriod);
            Assert.Null(responseReport.Enrollments);
        }
        public async Task OrganizationControllerOrganizationsGet_ReturnsCorrectResponseShape(
            string[] include,
            bool isInclude
            )
        {
            User         user;
            Organization organization;

            Site[] sites;
            using (var context = new TestHedwigContextProvider().Context)
            {
                organization = OrganizationHelper.CreateOrganization(context);
                var site1 = SiteHelper.CreateSite(context, organization: organization);
                var site2 = SiteHelper.CreateSite(context, organization: organization);
                sites = new Site[] { site1, site2 };
                EnrollmentHelper.CreateEnrollment(context, site: site1);
                user = UserHelper.CreateUser(context);
                PermissionHelper.CreateSitePermission(context, user, site1);
                PermissionHelper.CreateSitePermission(context, user, site2);
                PermissionHelper.CreateOrganizationPermission(context, user, organization);
            }

            var client = _factory.CreateClient();

            var request = HedwigAPIRequests.Organizations(
                user,
                organization,
                include
                );

            var response = await client.SendAsync(request);

            response.EnsureSuccessStatusCode();

            var responseString = await response.Content.ReadAsStringAsync();

            var responseOrganization = JsonConvert.DeserializeObject <Organization>(responseString);

            Assert.NotNull(responseOrganization);
            Assert.Equal(organization.Id, responseOrganization.Id);
            Assert.Equal(organization.Name, responseOrganization.Name);
            Assert.Null(responseOrganization.Reports);
            if (isInclude)
            {
                Assert.NotEmpty(responseOrganization.Sites);
                Assert.All(
                    responseOrganization.Sites,
                    site =>
                {
                    Assert.NotNull(site.Name);
                    Assert.Null(site.Organization);
                    Assert.Null(site.Enrollments);
                }
                    );
                Assert.Null(responseOrganization.Reports);
                Assert.NotNull(responseOrganization.FundingSpaces);
                Assert.All(
                    responseOrganization.FundingSpaces,
                    fundingSpace =>
                {
                    Assert.NotNull(fundingSpace);
                    Assert.Equal(fundingSpace.Time == FundingTime.Split, fundingSpace.TimeSplit != null);
                }
                    );
            }
            else
            {
                Assert.Null(responseOrganization.Sites);
                Assert.Null(responseOrganization.FundingSpaces);
            }
        }
Пример #3
0
        public async Task ReportControllerOrganizationsReportGet_ReturnsCorrectResponseShape()
        {
            User         user;
            Organization organization;

            Site[] sites;
            Report report;

            using (var context = new TestHedwigContextProvider().Context)
            {
                organization = OrganizationHelper.CreateOrganization(context);
                var site1 = SiteHelper.CreateSite(context, organization: organization);
                var site2 = SiteHelper.CreateSite(context, organization: organization);
                report = ReportHelper.CreateCdcReport(context, organization: organization);
                sites  = new Site[] { site1, site2 };
                EnrollmentHelper.CreateEnrollment(context, site: site1);
                user = UserHelper.CreateUser(context);
                PermissionHelper.CreateSitePermission(context, user, site1);
                PermissionHelper.CreateSitePermission(context, user, site2);
                PermissionHelper.CreateOrganizationPermission(context, user, organization);
            }

            var client = _factory.CreateClient();

            var request = HedwigAPIRequests.OrganizationReport(
                user,
                organization,
                report
                );

            var response = await client.SendAsync(request);

            response.EnsureSuccessStatusCode();

            var responseString = await response.Content.ReadAsStringAsync();

            var responseReport = JsonConvert.DeserializeObject <CdcReport>(responseString);

            Assert.NotNull(responseReport);
            Assert.Equal(report.Id, responseReport.Id);
            Assert.NotNull(responseReport.Organization);
            Assert.All(
                responseReport.Organization.Sites,
                site =>
            {
                Assert.NotNull(site.Name);
                Assert.Null(site.Organization);
                Assert.Null(site.Enrollments);
            }
                );
            Assert.NotNull(responseReport.Organization.FundingSpaces);
            Assert.All(
                responseReport.Organization.FundingSpaces,
                fundingSpace =>
            {
                Assert.NotNull(fundingSpace);
                Assert.Equal(fundingSpace.Time == FundingTime.Split, fundingSpace.TimeSplit != null);
            }
                );
            Assert.NotNull(responseReport.ReportingPeriod);
            Assert.NotNull(responseReport.Enrollments);
            Assert.All(
                responseReport.Enrollments,
                enrollment =>
            {
                Assert.NotNull(enrollment.Child);
                Assert.Null(enrollment.Child.Family);
                Assert.Null(enrollment.Child.Enrollments);
                Assert.Null(enrollment.Child.Organization);
                Assert.Null(enrollment.Site);
                Assert.All(
                    enrollment.Fundings,
                    funding =>
                {
                    Assert.NotNull(funding.FundingSpace);
                    Assert.Equal(funding.FundingSpace.Time == FundingTime.Split, funding.FundingSpace.TimeSplit != null);
                    Assert.NotNull(funding.Source);
                    Assert.NotNull(funding.FirstReportingPeriod);
                    Assert.NotNull(funding.LastReportingPeriod);
                }
                    );
                Assert.Null(enrollment.PastEnrollments);
            }
                );
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
        public async Task EnrollmentControllerOrganizationSiteEnrollmentGet_ReturnsCorrectResponseShape()
        {
            Enrollment   enrollment;
            User         user;
            Organization organization;
            Site         site;

            using (var context = new TestHedwigContextProvider().Context)
            {
                organization = OrganizationHelper.CreateOrganization(context);
                site         = SiteHelper.CreateSite(context, organization: organization);
                enrollment   = EnrollmentHelper.CreateEnrollment(context, site: site);
                user         = UserHelper.CreateUser(context);
                PermissionHelper.CreateSitePermission(context, user, site);
                PermissionHelper.CreateOrganizationPermission(context, user, organization);
            }

            var client = _factory.CreateClient();

            var request = HedwigAPIRequests.OrganizationSiteEnrollmentDetail(
                user,
                enrollment,
                organization,
                site
                );

            var response = await client.SendAsync(request);

            response.EnsureSuccessStatusCode();

            var responseString = await response.Content.ReadAsStringAsync();

            var responseEnrollment = JsonConvert.DeserializeObject <Enrollment>(responseString);

            Assert.NotNull(responseEnrollment);
            Assert.Equal(enrollment.Id, responseEnrollment.Id);
            Assert.Equal(enrollment.ChildId, responseEnrollment.ChildId);
            Assert.NotNull(responseEnrollment.Child);
            Assert.Equal(enrollment.ChildId, responseEnrollment.Child.Id);
            Assert.Equal(enrollment.Child.FirstName, responseEnrollment.Child.FirstName);
            Assert.Equal(enrollment.Child.MiddleName, responseEnrollment.Child.MiddleName);
            Assert.Equal(enrollment.Child.LastName, responseEnrollment.Child.LastName);
            Assert.Empty(responseEnrollment.Child.Enrollments);
            Assert.Equal(enrollment.SiteId, responseEnrollment.SiteId);
            Assert.NotNull(responseEnrollment.Site);
            Assert.NotNull(responseEnrollment.Site.Name);
            Assert.Empty(responseEnrollment.Site.Enrollments);
            Assert.Equal(enrollment.AgeGroup, responseEnrollment.AgeGroup);
            Assert.Equal(enrollment.Entry, responseEnrollment.Entry);
            Assert.Equal(enrollment.Exit, responseEnrollment.Exit);
            Assert.Equal(enrollment.ExitReason, responseEnrollment.ExitReason);
            Assert.All(
                responseEnrollment.Fundings,
                funding =>
            {
                Assert.NotNull(funding.FundingSpace);
                Assert.Equal(funding.FundingSpace.Time == FundingTime.Split, funding.FundingSpace.TimeSplit != null);
                Assert.NotNull(funding.Source);
                Assert.NotNull(funding.FirstReportingPeriod);
                Assert.NotNull(funding.LastReportingPeriod);
            }
                );
        }
Пример #6
0
        public async Task EnrollmentControllerOrganizationSiteEnrollmentPost_AddsEnrollment_And_ReturnsCorrectResponseShape(
            string firstName,
            string lastName,
            bool isSuccess
            )
        {
            User         user;
            Organization organization;
            Site         site;

            using (var context = new TestHedwigContextProvider().Context)
            {
                organization = OrganizationHelper.CreateOrganization(context);
                site         = SiteHelper.CreateSite(context, organization: organization);
                user         = UserHelper.CreateUser(context);
                PermissionHelper.CreateSitePermission(context, user, site);
                PermissionHelper.CreateOrganizationPermission(context, user, organization);
            }

            Child child = new Child
            {
                FirstName      = firstName,
                LastName       = lastName,
                OrganizationId = organization.Id
            };
            Enrollment enrollment = new Enrollment
            {
                Child  = child,
                SiteId = site.Id
            };

            var client = _factory.CreateClient();

            var request = HedwigAPIRequests.EnrollmentPost(
                user,
                enrollment,
                organization,
                site
                );

            var response = await client.SendAsync(request);

            if (!isSuccess)
            {
                Assert.False(response.IsSuccessStatusCode);
            }
            else
            {
                response.EnsureSuccessStatusCode();

                var responseString = await response.Content.ReadAsStringAsync();

                var responseEnrollment = JsonConvert.DeserializeObject <Enrollment>(responseString);
                Assert.NotNull(responseEnrollment);
                Assert.NotNull(responseEnrollment.Child);
                Assert.Equal(enrollment.Child.FirstName, responseEnrollment.Child.FirstName);
                Assert.Equal(enrollment.Child.MiddleName, responseEnrollment.Child.MiddleName);
                Assert.Equal(enrollment.Child.LastName, responseEnrollment.Child.LastName);
                Assert.Null(responseEnrollment.Child.Family);
                Assert.Empty(responseEnrollment.Child.Enrollments);
                Assert.Equal(site.Id, responseEnrollment.SiteId);
                Assert.Null(responseEnrollment.Site);
                Assert.Equal(enrollment.AgeGroup, responseEnrollment.AgeGroup);
                Assert.Equal(enrollment.Entry, responseEnrollment.Entry);
                Assert.Equal(enrollment.Exit, responseEnrollment.Exit);
                Assert.Equal(enrollment.ExitReason, responseEnrollment.ExitReason);
                Assert.Null(responseEnrollment.Fundings);

                using (var context = new TestHedwigContextProvider().Context)
                {
                    var dbEnrollment = context.Enrollments.FirstOrDefault(
                        e => e.Id == responseEnrollment.Id
                        );
                    Assert.NotNull(dbEnrollment);
                }
            }
        }