public async Task Handle_SavesUnitReport(ReportingFrequency reportingFrequency) { DateTimeDbTestExtensions.SetUtcNowToRandomDate(); var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { var username = DataProvider.Get <string>(); var year = 2019; var reportingTerm = ReportingTerm.One; var organization = new TestObjectBuilder <Organization>() .SetArgument(o => o.OrganizationType, OrganizationType.Unit) .SetArgument(o => o.ReportingFrequency, reportingFrequency) .BuildAndPersist(s); var cmd = new CreateUnitPlanCommand(organization, year, reportingTerm, reportingFrequency); var description = cmd.Description; var expected = new UnitReportBuilder() .SetDescription(description) .SetOrganization(organization) .SetReportingPeriod(new ReportingPeriod(reportingFrequency, reportingTerm, year)) .SetReportData(ReportData.Default()) .Build(); return(new { cmd, username, expected }); }); var context = await Endpoint.Act <CreateUnitPlanCommandHandler>(AssemblySetupFixture.EndpointTestContainer, (h, ctx) => { ctx.SetUsernameOnHeader(testParams.username); return(h.Handle(testParams.cmd, ctx)); }); var evt = context.ExpectPublish <IUnitPlanCreated>(); Endpoint.AssertOnSqlSessionThat(AssemblySetupFixture.EndpointTestContainer, s => { var report = s.Query <UnitReport>().Single(); report.Should().NotBeNull(); report.Should().BeEquivalentTo(testParams.expected, e => e.Excluding(p => p.Id)); report.ReportingPeriod.Should().BeEquivalentTo(testParams.expected.ReportingPeriod); EntityReference reportRef = report; var expectedEvt = Test.CreateInstance <IUnitPlanCreated>(e => { e.Organization = testParams.expected.Organization; e.Username = testParams.username; e.UnitReport = reportRef; }); evt.Should().BeEquivalentTo(expectedEvt, e => e.Excluding(p => p.SerializedData)); evt.SerializedData.Should().NotBe(null); }); }
public void CreateNewUnitPlan_SavesCorrectlyWhenLastYearSubmitted(ReportingFrequency reportingFrequency) { DateTimeDbTestExtensions.SetUtcNowToRandomDate(); var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { var organizationType = OrganizationType.Unit; var description = DataProvider.Get <string>(); var year = 2019; var reportingTerm = ReportingTerm.One; var organization = new TestObjectBuilder <Organization>() .SetArgument(o => o.OrganizationType, organizationType) .SetArgument(o => o.ReportingFrequency, reportingFrequency) .BuildAndPersist(s); OrganizationReference organizationRef = organization; var reportingPeriod = new ReportingPeriod(reportingFrequency, reportingTerm, year); var expected = new UnitReportBuilder() .SetDescription(description) .SetOrganization(organization) .SetReportingPeriod(new ReportingPeriod(reportingFrequency, reportingTerm, year)) .SetReportData(ReportData.Default()) .Build(); return(new { description, organizationRef, reportingPeriod, expected }); }); var result = Endpoint.Act(AssemblySetupFixture.EndpointTestContainer, c => { var unitReport = c.GetInstance <UnitReportFactory>() .CreateNewUnitPlan(testParams.description, testParams.organizationRef, testParams.reportingPeriod.ReportingTerm, testParams.reportingPeriod.Year, reportingFrequency); return(new { unitReport }); }); result.unitReport.Should().NotBeNull(); result.unitReport.Should().BeEquivalentTo(testParams.expected, e => e.Excluding(p => p.Id)); }
protected ReportData GetReportDataAi(Organization organization, ReportingPeriod reportingPeriod) { var lastSubmittedUnitReport = _unitReportService.GetSubmittedUnitReportOfPreviousTerm(organization.Id, reportingPeriod); var reportData = ReportData.Default(); if (lastSubmittedUnitReport != null) { var unitMemberMemberData = CreateMemberData(lastSubmittedUnitReport.MemberMemberData); var unitAssociateMemberData = CreateMemberData(lastSubmittedUnitReport.AssociateMemberData); var unitPreliminaryMemberData = CreateMemberData(lastSubmittedUnitReport.PreliminaryMemberData); var unitSupporterMemberData = CreateMemberData(lastSubmittedUnitReport.SupporterMemberData); var unitWorkerMeetingData = CreateMeetingProgramData(lastSubmittedUnitReport.WorkerMeetingProgramData); var unitDawahMeetingData = CreateMeetingProgramData(lastSubmittedUnitReport.DawahMeetingProgramData); var unitStateLeaderMeetingData = CreateMeetingProgramData(lastSubmittedUnitReport.StateLeaderMeetingProgramData); var unitStateOutingMeetingData = CreateMeetingProgramData(lastSubmittedUnitReport.StateOutingMeetingProgramData); var unitIftarMeetingData = CreateMeetingProgramData(lastSubmittedUnitReport.IftarMeetingProgramData); var unitLearningMeetingData = CreateMeetingProgramData(lastSubmittedUnitReport.LearningMeetingProgramData); var unitSocialDawahMeetingData = CreateMeetingProgramData(lastSubmittedUnitReport.SocialDawahMeetingProgramData); var unitDawahGroupMeetingData = CreateMeetingProgramData(lastSubmittedUnitReport.DawahGroupMeetingProgramData); var unitNextGMeetingData = CreateMeetingProgramData(lastSubmittedUnitReport.NextGMeetingProgramData); var baitulMalFinanceData = CreateFinanceData(lastSubmittedUnitReport.BaitulMalFinanceData); var aDayMasjidProjectFinanceData = CreateFinanceData(lastSubmittedUnitReport.ADayMasjidProjectFinanceData); var masjidTableBankFinanceData = CreateFinanceData(lastSubmittedUnitReport.MasjidTableBankFinanceData); reportData = new ReportData(unitMemberMemberData, unitAssociateMemberData, unitPreliminaryMemberData, unitSupporterMemberData, unitWorkerMeetingData, unitDawahMeetingData, unitStateLeaderMeetingData, unitStateOutingMeetingData, unitIftarMeetingData, unitLearningMeetingData, unitSocialDawahMeetingData, unitDawahGroupMeetingData, unitNextGMeetingData, baitulMalFinanceData: baitulMalFinanceData, aDayMasjidProjectFinanceData: aDayMasjidProjectFinanceData, masjidTableBankFinanceData: masjidTableBankFinanceData); } return(reportData); }
private UnitReport CreateNew(string description, OrganizationReference organizationRef, ReportingTerm reportingTerm, int year, ReportingFrequency reportingFrequency, bool isAi = false) { var organization = _session.Query <Organization>().Single(o => o.Id == organizationRef.Id); if (organization.OrganizationType != OrganizationType.Unit) { throw new ArgumentException("Invalid Organization Type"); } if (reportingFrequency != organization.ReportingFrequency) { throw new ArgumentException("Invalid Reporting Frequency"); } var reportingPeriod = new ReportingPeriod(reportingFrequency, reportingTerm, year); var reportData = isAi ? GetReportDataAi(organization, reportingPeriod) : ReportData.Default(); var report = new UnitReport(description, organization, reportingPeriod, reportData); _session.Save(report); return(report); }