Ejemplo n.º 1
0
        public void ReportingPeriod_Returns_AsExpected(ReportingFrequency reportingFrequency)
        {
            var now       = DateTimeDbTestExtensions.SetLocalNowToRandomDate();
            var startDate = now.AddYears(-2);
            var endDate   = now.AddYears(1);

            var reportingPeriods = ReportingPeriod.GetReportingPeriods(startDate, endDate, reportingFrequency);

            if (reportingFrequency == ReportingFrequency.Yearly)
            {
                reportingPeriods.Length.Should().Be(4);
                reportingPeriods[0].Year.Should().Be(startDate.Year);
                reportingPeriods[0].ReportingTerm.Should().Be(ReportingTerm.One);
                reportingPeriods[0].ReportingFrequency.Should().Be(reportingFrequency);
                reportingPeriods[3].Year.Should().Be(endDate.Year);
                reportingPeriods[3].ReportingTerm.Should().Be(ReportingTerm.One);
                reportingPeriods[3].ReportingFrequency.Should().Be(reportingFrequency);
            }
            if (reportingFrequency == ReportingFrequency.Quarterly)
            {
                reportingPeriods.Length.Should().Be(16);
                reportingPeriods[0].Year.Should().Be(startDate.Year);
                reportingPeriods[0].ReportingTerm.Should().Be(ReportingTerm.One);
                reportingPeriods[0].ReportingFrequency.Should().Be(reportingFrequency);
                reportingPeriods[15].Year.Should().Be(endDate.Year);
                reportingPeriods[15].ReportingTerm.Should().Be(ReportingTerm.Four);
                reportingPeriods[15].ReportingFrequency.Should().Be(reportingFrequency);
            }
            if (reportingFrequency == ReportingFrequency.Monthly)
            {
                reportingPeriods.Length.Should().Be(48);
                reportingPeriods[0].Year.Should().Be(startDate.Year);
                reportingPeriods[0].ReportingTerm.Should().Be(ReportingTerm.One);
                reportingPeriods[0].ReportingFrequency.Should().Be(reportingFrequency);
                reportingPeriods[47].Year.Should().Be(endDate.Year);
                reportingPeriods[47].ReportingTerm.Should().Be(ReportingTerm.Twelve);
                reportingPeriods[47].ReportingFrequency.Should().Be(reportingFrequency);
            }
        }
        public void GetReportingPeriodsToCreatePlan_For_User_Should_Return_CorrectResult(OrganizationType organizationType)
        {
            DateTimeDbTestExtensions.SetLocalNowToRandomDate();
            var username   = DataProvider.Get <string>();
            var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer,
                                                          s =>
            {
                var organizations = IntegrationTestOrganizationHelper.SetupOrzanizations();

                var central = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.Central).Value;
                var state   = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.NswState).Value;
                var zone    = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.NswZoneOne).Value;
                var unit    = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.Footscray).Value;

                EntityReference sut = null;
                switch (organizationType)
                {
                case OrganizationType.Central:
                    sut = central;
                    break;

                case OrganizationType.State:
                    sut = state;
                    break;

                case OrganizationType.Zone:
                    sut = zone;
                    break;

                default:
                    sut = unit;
                    break;
                }

                var organizationUser1 = new TestObjectBuilder <OrganizationUser>()
                                        .SetArgument(o => o.Username, username)
                                        .SetArgument(o => o.Organization, sut)
                                        .BuildAndPersist(s);

                new UserContextBuilder()
                .SetUsername(username)
                .AddClaims(TestHelper.GetOrganizationClaims(username, new[] { organizationUser1 }))
                .SetCurrentPrincipal();


                return(new
                {
                    sut
                });
            });

            var result = NsbWebTest.Act(AssemblySetupFixture.WebTestContainer,
                                        c =>
            {
                return(c.GetInstance <OrganizationQueryService>()
                       .GetReportingPeriods(testParams.sut.Id));
            });

            if (organizationType == OrganizationType.Unit)
            {
                result.Length.Should().Be(36);
                var activeReportPeriod = result.Single(o => o.IsActive);
                activeReportPeriod.Should().NotBeNull();
            }
            else
            {
                result.Length.Should().Be(20);
                var activeAnnualReportPeriod = result.Single(o => o.IsActive && o.ReportingFrequency == ReportingFrequency.Yearly);
                activeAnnualReportPeriod.Should().NotBeNull();

                var activeQuarterlyReportPeriod = result.Single(o => o.IsActive && o.ReportingFrequency == ReportingFrequency.Quarterly);
                activeQuarterlyReportPeriod.Should().NotBeNull();
            }
        }