public void GetUnitReportViewModel_Should_Return_Result() { DateTimeDbTestExtensions.SetUtcNowToRandomDate(); var username = DataProvider.Get <string>(); var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { var unitReport = new UnitReportBuilder() .Build(); unitReport.MarkStatusAsSubmitted(); s.Save(unitReport); var submittedUnitReportViewModel = TestHelper.ConvertToUnitReportViewModel(unitReport); TestHelper.SetUserAccessAllOrganizationsClaim(username); return(submittedUnitReportViewModel); }); var result = NsbWebTest.Act(AssemblySetupFixture.WebTestContainer, c => c.GetInstance <UnitReportQueryService>() .GetUnitReportViewModel(testParams.Id)); result.Should().NotBeNull(); result.Should().BeEquivalentTo(testParams); }
public async Task Handle_RaisesException_WhenOrganizationUserExists() { var username = DataProvider.Get <string>(); var role = DataProvider.Get <string>(); DateTimeDbTestExtensions.SetUtcNowToRandomDate(); var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { var org = new OrganizationBuilder().BuildAndPersist(s); new TestObjectBuilder <OrganizationUser>() .SetArgument(o => o.Username, username) .SetArgument(o => o.Role, role) .SetArgument(o => o.Organization, org) .BuildAndPersist(s); return(new { Cmd = new CreateOrganizationUserCommand(username, role, org) }); }); await Endpoint.ActRaisesException <CreateOrganizationUserCommandHandler>(AssemblySetupFixture.EndpointTestContainer, (h, ctx) => h.Handle(testParams.Cmd, ctx)); Endpoint.AssertOnSqlSessionThat(AssemblySetupFixture.EndpointTestContainer, s => { var organizationUser = s.Query <OrganizationUser>().Single(); organizationUser.Should().NotBeNull(); }); }
public void GetUnitPlanViewModel_Should_Return_Result() { DateTimeDbTestExtensions.SetUtcNowToRandomDate(); var username = DataProvider.Get <string>(); var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { var unitReport = new UnitReportBuilder() .BuildAndPersist(s); var unitReportViewModel = TestHelper.ConvertToUnitPlanViewModel(unitReport); TestHelper.SetUserAccessAllOrganizationsClaim(username); return(unitReportViewModel); }); var result = NsbWebTest.Act(AssemblySetupFixture.WebTestContainer, c => c.GetInstance <IUnitReportQueryService>() .GetUnitPlanViewModel(testParams.Id)); result.Should().NotBeNull(); //-- after finding the issue it will be removed result.BookLibraryStockPlanData = ValueObjects.LibraryStockData.Default(); result.VhsLibraryStockPlanData = ValueObjects.LibraryStockData.Default(); result.OtherLibraryStockPlanData = ValueObjects.LibraryStockData.Default(); //--------- result.Should().BeEquivalentTo(testParams); }
public async Task Handle_RaisesException_WhenInvalidOrganization() { var username = DataProvider.Get <string>(); var role = DataProvider.Get <string>(); DateTimeDbTestExtensions.SetUtcNowToRandomDate(); var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { var org = new OrganizationBuilder().Build(); //not persisted return(new { Cmd = new CreateOrganizationUserCommand(username, role, org) }); }); await Endpoint.ActRaisesException <CreateOrganizationUserCommandHandler>(AssemblySetupFixture.EndpointTestContainer, (h, ctx) => h.Handle(testParams.Cmd, ctx)); Endpoint.AssertOnSqlSessionThat(AssemblySetupFixture.EndpointTestContainer, s => { var organizationUser = s.Query <OrganizationUser>().SingleOrDefault(); organizationUser.Should().BeNull(); }); }
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)); }
public async Task Handle_DeletesReport(OrganizationType organizationType, 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 OrganizationBuilder() .SetOrganizationType(organizationType) .SetReportingFreQuency(reportingFrequency) .BuildAndPersist(s); Report report = new ReportBuilder() .SetOrganization(organization) .SetReportingPeriod(new ReportingPeriod(reportingFrequency, reportingTerm, year)) .BuildAndPersist(s); EntityReference reportRef = report; var expectedEvt = Test.CreateInstance <IReportDeleted>(e => { e.Organization = organization; e.Username = username; e.Report = reportRef; }); return(new { Cmd = new DeleteReportCommand(report.Id), username, expectedEvt }); }); var context = await Endpoint.Act <DeleteReportCommandHandler>(AssemblySetupFixture.EndpointTestContainer, (h, ctx) => { ctx.SetUsernameOnHeader(testParams.username); return(h.Handle(testParams.Cmd, ctx)); }); var evt = context.ExpectPublish <IReportDeleted>(); Endpoint.AssertOnSqlSessionThat(AssemblySetupFixture.EndpointTestContainer, s => { var report = s.Get <Report>(testParams.Cmd.ReportId); report.Should().BeNull(); evt.Should().BeEquivalentTo(testParams.expectedEvt, e => e.Excluding(p => p.SerializedData)); evt.SerializedData.Should().NotBe(null); }); }
public async Task Handle_DoNotSavesCentralReport_WhenDuplicate(ReportingFrequency reportingFrequency) { DateTimeDbTestExtensions.SetUtcNowToRandomDate(); var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { var username = DataProvider.Get <string>(); var description = DataProvider.Get <string>(); var year = 2019; var reportingTerm = ReportingTerm.One; var organization = new TestObjectBuilder <Organization>() .SetArgument(o => o.OrganizationType, OrganizationType.Central) .SetArgument(o => o.ReportingFrequency, reportingFrequency) .BuildAndPersist(s); var copyFrom = new CentralReportBuilder() .SetDescription(description) .SetOrganization(organization) .SetReportingPeriod(new ReportingPeriod(reportingFrequency, reportingTerm, year - 1)) .BuildAndPersist(s); var duplicate = new CentralReportBuilder() .SetDescription(description) .SetOrganization(organization) .SetReportingPeriod(new ReportingPeriod(reportingFrequency, reportingTerm, year)) .BuildAndPersist(s); return(new { Cmd = new CopyCentralPlanCommand(copyFrom.Id, organization, year, reportingTerm, reportingFrequency), username, duplicate }); }); var context = await Endpoint.Act <CopyCentralPlanCommandHandler>(AssemblySetupFixture.EndpointTestContainer, (h, ctx) => { ctx.SetUsernameOnHeader(testParams.username); return(h.Handle(testParams.Cmd, ctx)); }); var evt = context.ExpectPublish <ICentralPlanCopyFailed>(); Endpoint.AssertOnSqlSessionThat(AssemblySetupFixture.EndpointTestContainer, s => { var report = s.Query <CentralReport>().OrderByDescending(o => o.Id).First(); report.Should().NotBeNull(); report.Should().BeEquivalentTo(testParams.duplicate); evt.Errors[0].Should().Contain(testParams.duplicate.Description); }); }
public async Task Handle_SavesRecord(OrganizationType organizationType, ReportingFrequency reportingFrequency) { var username = DataProvider.Get <string>(); var description = DataProvider.Get <string>(); var details = DataProvider.Get <string>(); var parent = DataProvider.Get <EntityReference>(); DateTimeDbTestExtensions.SetUtcNowToRandomDate(); var expected = new OrganizationBuilder() .SetDescription(description) .SetDetails(details) .SetParent(parent) .SetOrganizationType(organizationType) .SetReportingFreQuency(reportingFrequency) .Build(); var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => new { Cmd = new CreateOrganizationCommand(description, details, organizationType, reportingFrequency, parent), username, expected }); var context = await Endpoint.Act <CreateOrganizationCommandHandler>( AssemblySetupFixture.EndpointTestContainer, (h, ctx) => { ctx.SetUsernameOnHeader(testParams.username); return(h.Handle(testParams.Cmd, ctx)); }); var evt = context.ExpectPublish <IOrganizationCreated>(); Endpoint.AssertOnSqlSessionThat(AssemblySetupFixture.EndpointTestContainer, s => { var org = s.Query <Organization>().Single(); org.Should().NotBeNull(); org.Should().BeEquivalentTo(testParams.expected, e => e.Excluding(p => p.Id)); OrganizationReference orgRef = org; var expectedEvt = Test.CreateInstance <IOrganizationCreated>(e => { e.Organization = orgRef; e.Username = testParams.username; }); evt.Should().BeEquivalentTo(expectedEvt, e => e.Excluding(p => p.SerializedData)); evt.SerializedData.Should().NotBe(null); }); }
public async Task Handle_RaisesFailedEvent_WhenParentIsSameOrganization(OrganizationType newOrganizationType, ReportingFrequency newReportingFrequency) { var now = DateTimeDbTestExtensions.SetUtcNowToRandomDate(); var username = DataProvider.Get <string>(); var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { var org = new OrganizationBuilder().BuildAndPersist(s); EntityReference parent = org; var newDescription = DataProvider.Get <string>(); var newDetails = DataProvider.Get <string>(); var expectedEvt = Test.CreateInstance <IOrganizationUpdateFailed>(e => { e.Errors = new string[] { $"unable to add same organization as Parent organization" }; }); return(new { username, expectedEvt, Cmd = new UpdateOrganizationCommand(org.Id, newDescription, newDetails, newOrganizationType, newReportingFrequency, parent), org }); }); var context = await Endpoint.Act <UpdateOrganizationCommandHandler>(AssemblySetupFixture.EndpointTestContainer, (h, ctx) => { ctx.SetUsernameOnHeader(testParams.username); return(h.Handle(testParams.Cmd, ctx)); }); var evt = context.ExpectPublish <IOrganizationUpdateFailed>(); Endpoint.AssertOnSqlSessionThat(AssemblySetupFixture.EndpointTestContainer, s => { var organization = s.Query <Organization>().SingleOrDefault(); organization.Should().NotBeNull(); organization.Should().BeEquivalentTo(testParams.org); }); evt.Should().BeEquivalentTo(testParams.expectedEvt); }
public void PromotePlanToUnitReport_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); var period1 = new ReportingPeriod(reportingFrequency, reportingTerm, year); var period1ReportingData = new ReportDataBuilder().Build(); var period1UnitReport = new UnitReport(description, organization, period1, period1ReportingData); s.Save(period1UnitReport); return(new { period1UnitReport, }); }); var result = Endpoint.Act(AssemblySetupFixture.EndpointTestContainer, c => { var unitReport = c.GetInstance <UnitReportService>() .PromotePlanToUnitReport(testParams.period1UnitReport.Id); return(new { unitReport }); }); result.unitReport.Should().NotBeNull(); result.unitReport.Should().BeEquivalentTo(testParams.period1UnitReport, e => e.Excluding(p => p.ReportStatus)); result.unitReport.ReportStatus.Should().Be(ReportStatus.PlanPromoted); }
public void GetManagedOrganizationsAsExpected() { DateTimeDbTestExtensions.SetUtcNowToRandomDate(); var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { var organizations = IntegrationTestOrganizationHelper.SetupOrzanizations(); var central = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.Central).Value; var nswState = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.NswState).Value; var victoriaState = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.VictoriaState).Value; var footscray = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.Footscray).Value; var truganinaNorth = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.TruganinaNorth).Value; return(new { central, victoriaState, expectedCentralManagedOrganizations = new List <Organization> { victoriaState, nswState }, expectedVictoriaStateManagedOrganizations = new List <Organization> { footscray, truganinaNorth }, }); }); var result = Endpoint.Act(AssemblySetupFixture.EndpointTestContainer, c => { var centralManagedOrganizations = c.GetInstance <IOrganizationService>().GetManagedOrganizations(testParams.central.Id); var victoriaStateManagedOrganizations = c.GetInstance <IOrganizationService>().GetManagedOrganizations(testParams.victoriaState.Id); return(new { centralManagedOrganizations, victoriaStateManagedOrganizations }); }); result.centralManagedOrganizations.Should() .BeEquivalentTo(testParams.expectedCentralManagedOrganizations, x => x.WithStrictOrderingFor(o => o)); result.victoriaStateManagedOrganizations.Should().BeEquivalentTo(testParams.expectedVictoriaStateManagedOrganizations); }
public async Task Handle_PublishesError_When_OnlyOne_ReportIds() { DateTimeDbTestExtensions.SetUtcNowToRandomDate(); var testParams = new { username = DataProvider.Get <string>(), Cmd = new ConsolidateReportCommand(new[] { 1 }), Error = $"Nothing to consolidate. Only one report found" }; var context = await Endpoint.Act <ConsolidateReportCommandHandler>(AssemblySetupFixture.EndpointTestContainer, (h, ctx) => { ctx.SetUsernameOnHeader(testParams.username); return(h.Handle(testParams.Cmd, ctx)); }); var evt = context.ExpectPublish <IConsolidateReportFailed>(); evt.Errors[0].Should().Contain(testParams.Error); }
public async Task Handle_SavesRecord() { var username = DataProvider.Get <string>(); var role = DataProvider.Get <string>(); var now = DateTimeDbTestExtensions.SetUtcNowToRandomDate(); var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { var org = new OrganizationBuilder().BuildAndPersist(s); return(new { username, Cmd = new CreateOrganizationUserCommand(username, role, org) }); }); await Endpoint.Act <CreateOrganizationUserCommandHandler>( AssemblySetupFixture.EndpointTestContainer, (h, ctx) => { ctx.SetUsernameOnHeader(testParams.username); return(h.Handle(testParams.Cmd, ctx)); }); Endpoint.AssertOnSqlSessionThat(AssemblySetupFixture.EndpointTestContainer, s => { var organizationUser = s.Query <OrganizationUser>().Single(); organizationUser.Should().NotBeNull(); organizationUser.Username.Should().Be(testParams.Cmd.Username); organizationUser.Role.Should().Be(testParams.Cmd.Role); organizationUser.Organization.Should().Be(testParams.Cmd.Organization); organizationUser.Timestamp.Should().Be(now); organizationUser.IsDeleted.Should().Be(false); }); }
public async Task Handle_UnitPlanCreated(ReportingFrequency reportingFrequency) { var now = DateTimeDbTestExtensions.SetUtcNowToRandomDate(); var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { var username = DataProvider.Get <string>(); var organization = new TestObjectBuilder <Organization>() .SetArgument(o => o.OrganizationType, OrganizationType.Unit) .SetArgument(o => o.ReportingFrequency, reportingFrequency) .BuildAndPersist(s); var evt = Test.CreateInstance <IUnitPlanCreated>(x => { x.Username = username; x.Organization = organization; x.UnitReport = DataProvider.Get <EntityReference>(); x.SerializedData = DataProvider.Get <string>(); }); return(new { evt }); }); await Endpoint.Act <LogWhenReportEventReceived>(AssemblySetupFixture.EndpointTestContainer, (h, ctx) => h.Handle(testParams.evt, ctx)); Endpoint.AssertOnSqlSessionThat(AssemblySetupFixture.EndpointTestContainer, s => { var reportEventLog = s.Query <ReportEventLog>().Single(); reportEventLog.Should().NotBeNull(); reportEventLog.OrganizationId.Should().Be(testParams.evt.Organization.Id); reportEventLog.Timestamp.Should().Be(now); }); }
public async Task Handle_DeletesOrganizationUser() { var deletedByusername = DataProvider.Get <string>(); var username = DataProvider.Get <string>(); var role = DataProvider.Get <string>(); DateTimeDbTestExtensions.SetUtcNowToRandomDate(); var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { var org = new OrganizationBuilder().BuildAndPersist(s); var organizationUser = new TestObjectBuilder <OrganizationUser>() .SetArgument(o => o.Username, username) .SetArgument(o => o.Role, role) .SetArgument(o => o.Organization, org) .BuildAndPersist(s); return(new { deletedByusername, cmd = new DeleteOrganizationUserCommand(organizationUser.Id) }); }); await Endpoint.Act <DeleteOrganizationUserCommandHandler>(AssemblySetupFixture.EndpointTestContainer, (h, ctx) => { ctx.SetUsernameOnHeader(testParams.deletedByusername); return(h.Handle(testParams.cmd, ctx)); }); Endpoint.AssertOnSqlSessionThat(AssemblySetupFixture.EndpointTestContainer, s => { var report = s.Get <OrganizationUser>(testParams.cmd.OrganizationUserId); report.Should().BeNull(); }); }
public void GetCentralPlanViewModel_Should_Return_Result() { DateTimeDbTestExtensions.SetUtcNowToRandomDate(); var username = DataProvider.Get <string>(); var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { var centralReport = new CentralReportBuilder() .BuildAndPersist(s); var centralPlanViewModel = TestHelper.ConvertToCentralPlanViewModel(centralReport); TestHelper.SetUserAccessAllOrganizationsClaim(username); return(centralPlanViewModel); }); var result = NsbWebTest.Act(AssemblySetupFixture.WebTestContainer, c => c.GetInstance <ICentralReportQueryService>() .GetCentralPlanViewModel(testParams.Id)); result.Should().NotBeNull(); result.Should().BeEquivalentTo(testParams); }
public void CreateNewPlan_For_State_Unit_SavesMaterialDataCorrectly( bool thisPeriodSubmitted, bool lastPeriod1Submitted, bool lastPeriod2Submitted ) { DateTimeDbTestExtensions.SetUtcNowToRandomDate(); var reportingTerms = ReportingPeriod.GetReportingTerms(reportingFrequency); if (reportingTerms.All(o => o != reportingTerm)) { return; } var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { var organizations = IntegrationTestOrganizationHelper.SetupOrzanizations( stateReportingFrequency: reportingFrequency, zoneReportingFrequency: ReportingFrequency.Monthly); var nswState = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.NswState).Value; var laPerouse = new OrganizationBuilder() .SetDescription("La perouse") .SetOrganizationType(OrganizationType.Unit) .SetReportingFreQuency(ReportingFrequency.Monthly) .SetParent(nswState) .BuildAndPersist(s); var lalorPark = new OrganizationBuilder() .SetDescription("Lalor park") .SetOrganizationType(OrganizationType.Unit) .SetReportingFreQuency(ReportingFrequency.Monthly) .SetParent(nswState) .BuildAndPersist(s); var description = DataProvider.Get <string>(); var year = 2019; OrganizationReference organizationRef = nswState; var reportingPeriod = new ReportingPeriod(reportingFrequency, reportingTerm, year); var expected = new StateReportBuilder() .SetDescription(description) .SetOrganization(organizationRef) .SetReportingPeriod(new ReportingPeriod(reportingFrequency, reportingPeriod.ReportingTerm, reportingPeriod.Year)) .Build(); var lastPeriod1 = reportingPeriod.GetReportingPeriodOfPreviousTerm(); var lastPeriod2 = lastPeriod1.GetReportingPeriodOfPreviousTerm(); var laPerouseThisPeriodUnitReport = IntegrationTestStateReportHelper.BuildAndPersistUnitReport(thisPeriodSubmitted, laPerouse, reportingPeriod, s); var laPerouseLastPeriod1UnitReport = IntegrationTestStateReportHelper.BuildAndPersistUnitReport(lastPeriod1Submitted, laPerouse, lastPeriod1, s); var laPerouseLastPeriod2UnitReport = IntegrationTestStateReportHelper.BuildAndPersistUnitReport(lastPeriod2Submitted, laPerouse, lastPeriod2, s); var lalorParkThisPeriodUnitReport = IntegrationTestStateReportHelper.BuildAndPersistUnitReport(thisPeriodSubmitted, lalorPark, reportingPeriod, s); var lalorParkLastPeriod1UnitReport = IntegrationTestStateReportHelper.BuildAndPersistUnitReport(lastPeriod1Submitted, lalorPark, lastPeriod1, s); var lalorParkLastPeriod2UnitReport = IntegrationTestStateReportHelper.BuildAndPersistUnitReport(lastPeriod2Submitted, lalorPark, lastPeriod2, s); var allUnitReports = new[] { laPerouseThisPeriodUnitReport, laPerouseLastPeriod1UnitReport, laPerouseLastPeriod2UnitReport, lalorParkThisPeriodUnitReport, lalorParkLastPeriod1UnitReport, lalorParkLastPeriod2UnitReport, }; var submittedReports = IntegrationTestStateReportHelper.GetSubmittedReports(allUnitReports, reportingPeriod); var expectedBookSaleMaterialData = IntegrationTestStateReportHelper.GetExpectedMaterialData(submittedReports, nameof(StateReport.BookSaleMaterialData)); var expectedBookSaleMaterialGeneratedData = expectedBookSaleMaterialData; var expectedBookDistributionMaterialData = IntegrationTestStateReportHelper.GetExpectedMaterialData(submittedReports, nameof(StateReport.BookDistributionMaterialData)); var expectedBookDistributionMaterialGeneratedData = expectedBookDistributionMaterialData; var expectedVhsSaleMaterialData = IntegrationTestStateReportHelper.GetExpectedMaterialData(submittedReports, nameof(StateReport.VhsSaleMaterialData)); var expectedVhsSaleMaterialGeneratedData = expectedVhsSaleMaterialData; var expectedVhsDistributionMaterialData = IntegrationTestStateReportHelper.GetExpectedMaterialData(submittedReports, nameof(StateReport.VhsDistributionMaterialData)); var expectedVhsDistributionMaterialGeneratedData = expectedVhsDistributionMaterialData; var expectedEmailDistributionMaterialData = IntegrationTestStateReportHelper.GetExpectedMaterialData(submittedReports, nameof(StateReport.EmailDistributionMaterialData)); var expectedEmailDistributionMaterialGeneratedData = expectedEmailDistributionMaterialData; var expectedIpdcLeafletDistributionMaterialData = IntegrationTestStateReportHelper.GetExpectedMaterialData(submittedReports, nameof(StateReport.IpdcLeafletDistributionMaterialData)); var expectedIpdcLeafletDistributionMaterialGeneratedData = expectedIpdcLeafletDistributionMaterialData; return(new { description, reportingPeriod, organizationRef, expected, expectedBookSaleMaterialData, expectedBookSaleMaterialGeneratedData, expectedBookDistributionMaterialData, expectedBookDistributionMaterialGeneratedData, expectedVhsSaleMaterialData, expectedVhsSaleMaterialGeneratedData, expectedVhsDistributionMaterialData, expectedVhsDistributionMaterialGeneratedData, expectedEmailDistributionMaterialData, expectedEmailDistributionMaterialGeneratedData, expectedIpdcLeafletDistributionMaterialData, expectedIpdcLeafletDistributionMaterialGeneratedData }); }); var result = Endpoint.Act(AssemblySetupFixture.EndpointTestContainer, c => { var stateReport = c.GetInstance <IStateReportFactory>() .CreateNewStatePlan(testParams.description, testParams.organizationRef, testParams.reportingPeriod.ReportingTerm, testParams.reportingPeriod.Year, reportingFrequency); return(new { stateReport }); }); result.stateReport.Should().NotBeNull(); result.stateReport.BookSaleMaterialData.Should().BeEquivalentTo(testParams.expectedBookSaleMaterialData); result.stateReport.BookSaleMaterialGeneratedData.Should().BeEquivalentTo(testParams.expectedBookSaleMaterialGeneratedData); result.stateReport.BookDistributionMaterialData.Should().BeEquivalentTo(testParams.expectedBookDistributionMaterialData); result.stateReport.BookDistributionMaterialGeneratedData.Should().BeEquivalentTo(testParams.expectedBookDistributionMaterialGeneratedData); result.stateReport.VhsSaleMaterialData.Should().BeEquivalentTo(testParams.expectedVhsSaleMaterialData); result.stateReport.VhsSaleMaterialGeneratedData.Should().BeEquivalentTo(testParams.expectedVhsSaleMaterialGeneratedData); result.stateReport.VhsDistributionMaterialData.Should().BeEquivalentTo(testParams.expectedVhsDistributionMaterialData); result.stateReport.VhsDistributionMaterialGeneratedData.Should().BeEquivalentTo(testParams.expectedVhsDistributionMaterialGeneratedData); result.stateReport.EmailDistributionMaterialData.Should().BeEquivalentTo(testParams.expectedEmailDistributionMaterialData); result.stateReport.EmailDistributionMaterialGeneratedData.Should().BeEquivalentTo(testParams.expectedEmailDistributionMaterialGeneratedData); result.stateReport.IpdcLeafletDistributionMaterialData.Should().BeEquivalentTo(testParams.expectedIpdcLeafletDistributionMaterialData); result.stateReport.IpdcLeafletDistributionMaterialGeneratedData.Should().BeEquivalentTo(testParams.expectedIpdcLeafletDistributionMaterialGeneratedData); }
public void PromotePlanToUnitReportAi_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); var period1 = new ReportingPeriod(reportingFrequency, reportingTerm, year); var period1ReportingData = new ReportDataBuilder().Build(); var period1UnitReport = new UnitReport(description, organization, period1, period1ReportingData); s.Save(period1UnitReport); var lastPeriod2 = period1.GetReportingPeriodOfPreviousTerm(); var lastPeriod2ReportingData = new ReportDataBuilder().Build(); var lastPeriod2UnitReport = new UnitReport(description, organization, lastPeriod2, lastPeriod2ReportingData); lastPeriod2UnitReport.MarkStatusAsSubmitted(); s.Save(lastPeriod2UnitReport); return(new { period1UnitReport, lastPeriod2UnitReport }); }); var result = Endpoint.Act(AssemblySetupFixture.EndpointTestContainer, c => { var unitReport = c.GetInstance <UnitReportService>() .PromotePlanToUnitReportAi(testParams.period1UnitReport.Id); return(new { unitReport }); }); result.unitReport.Should().NotBeNull(); result.unitReport.Should().BeEquivalentTo(testParams.period1UnitReport, e => e.Excluding(p => p.ReportStatus) .Excluding(p => p.AssociateMemberData) .Excluding(p => p.PreliminaryMemberData) .Excluding(p => p.WorkerMeetingProgramData)); result.unitReport.ReportStatus.Should().Be(ReportStatus.PlanPromoted); result.unitReport.AssociateMemberData.UpgradeTarget.Should() .Be(testParams.period1UnitReport.AssociateMemberData.UpgradeTarget); result.unitReport.AssociateMemberData.LastPeriod.Should() .Be(testParams.period1UnitReport.AssociateMemberData.LastPeriod); result.unitReport.AssociateMemberData.ThisPeriod.Should() .Be(testParams.lastPeriod2UnitReport.AssociateMemberData.ThisPeriod); result.unitReport.PreliminaryMemberData.UpgradeTarget.Should() .Be(testParams.period1UnitReport.PreliminaryMemberData.UpgradeTarget); result.unitReport.PreliminaryMemberData.LastPeriod.Should() .Be(testParams.period1UnitReport.PreliminaryMemberData.LastPeriod); result.unitReport.PreliminaryMemberData.ThisPeriod.Should() .Be(testParams.lastPeriod2UnitReport.PreliminaryMemberData.ThisPeriod); //Worker meeting values should be initial values. Should not set last period values (as that will be irrelevant) result.unitReport.WorkerMeetingProgramData.Target.Should() .Be(testParams.period1UnitReport.WorkerMeetingProgramData.Target); result.unitReport.WorkerMeetingProgramData.Actual.Should() .Be(testParams.period1UnitReport.WorkerMeetingProgramData.Actual); result.unitReport.WorkerMeetingProgramData.AverageAttendance.Should() .Be(testParams.period1UnitReport.WorkerMeetingProgramData.AverageAttendance); }
public void CreateNewPlan_For_State_Unit_SavesMemberDataCorrectly( bool thisPeriodSubmitted, bool lastPeriod1Submitted, bool lastPeriod2Submitted ) { DateTimeDbTestExtensions.SetUtcNowToRandomDate(); var reportingTerms = ReportingPeriod.GetReportingTerms(reportingFrequency); if (reportingTerms.All(o => o != reportingTerm)) { return; } var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { var organizations = IntegrationTestOrganizationHelper.SetupOrzanizations( stateReportingFrequency: reportingFrequency, zoneReportingFrequency: ReportingFrequency.Monthly); var nswState = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.NswState).Value; var laPerouse = new OrganizationBuilder() .SetDescription("La perouse") .SetOrganizationType(OrganizationType.Unit) .SetReportingFreQuency(ReportingFrequency.Monthly) .SetParent(nswState) .BuildAndPersist(s); var lalorPark = new OrganizationBuilder() .SetDescription("Lalor park") .SetOrganizationType(OrganizationType.Unit) .SetReportingFreQuency(ReportingFrequency.Monthly) .SetParent(nswState) .BuildAndPersist(s); var description = DataProvider.Get <string>(); var year = 2019; OrganizationReference organizationRef = nswState; var reportingPeriod = new ReportingPeriod(reportingFrequency, reportingTerm, year); var expected = new StateReportBuilder() .SetDescription(description) .SetOrganization(organizationRef) .SetReportingPeriod(new ReportingPeriod(reportingFrequency, reportingPeriod.ReportingTerm, reportingPeriod.Year)) .Build(); var lastPeriod1 = reportingPeriod.GetReportingPeriodOfPreviousTerm(); var lastPeriod2 = lastPeriod1.GetReportingPeriodOfPreviousTerm(); var laPerouseThisPeriodUnitReport = IntegrationTestStateReportHelper.BuildAndPersistUnitReport(thisPeriodSubmitted, laPerouse, reportingPeriod, s); var laPerouseLastPeriod1UnitReport = IntegrationTestStateReportHelper.BuildAndPersistUnitReport(lastPeriod1Submitted, laPerouse, lastPeriod1, s); var laPerouseLastPeriod2UnitReport = IntegrationTestStateReportHelper.BuildAndPersistUnitReport(lastPeriod2Submitted, laPerouse, lastPeriod2, s); var lalorParkThisPeriodUnitReport = IntegrationTestStateReportHelper.BuildAndPersistUnitReport(thisPeriodSubmitted, lalorPark, reportingPeriod, s); var lalorParkLastPeriod1UnitReport = IntegrationTestStateReportHelper.BuildAndPersistUnitReport(lastPeriod1Submitted, lalorPark, lastPeriod1, s); var lalorParkLastPeriod2UnitReport = IntegrationTestStateReportHelper.BuildAndPersistUnitReport(lastPeriod2Submitted, lalorPark, lastPeriod2, s); var laPerouseUnitReports = new[] { laPerouseThisPeriodUnitReport, laPerouseLastPeriod1UnitReport, laPerouseLastPeriod2UnitReport, }; var lalorParkeUnitReports = new[] { lalorParkThisPeriodUnitReport, lalorParkLastPeriod1UnitReport, lalorParkLastPeriod2UnitReport, }; var lastSubmittedLapeRouseReport = IntegrationTestStateReportHelper.GetLastSubmittedReport(laPerouseUnitReports, reportingPeriod); var lastSubmittedLalorParkReport = IntegrationTestStateReportHelper.GetLastSubmittedReport(lalorParkeUnitReports, reportingPeriod); var submittedReports = new[] { lastSubmittedLapeRouseReport, lastSubmittedLalorParkReport }.Where(o => o != null).ToArray(); var expectedMemberMemberData = IntegrationTestStateReportHelper.GetExpectedMemberData(submittedReports, nameof(StateReport.MemberMemberData)); var expectedMemberMemberGeneratedData = expectedMemberMemberData; var expectedAssociateMemberData = IntegrationTestStateReportHelper.GetExpectedMemberData(submittedReports, nameof(StateReport.AssociateMemberData)); var expectedAssociateMemberGeneratedData = expectedAssociateMemberData; var expectedPreliminaryMemberData = IntegrationTestStateReportHelper.GetExpectedMemberData(submittedReports, nameof(StateReport.PreliminaryMemberData)); var expectedPreliminaryMemberGeneratedData = expectedPreliminaryMemberData; var expectedSupporterMemberData = IntegrationTestStateReportHelper.GetExpectedMemberData(submittedReports, nameof(StateReport.SupporterMemberData)); var expectedSupporterMemberGeneratedData = expectedSupporterMemberData; return(new { description, reportingPeriod, organizationRef, expected, expectedMemberMemberData, expectedMemberMemberGeneratedData, expectedAssociateMemberData, expectedAssociateMemberGeneratedData, expectedPreliminaryMemberData, expectedPreliminaryMemberGeneratedData, expectedSupporterMemberData, expectedSupporterMemberGeneratedData, }); }); var result = Endpoint.Act(AssemblySetupFixture.EndpointTestContainer, c => { var stateReport = c.GetInstance <IStateReportFactory>() .CreateNewStatePlan(testParams.description, testParams.organizationRef, testParams.reportingPeriod.ReportingTerm, testParams.reportingPeriod.Year, reportingFrequency); return(new { stateReport }); }); result.stateReport.Should().NotBeNull(); //no need to repeat this section for the other field types result.stateReport.Should().BeEquivalentTo(testParams.expected, e => e.Excluding(p => p.Id) .Excluding(p => p.MemberMemberData) .Excluding(p => p.MemberMemberGeneratedData) .Excluding(p => p.AssociateMemberData) .Excluding(p => p.AssociateMemberGeneratedData) .Excluding(p => p.PreliminaryMemberData) .Excluding(p => p.PreliminaryMemberGeneratedData) .Excluding(p => p.SupporterMemberData) .Excluding(p => p.SupporterMemberGeneratedData) .Excluding(p => p.WorkerMeetingProgramData) .Excluding(p => p.WorkerMeetingProgramGeneratedData) .Excluding(p => p.DawahMeetingProgramData) .Excluding(p => p.DawahMeetingProgramGeneratedData) .Excluding(p => p.StateLeaderMeetingProgramData) .Excluding(p => p.StateLeaderMeetingProgramGeneratedData) .Excluding(p => p.StateOutingMeetingProgramData) .Excluding(p => p.StateOutingMeetingProgramGeneratedData) .Excluding(p => p.IftarMeetingProgramData) .Excluding(p => p.IftarMeetingProgramGeneratedData) .Excluding(p => p.LearningMeetingProgramData) .Excluding(p => p.LearningMeetingProgramGeneratedData) .Excluding(p => p.SocialDawahMeetingProgramData) .Excluding(p => p.SocialDawahMeetingProgramGeneratedData) .Excluding(p => p.DawahGroupMeetingProgramData) .Excluding(p => p.DawahGroupMeetingProgramGeneratedData) .Excluding(p => p.NextGMeetingProgramData) .Excluding(p => p.NextGMeetingProgramGeneratedData) .Excluding(p => p.CmsMeetingProgramData) .Excluding(p => p.CmsMeetingProgramGeneratedData) .Excluding(p => p.SmMeetingProgramData) .Excluding(p => p.SmMeetingProgramGeneratedData) .Excluding(p => p.MemberMeetingProgramData) .Excluding(p => p.MemberMeetingProgramGeneratedData) .Excluding(p => p.TafsirMeetingProgramData) .Excluding(p => p.TafsirMeetingProgramGeneratedData) .Excluding(p => p.UnitMeetingProgramData) .Excluding(p => p.UnitMeetingProgramGeneratedData) .Excluding(p => p.FamilyVisitMeetingProgramData) .Excluding(p => p.FamilyVisitMeetingProgramGeneratedData) .Excluding(p => p.EidReunionMeetingProgramData) .Excluding(p => p.EidReunionMeetingProgramGeneratedData) .Excluding(p => p.BbqMeetingProgramData) .Excluding(p => p.BbqMeetingProgramGeneratedData) .Excluding(p => p.GatheringMeetingProgramData) .Excluding(p => p.GatheringMeetingProgramGeneratedData) .Excluding(p => p.OtherMeetingProgramData) .Excluding(p => p.OtherMeetingProgramGeneratedData) .Excluding(p => p.GroupStudyTeachingLearningProgramData) .Excluding(p => p.GroupStudyTeachingLearningProgramGeneratedData) .Excluding(p => p.StudyCircleTeachingLearningProgramData) .Excluding(p => p.StudyCircleTeachingLearningProgramGeneratedData) .Excluding(p => p.PracticeDarsTeachingLearningProgramData) .Excluding(p => p.PracticeDarsTeachingLearningProgramGeneratedData) .Excluding(p => p.StateLearningCampTeachingLearningProgramData) .Excluding(p => p.StateLearningCampTeachingLearningProgramGeneratedData) .Excluding(p => p.QuranStudyTeachingLearningProgramData) .Excluding(p => p.QuranStudyTeachingLearningProgramGeneratedData) .Excluding(p => p.QuranClassTeachingLearningProgramData) .Excluding(p => p.QuranClassTeachingLearningProgramGeneratedData) .Excluding(p => p.MemorizingAyatTeachingLearningProgramData) .Excluding(p => p.MemorizingAyatTeachingLearningProgramGeneratedData) .Excluding(p => p.StateLearningSessionTeachingLearningProgramData) .Excluding(p => p.StateLearningSessionTeachingLearningProgramGeneratedData) .Excluding(p => p.StateQiyamulLailTeachingLearningProgramData) .Excluding(p => p.StateQiyamulLailTeachingLearningProgramGeneratedData) .Excluding(p => p.StudyCircleForAssociateMemberTeachingLearningProgramData) .Excluding(p => p.StudyCircleForAssociateMemberTeachingLearningProgramGeneratedData) .Excluding(p => p.HadithTeachingLearningProgramData) .Excluding(p => p.HadithTeachingLearningProgramGeneratedData) .Excluding(p => p.WeekendIslamicSchoolTeachingLearningProgramData) .Excluding(p => p.WeekendIslamicSchoolTeachingLearningProgramGeneratedData) .Excluding(p => p.MemorizingHadithTeachingLearningProgramData) .Excluding(p => p.MemorizingHadithTeachingLearningProgramGeneratedData) .Excluding(p => p.MemorizingDoaTeachingLearningProgramData) .Excluding(p => p.MemorizingDoaTeachingLearningProgramGeneratedData) .Excluding(p => p.OtherTeachingLearningProgramData) .Excluding(p => p.OtherTeachingLearningProgramGeneratedData) .Excluding(p => p.BookSaleMaterialData) .Excluding(p => p.BookSaleMaterialGeneratedData) .Excluding(p => p.BookDistributionMaterialData) .Excluding(p => p.BookDistributionMaterialGeneratedData) .Excluding(p => p.BookLibraryStockData) .Excluding(p => p.BookLibraryStockGeneratedData) .Excluding(p => p.OtherSaleMaterialData) .Excluding(p => p.OtherSaleMaterialGeneratedData) .Excluding(p => p.OtherDistributionMaterialData) .Excluding(p => p.OtherDistributionMaterialGeneratedData) .Excluding(p => p.OtherLibraryStockData) .Excluding(p => p.OtherLibraryStockGeneratedData) .Excluding(p => p.VhsSaleMaterialData) .Excluding(p => p.VhsSaleMaterialGeneratedData) .Excluding(p => p.VhsDistributionMaterialData) .Excluding(p => p.VhsDistributionMaterialGeneratedData) .Excluding(p => p.VhsLibraryStockData) .Excluding(p => p.VhsLibraryStockGeneratedData) .Excluding(p => p.EmailDistributionMaterialData) .Excluding(p => p.EmailDistributionMaterialGeneratedData) .Excluding(p => p.IpdcLeafletDistributionMaterialData) .Excluding(p => p.IpdcLeafletDistributionMaterialGeneratedData) .Excluding(p => p.BaitulMalFinanceData) .Excluding(p => p.BaitulMalFinanceGeneratedData) .Excluding(p => p.ADayMasjidProjectFinanceData) .Excluding(p => p.ADayMasjidProjectFinanceGeneratedData) .Excluding(p => p.MasjidTableBankFinanceData) .Excluding(p => p.MasjidTableBankFinanceGeneratedData) .Excluding(p => p.QardeHasanaSocialWelfareData) .Excluding(p => p.QardeHasanaSocialWelfareGeneratedData) .Excluding(p => p.PatientVisitSocialWelfareData) .Excluding(p => p.PatientVisitSocialWelfareGeneratedData) .Excluding(p => p.SocialVisitSocialWelfareData) .Excluding(p => p.SocialVisitSocialWelfareGeneratedData) .Excluding(p => p.TransportSocialWelfareData) .Excluding(p => p.TransportSocialWelfareGeneratedData) .Excluding(p => p.ShiftingSocialWelfareData) .Excluding(p => p.ShiftingSocialWelfareGeneratedData) .Excluding(p => p.ShoppingSocialWelfareData) .Excluding(p => p.ShoppingSocialWelfareGeneratedData) .Excluding(p => p.FoodDistributionSocialWelfareData) .Excluding(p => p.FoodDistributionSocialWelfareGeneratedData) .Excluding(p => p.CleanUpAustraliaSocialWelfareData) .Excluding(p => p.CleanUpAustraliaSocialWelfareGeneratedData) .Excluding(p => p.OtherSocialWelfareData) .Excluding(p => p.OtherSocialWelfareGeneratedData) ); result.stateReport.MemberMemberData.Should().BeEquivalentTo(testParams.expectedMemberMemberData); result.stateReport.MemberMemberGeneratedData.Should().BeEquivalentTo(testParams.expectedMemberMemberGeneratedData); result.stateReport.AssociateMemberData.Should().BeEquivalentTo(testParams.expectedAssociateMemberData); result.stateReport.AssociateMemberGeneratedData.Should().BeEquivalentTo(testParams.expectedAssociateMemberGeneratedData); result.stateReport.PreliminaryMemberData.Should().BeEquivalentTo(testParams.expectedPreliminaryMemberData); result.stateReport.PreliminaryMemberGeneratedData.Should().BeEquivalentTo(testParams.expectedPreliminaryMemberGeneratedData); result.stateReport.SupporterMemberData.Should().BeEquivalentTo(testParams.expectedSupporterMemberData); result.stateReport.SupporterMemberGeneratedData.Should().BeEquivalentTo(testParams.expectedSupporterMemberGeneratedData); }
public async Task Handle_SavesReport(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 OrganizationBuilder() .SetOrganizationType(OrganizationType.Central) .SetReportingFreQuency(reportingFrequency) .BuildAndPersist(s); var report = new CentralReportBuilder() .SetOrganization(organization) .SetReportingPeriod(new ReportingPeriod(reportingFrequency, reportingTerm, year)) .Build(); report.MarkStatusAsPlanPromoted(); s.Save(report); var memberMemberData = new TestObjectBuilder <MemberData>() .Build(); var associateMemberData = new TestObjectBuilder <MemberData>() .Build(); var preliminaryMemberData = new TestObjectBuilder <MemberData>() .Build(); //Todo pass random data once supporterMember is added to the CentralReport var supporterMemberData = new TestObjectBuilder <MemberData>() .Build(); var workerMeetingProgramData = new TestObjectBuilder <MeetingProgramData>().Build(); var dawahMeetingProgramData = new TestObjectBuilder <MeetingProgramData>().Build(); var stateLeaderMeetingProgramData = new TestObjectBuilder <MeetingProgramData>().Build(); var stateOutingMeetingProgramData = new TestObjectBuilder <MeetingProgramData>().Build(); var iftarMeetingProgramData = new TestObjectBuilder <MeetingProgramData>().Build(); var learningMeetingProgramData = new TestObjectBuilder <MeetingProgramData>().Build(); var socialDawahMeetingProgramData = new TestObjectBuilder <MeetingProgramData>().Build(); var dawahGroupMeetingProgramData = new TestObjectBuilder <MeetingProgramData>().Build(); var nextGMeetingProgramData = new TestObjectBuilder <MeetingProgramData>().Build(); var cmsMeetingProgramData = new TestObjectBuilder <MeetingProgramData>().Build(); var smMeetingProgramData = new TestObjectBuilder <MeetingProgramData>().Build(); var memberMeetingProgramData = new TestObjectBuilder <MeetingProgramData>().Build(); var tafsirMeetingProgramData = new TestObjectBuilder <MeetingProgramData>().Build(); var unitMeetingProgramData = new TestObjectBuilder <MeetingProgramData>().Build(); var familyVisitMeetingProgramData = new TestObjectBuilder <MeetingProgramData>().Build(); var eidReunionMeetingProgramData = new TestObjectBuilder <MeetingProgramData>().Build(); var bbqMeetingProgramData = new TestObjectBuilder <MeetingProgramData>().Build(); var gatheringMeetingProgramData = new TestObjectBuilder <MeetingProgramData>().Build(); var otherMeetingProgramData = new TestObjectBuilder <MeetingProgramData>().Build(); var groupStudyTeachingLearningProgramData = new TestObjectBuilder <TeachingLearningProgramData>().Build(); var studyCircleTeachingLearningProgramData = new TestObjectBuilder <TeachingLearningProgramData>().Build(); var practiceDarsTeachingLearningProgramData = new TestObjectBuilder <TeachingLearningProgramData>().Build(); var stateLearningCampTeachingLearningProgramData = new TestObjectBuilder <TeachingLearningProgramData>().Build(); var quranStudyTeachingLearningProgramData = new TestObjectBuilder <TeachingLearningProgramData>().Build(); var quranClassTeachingLearningProgramData = new TestObjectBuilder <TeachingLearningProgramData>().Build(); var memorizingAyatTeachingLearningProgramData = new TestObjectBuilder <TeachingLearningProgramData>().Build(); var stateLearningSessionTeachingLearningProgramData = new TestObjectBuilder <TeachingLearningProgramData>().Build(); var stateQiyamulLailTeachingLearningProgramData = new TestObjectBuilder <TeachingLearningProgramData>().Build(); var studyCircleForAssociateMemberTeachingLearningProgramData = new TestObjectBuilder <TeachingLearningProgramData>().Build(); var hadithTeachingLearningProgramData = new TestObjectBuilder <TeachingLearningProgramData>().Build(); var weekendIslamicSchoolTeachingLearningProgramData = new TestObjectBuilder <TeachingLearningProgramData>().Build(); var memorizingHadithTeachingLearningProgramData = new TestObjectBuilder <TeachingLearningProgramData>().Build(); var memorizingDoaTeachingLearningProgramData = new TestObjectBuilder <TeachingLearningProgramData>().Build(); var otherTeachingLearningProgramData = new TestObjectBuilder <TeachingLearningProgramData>().Build(); var baitulMalFinanceData = FinanceData.Default(); var aDayMasjidProjectFinanceData = FinanceData.Default(); var masjidTableBankFinanceData = FinanceData.Default(); var qardeHasanaSocialWelfareData = SocialWelfareData.Default(); var patientVisitSocialWelfareData = SocialWelfareData.Default(); var socialVisitSocialWelfareData = SocialWelfareData.Default(); var transportSocialWelfareData = SocialWelfareData.Default(); var shiftingSocialWelfareData = SocialWelfareData.Default(); var shoppingSocialWelfareData = SocialWelfareData.Default(); var foodDistributionSocialWelfareData = SocialWelfareData.Default(); var cleanUpAustraliaSocialWelfareData = SocialWelfareData.Default(); var otherSocialWelfareData = SocialWelfareData.Default(); var bookSaleMaterialData = MaterialData.Default(); var bookDistributionMaterialData = MaterialData.Default(); var bookLibraryStockData = LibraryStockData.Default(); var otherSaleMaterialData = MaterialData.Default(); var otherDistributionMaterialData = MaterialData.Default(); var otherLibraryStockData = LibraryStockData.Default(); var vhsSaleMaterialData = MaterialData.Default(); var vhsDistributionMaterialData = MaterialData.Default(); var vhsLibraryStockData = LibraryStockData.Default(); var emailDistributionMaterialData = MaterialData.Default(); var ipdcLeafletDistributionMaterialData = MaterialData.Default(); //var bookLibraryStockData = LibraryStockData.Default(); //var vhsLibraryStockData = LibraryStockData.Default(); var comment = DataProvider.Get <string>(); ReportUpdateData centralReportUpdateData = new ReportDataBuilder() .SetMemberMemberData(memberMemberData) .SetAssociateMemberData(associateMemberData) .SetPreliminaryMemberData(preliminaryMemberData) .SetSupporterMemberData(supporterMemberData) .SetWorkerMeetingProgramData(workerMeetingProgramData) .SetDawahMeetingProgramData(dawahMeetingProgramData) .SetStateLeaderMeetingProgramData(stateLeaderMeetingProgramData) .SetStateOutingMeetingProgramData(stateOutingMeetingProgramData) .SetIftarMeetingProgramData(iftarMeetingProgramData) .SetLearningMeetingProgramData(learningMeetingProgramData) .SetSocialDawahMeetingProgramData(socialDawahMeetingProgramData) .SetDawahGroupMeetingProgramData(dawahGroupMeetingProgramData) .SetNextGMeetingProgramData(nextGMeetingProgramData) .SetCmsMeetingProgramData(cmsMeetingProgramData) .SetSmMeetingProgramData(smMeetingProgramData) .SetMemberMeetingProgramData(memberMeetingProgramData) .SetTafsirMeetingProgramData(tafsirMeetingProgramData) .SetUnitMeetingProgramData(unitMeetingProgramData) .SetFamilyVisitMeetingProgramData(familyVisitMeetingProgramData) .SetEidReunionMeetingProgramData(eidReunionMeetingProgramData) .SetBbqMeetingProgramData(bbqMeetingProgramData) .SetGatheringMeetingProgramData(gatheringMeetingProgramData) .SetOtherMeetingProgramData(otherMeetingProgramData) .SetGroupStudyTeachingLearningProgramData(groupStudyTeachingLearningProgramData) .SetStudyCircleTeachingLearningProgramData(studyCircleTeachingLearningProgramData) .SetPracticeDarsTeachingLearningProgramData(practiceDarsTeachingLearningProgramData) .SetStateLearningCampTeachingLearningProgramData(stateLearningCampTeachingLearningProgramData) .SetQuranStudyTeachingLearningProgramData(quranStudyTeachingLearningProgramData) .SetQuranClassTeachingLearningProgramData(quranClassTeachingLearningProgramData) .SetMemorizingAyatTeachingLearningProgramData(memorizingAyatTeachingLearningProgramData) .SetStateLearningSessionTeachingLearningProgramData(stateLearningSessionTeachingLearningProgramData) .SetStateQiyamulLailTeachingLearningProgramData(stateQiyamulLailTeachingLearningProgramData) .SetBaitulMalFinanceData(baitulMalFinanceData) .SetADayMasjidProjectFinanceData(aDayMasjidProjectFinanceData) .SetMasjidTableBankFinanceData(masjidTableBankFinanceData) .SetQardeHasanaSocialWelfareData(qardeHasanaSocialWelfareData) .SetPatientVisitSocialWelfareData(patientVisitSocialWelfareData) .SetSocialVisitSocialWelfareData(socialVisitSocialWelfareData) .SetTransportSocialWelfareData(transportSocialWelfareData) .SetShiftingSocialWelfareData(shiftingSocialWelfareData) .SetShoppingSocialWelfareData(shoppingSocialWelfareData) .SetFoodDistributionSocialWelfareData(foodDistributionSocialWelfareData) .SetCleanUpAustraliaSocialWelfareData(cleanUpAustraliaSocialWelfareData) .SetOtherSocialWelfareData(otherSocialWelfareData) .SetBookSaleMaterialData(bookSaleMaterialData) .SetBookDistributionMaterialData(bookDistributionMaterialData) .SetBookLibraryStockData(bookLibraryStockData) .SetOtherSaleMaterialData(otherSaleMaterialData) .SetOtherDistributionMaterialData(otherDistributionMaterialData) .SetOtherLibraryStockData(otherLibraryStockData) .SetVhsSaleMaterialData(vhsSaleMaterialData) .SetVhsDistributionMaterialData(vhsDistributionMaterialData) .SetVhsLibraryStockData(vhsLibraryStockData) .SetEmailDistributionMaterialData(emailDistributionMaterialData) .SetIpdcLeafletDistributionMaterialData(ipdcLeafletDistributionMaterialData) .SetGroupStudyTeachingLearningProgramData(groupStudyTeachingLearningProgramData) .SetStudyCircleTeachingLearningProgramData(studyCircleTeachingLearningProgramData) .SetPracticeDarsTeachingLearningProgramData(practiceDarsTeachingLearningProgramData) .SetStateLearningCampTeachingLearningProgramData(stateLearningCampTeachingLearningProgramData) .SetQuranStudyTeachingLearningProgramData(quranStudyTeachingLearningProgramData) .SetQuranClassTeachingLearningProgramData(quranClassTeachingLearningProgramData) .SetMemorizingAyatTeachingLearningProgramData(memorizingAyatTeachingLearningProgramData) .SetStateLearningSessionTeachingLearningProgramData(stateLearningSessionTeachingLearningProgramData) .SetStateQiyamulLailTeachingLearningProgramData(stateQiyamulLailTeachingLearningProgramData) .SetStudyCircleForAssociateMemberTeachingLearningProgramData(studyCircleForAssociateMemberTeachingLearningProgramData) .SetHadithTeachingLearningProgramData(hadithTeachingLearningProgramData) .SetWeekendIslamicSchoolTeachingLearningProgramData(weekendIslamicSchoolTeachingLearningProgramData) .SetMemorizingHadithTeachingLearningProgramData(memorizingHadithTeachingLearningProgramData) .SetMemorizingDoaTeachingLearningProgramData(memorizingDoaTeachingLearningProgramData) .SetOtherTeachingLearningProgramData(otherTeachingLearningProgramData) .SetComment(comment) .Build(); EntityReference reportRef = report; var expectedEvt = Test.CreateInstance <ICentralReportUpdated>(e => { e.Organization = organization; e.Username = username; e.CentralReport = reportRef; }); return(new { Cmd = new UpdateCentralReportCommand(report.Id, centralReportUpdateData), Report = report, username, expectedEvt }); }); var context = await Endpoint.Act <UpdateCentralReportCommandHandler>(AssemblySetupFixture.EndpointTestContainer, (h, ctx) => { ctx.SetUsernameOnHeader(testParams.username); return(h.Handle(testParams.Cmd, ctx)); }); var evt = context.ExpectPublish <ICentralReportUpdated>(); Endpoint.AssertOnSqlSessionThat(AssemblySetupFixture.EndpointTestContainer, s => { var centralReport = s.Get <CentralReport>(testParams.Cmd.ReportId); centralReport.Should().NotBeNull(); centralReport.Should().BeEquivalentTo(testParams.Report, e => e.Excluding(p => p.MemberMemberData) .Excluding(p => p.AssociateMemberData) .Excluding(p => p.PreliminaryMemberData) .Excluding(p => p.SupporterMemberData) .Excluding(p => p.WorkerMeetingProgramData) .Excluding(p => p.DawahMeetingProgramData) .Excluding(p => p.StateLeaderMeetingProgramData) .Excluding(p => p.StateOutingMeetingProgramData) .Excluding(p => p.IftarMeetingProgramData) .Excluding(p => p.LearningMeetingProgramData) .Excluding(p => p.SocialDawahMeetingProgramData) .Excluding(p => p.DawahGroupMeetingProgramData) .Excluding(p => p.NextGMeetingProgramData) .Excluding(p => p.CmsMeetingProgramData) .Excluding(p => p.SmMeetingProgramData) .Excluding(p => p.MemberMeetingProgramData) .Excluding(p => p.TafsirMeetingProgramData) .Excluding(p => p.UnitMeetingProgramData) .Excluding(p => p.FamilyVisitMeetingProgramData) .Excluding(p => p.EidReunionMeetingProgramData) .Excluding(p => p.BbqMeetingProgramData) .Excluding(p => p.GatheringMeetingProgramData) .Excluding(p => p.OtherMeetingProgramData) .Excluding(p => p.GroupStudyTeachingLearningProgramData) .Excluding(p => p.StudyCircleTeachingLearningProgramData) .Excluding(p => p.PracticeDarsTeachingLearningProgramData) .Excluding(p => p.StateLearningCampTeachingLearningProgramData) .Excluding(p => p.QuranStudyTeachingLearningProgramData) .Excluding(p => p.QuranClassTeachingLearningProgramData) .Excluding(p => p.MemorizingAyatTeachingLearningProgramData) .Excluding(p => p.StateLearningSessionTeachingLearningProgramData) .Excluding(p => p.StateQiyamulLailTeachingLearningProgramData) .Excluding(p => p.StudyCircleForAssociateMemberTeachingLearningProgramData) .Excluding(p => p.HadithTeachingLearningProgramData) .Excluding(p => p.WeekendIslamicSchoolTeachingLearningProgramData) .Excluding(p => p.MemorizingHadithTeachingLearningProgramData) .Excluding(p => p.MemorizingDoaTeachingLearningProgramData) .Excluding(p => p.OtherTeachingLearningProgramData) .Excluding(p => p.BookSaleMaterialData) .Excluding(p => p.BookDistributionMaterialData) .Excluding(p => p.BookLibraryStockData) .Excluding(p => p.OtherSaleMaterialData) .Excluding(p => p.OtherDistributionMaterialData) .Excluding(p => p.OtherLibraryStockData) .Excluding(p => p.VhsSaleMaterialData) .Excluding(p => p.VhsDistributionMaterialData) .Excluding(p => p.VhsLibraryStockData) .Excluding(p => p.EmailDistributionMaterialData) .Excluding(p => p.IpdcLeafletDistributionMaterialData) .Excluding(p => p.BaitulMalFinanceData) .Excluding(p => p.ADayMasjidProjectFinanceData) .Excluding(p => p.MasjidTableBankFinanceData) .Excluding(p => p.QardeHasanaSocialWelfareData) .Excluding(p => p.PatientVisitSocialWelfareData) .Excluding(p => p.SocialVisitSocialWelfareData) .Excluding(p => p.TransportSocialWelfareData) .Excluding(p => p.ShiftingSocialWelfareData) .Excluding(p => p.ShoppingSocialWelfareData) .Excluding(p => p.FoodDistributionSocialWelfareData) .Excluding(p => p.CleanUpAustraliaSocialWelfareData) .Excluding(p => p.OtherSocialWelfareData) .Excluding(p => p.Comment) ); ReportData reportData = centralReport; ReportUpdateData reportUpdateData = reportData; reportUpdateData.Should().BeEquivalentTo(testParams.Cmd.ReportUpdateData); evt.Should().BeEquivalentTo(testParams.expectedEvt, e => e.Excluding(p => p.SerializedData)); evt.SerializedData.Should().NotBe(null); }); }
public async Task Handle_SavesPlan(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 OrganizationBuilder() .SetOrganizationType(OrganizationType.State) .SetReportingFreQuency(reportingFrequency) .BuildAndPersist(s); var associateMemberData = new TestObjectBuilder <MemberData>() .Build(); var preliminaryMemberData = new TestObjectBuilder <MemberData>() .Build(); PlanData planData = new ReportDataBuilder() .SetAssociateMemberData(associateMemberData) .SetPreliminaryMemberData(preliminaryMemberData) .Build(); var report = new StateReportBuilder() .SetOrganization(organization) .SetReportingPeriod(new ReportingPeriod(reportingFrequency, reportingTerm, year)) .BuildAndPersist(s); report.UpdatePlan(planData); s.Save(report); EntityReference reportRef = report; var expectedEvt = Test.CreateInstance <IStatePlanPromoted>(e => { e.Organization = organization; e.Username = username; e.StateReport = reportRef; }); return(new { Cmd = new PromotePlanToStateReportCommand(report.Id), Report = report, username, expectedEvt }); }); var context = await Endpoint.Act <PromotePlanToStateReportCommandHandler>(AssemblySetupFixture.EndpointTestContainer, (h, ctx) => { ctx.SetUsernameOnHeader(testParams.username); return(h.Handle(testParams.Cmd, ctx)); }); var evt = context.ExpectPublish <IStatePlanPromoted>(); Endpoint.AssertOnSqlSessionThat(AssemblySetupFixture.EndpointTestContainer, s => { var stateReport = s.Get <StateReport>(testParams.Cmd.PlanId); stateReport.Should().NotBeNull(); stateReport.Should().BeEquivalentTo(testParams.Report, e => e.Excluding(p => p.ReportStatus)); stateReport.ReportStatus.Should().Be(ReportStatus.PlanPromoted); evt.Should().BeEquivalentTo(testParams.expectedEvt, e => e.Excluding(p => p.SerializedData)); evt.SerializedData.Should().NotBe(null); }); }
public async Task Handle_SavesZoneReport(ReportingFrequency reportingFrequency, ReportingFrequency differentFrequency) { 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.Zone) .SetArgument(o => o.ReportingFrequency, reportingFrequency) .BuildAndPersist(s); var existing = new ZoneReportBuilder() .SetDescription(DataProvider.Get <string>()) .SetOrganization(organization) .SetReportingPeriod(new ReportingPeriod(reportingFrequency, reportingTerm, year)) .BuildAndPersist(s); var newReportYear = year + 1; new ZoneReportBuilder() .SetDescription(DataProvider.Get <string>()) .SetOrganization(organization) .SetReportingPeriod(new ReportingPeriod(differentFrequency, reportingTerm, newReportYear)) .BuildAndPersist(s); var cmd = new CopyZonePlanCommand(existing.Id, organization, newReportYear, reportingTerm, reportingFrequency); var description = cmd.Description; var lastPeriodData = Calculator.GetLastPeriodUpdateData(existing); var expected = new ZoneReportBuilder() .SetDescription(description) .SetOrganization(organization) .SetReportingPeriod(new ReportingPeriod(reportingFrequency, reportingTerm, newReportYear)) .SetReportData(existing) .Build(); expected.Update(lastPeriodData); return(new { cmd, username, expected }); }); var context = await Endpoint.Act <CopyZonePlanCommandHandler>(AssemblySetupFixture.EndpointTestContainer, (h, ctx) => { ctx.SetUsernameOnHeader(testParams.username); return(h.Handle(testParams.cmd, ctx)); }); var evt = context.ExpectPublish <IZonePlanCopied>(); Endpoint.AssertOnSqlSessionThat(AssemblySetupFixture.EndpointTestContainer, s => { var report = s.Query <ZoneReport>().OrderByDescending(o => o.Id).First(); report.Should().NotBeNull(); report.Should().BeEquivalentTo(testParams.expected, e => e.Excluding(p => p.Id) .Excluding(p => p.ReportingPeriod) .Excluding(p => p.ReportStatus)); EntityReference reportRef = report; var expectedEvt = Test.CreateInstance <IZonePlanCopied>(e => { e.Organization = testParams.expected.Organization; e.Username = testParams.username; e.ZoneReport = reportRef; }); evt.Should().BeEquivalentTo(expectedEvt, e => e.Excluding(p => p.SerializedData)); evt.SerializedData.Should().NotBe(null); }); }
public async Task Handle_Publishes_ExpectedResult() { DateTimeDbTestExtensions.SetUtcNowToRandomDate(); var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { var username = DataProvider.Get <string>(); var organizations = IntegrationTestOrganizationHelper.SetupOrzanizations(); var central = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.Central).Value; var nswState = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.NswState).Value; var nswZone1 = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.NswZoneOne).Value; var lakemba = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.Lakemba).Value; var year1 = 2019; var year2 = 2020; var period1 = new ReportingPeriod(ReportingFrequency.Monthly, ReportingTerm.One, year1); var period2 = new ReportingPeriod(ReportingFrequency.Monthly, ReportingTerm.One, year2); var period1ReportingData = new ReportDataBuilder().Build(); var period2ReportingData = new ReportDataBuilder().Build(); var period1UnitReport = new UnitReport(DataProvider.Get <string>(), lakemba, period1, period1ReportingData); s.Save(period1UnitReport); var period2UnitReport = new UnitReport(DataProvider.Get <string>(), lakemba, period2, period2ReportingData); s.Save(period2UnitReport); var period1ZoneReport = new ZoneReport(DataProvider.Get <string>(), nswZone1, period1, period1ReportingData); s.Save(period1ZoneReport); var period2ZoneReport = new ZoneReport(DataProvider.Get <string>(), nswZone1, period2, period2ReportingData); s.Save(period2ZoneReport); var period1StateReport = new StateReport(DataProvider.Get <string>(), nswState, period1, period1ReportingData); s.Save(period1StateReport); var period2StateReport = new StateReport(DataProvider.Get <string>(), nswState, period2, period2ReportingData); s.Save(period2StateReport); var period1CentralReport = new CentralReport(DataProvider.Get <string>(), central, period1, period1ReportingData); s.Save(period1CentralReport); var period2CentralReport = new CentralReport(DataProvider.Get <string>(), central, period2, period2ReportingData); s.Save(period2CentralReport); var reportIds = new[] { period1UnitReport.Id, period2UnitReport.Id, period1ZoneReport.Id, period2ZoneReport.Id, period1StateReport.Id, period2StateReport.Id, period1CentralReport.Id, period2CentralReport.Id, }; var expectedReportData = ReportDataCalculator.GetCalculatedReportData(new[] { period2UnitReport }, new[] { period1UnitReport, period2UnitReport }, new[] { period2ZoneReport }, new[] { period1ZoneReport, period2ZoneReport }, new[] { period2StateReport }, new[] { period1StateReport, period2StateReport }, new[] { period2CentralReport }, new[] { period1CentralReport, period2CentralReport }); return(new { username, expectedReportData, cmd = new ConsolidateReportCommand(reportIds), }); }); var context = await Endpoint.Act <ConsolidateReportCommandHandler>(AssemblySetupFixture.EndpointTestContainer, (h, ctx) => { ctx.SetUsernameOnHeader(testParams.username); return(h.Handle(testParams.cmd, ctx)); }); var evt = context.ExpectPublish <IConsolidateReportSucceeded>(); evt.ReportIds.Should().BeEquivalentTo(testParams.cmd.ReportIds); evt.ReportData.Should().BeEquivalentTo(testParams.expectedReportData); evt.Username.Should().BeEquivalentTo(testParams.username); }
public void GetConsolidatedReportData_Returns_ExpectedReportData() { DateTimeDbTestExtensions.SetUtcNowToRandomDate(); var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { var organizations = IntegrationTestOrganizationHelper.SetupOrzanizations(); var central = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.Central).Value; var nswState = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.NswState).Value; var nswZone1 = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.NswZoneOne).Value; var lakemba = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.Lakemba).Value; var year1 = 2019; var year2 = 2020; var period1 = new ReportingPeriod(ReportingFrequency.Monthly, ReportingTerm.One, year1); var period2 = new ReportingPeriod(ReportingFrequency.Monthly, ReportingTerm.One, year2); var period1ReportingData = new ReportDataBuilder().Build(); var period2ReportingData = new ReportDataBuilder().Build(); var period1UnitReport = new UnitReport(DataProvider.Get <string>(), lakemba, period1, period1ReportingData); s.Save(period1UnitReport); var period2UnitReport = new UnitReport(DataProvider.Get <string>(), lakemba, period2, period2ReportingData); s.Save(period2UnitReport); var period1ZoneReport = new ZoneReport(DataProvider.Get <string>(), nswZone1, period1, period1ReportingData); s.Save(period1ZoneReport); var period2ZoneReport = new ZoneReport(DataProvider.Get <string>(), nswZone1, period2, period2ReportingData); s.Save(period2ZoneReport); var period1StateReport = new StateReport(DataProvider.Get <string>(), nswState, period1, period1ReportingData); s.Save(period1StateReport); var period2StateReport = new StateReport(DataProvider.Get <string>(), nswState, period2, period2ReportingData); s.Save(period2StateReport); var period1CentralReport = new CentralReport(DataProvider.Get <string>(), central, period1, period1ReportingData); s.Save(period1CentralReport); var period2CentralReport = new CentralReport(DataProvider.Get <string>(), central, period2, period2ReportingData); s.Save(period2CentralReport); var reportIds = new[] { period1UnitReport.Id, period2UnitReport.Id, period1ZoneReport.Id, period2ZoneReport.Id, period1StateReport.Id, period2StateReport.Id, period1CentralReport.Id, period2CentralReport.Id, }; var expectedReportData = ReportDataCalculator.GetCalculatedReportData(new[] { period2UnitReport }, new[] { period1UnitReport, period2UnitReport }, new[] { period2ZoneReport }, new[] { period1ZoneReport, period2ZoneReport }, new[] { period2StateReport }, new[] { period1StateReport, period2StateReport }, new[] { period2CentralReport }, new[] { period1CentralReport, period2CentralReport }); return(new { reportIds, expectedReportData }); }); var result = Endpoint.Act(AssemblySetupFixture.EndpointTestContainer, c => c.GetInstance <ConsolidatedReportService>().GetConsolidatedReportData(testParams.reportIds)); result.Should().NotBeNull(); result.Should().BeEquivalentTo(testParams.expectedReportData); }
public async Task Handle_SavesReportWhenNoPreviousReportSubmitted(ReportingFrequency reportingFrequency, bool overrideReportData) { var now = DateTimeDbTestExtensions.SetUtcNowToRandomDate(); var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { var username = DataProvider.Get <string>(); var year = 2019; var reportingTerm = ReportingTerm.One; var organization = new OrganizationBuilder() .SetOrganizationType(OrganizationType.Zone) .SetReportingFreQuency(reportingFrequency) .BuildAndPersist(s); var report = new ZoneReportBuilder() .SetOrganization(organization) .SetReportingPeriod(new ReportingPeriod(reportingFrequency, reportingTerm, year)) .Build(); report.MarkStatusAsPlanPromoted(); s.Save(report); var generatedData = GetZoneReportData(); report.UpdateGeneratedData(generatedData); report.Update(generatedData); s.Save(report); EntityReference reportRef = report; var expectedEvt = Test.CreateInstance <IZoneReportUpdated>(e => { e.Organization = organization; e.Username = username; e.ZoneReport = reportRef; }); return(new { Cmd = new UpdateZoneReportGeneratedDataCommand(report.Id, overrideReportData), Organization = organization, Report = report, zoneReportData = generatedData, overrideReportData, username, expectedEvt }); }); var context = await Endpoint.Act <UpdateZoneReportGeneratedDataCommandHandler>(AssemblySetupFixture.EndpointTestContainer, (h, ctx) => { ctx.SetUsernameOnHeader(testParams.username); return(h.Handle(testParams.Cmd, ctx)); }); var evt = context.ExpectPublish <IZoneReportUpdated>(); Endpoint.AssertOnSqlSessionThat(AssemblySetupFixture.EndpointTestContainer, s => { var report = s.Get <Report>(testParams.Cmd.ReportId); report.Should().NotBeNull(); report.Description.Should().Be(testParams.Report.Description); report.ReportingPeriod.Year.Should().Be(testParams.Report.ReportingPeriod.Year); report.ReportingPeriod.ReportingFrequency.Should().Be(testParams.Organization.ReportingFrequency); report.ReportingPeriod.ReportingTerm.Should().Be(testParams.Report.ReportingPeriod.ReportingTerm); report.Organization.Should().Be(testParams.Report.Organization); report.ReportStatus.Should().Be(ReportStatus.PlanPromoted); report.Timestamp.Should().Be(now); report.IsDeleted.Should().Be(false); var zoneReport = s.Get <ZoneReport>(testParams.Cmd.ReportId); zoneReport.Should().NotBeNull(); zoneReport.Description.Should().Be(testParams.Report.Description); zoneReport.ReportingPeriod.Year.Should().Be(testParams.Report.ReportingPeriod.Year); zoneReport.ReportingPeriod.ReportingFrequency.Should() .Be(testParams.Organization.ReportingFrequency); zoneReport.ReportingPeriod.ReportingTerm.Should() .Be(testParams.Report.ReportingPeriod.ReportingTerm); zoneReport.Organization.Should().Be(testParams.Report.Organization); //zoneReport.AssociateMemberData.Should().Be(overrideReportData // ? MemberData.Default() // : testParams.zoneReportData.AssociateMemberData); //zoneReport.AssociateMemberGeneratedData.Should().Be(MemberData.Default()); //zoneReport.PreliminaryMemberData.Should().Be(overrideReportData // ? MemberData.Default() // : testParams.zoneReportData.PreliminaryMemberData); //zoneReport.PreliminaryMemberGeneratedData.Should().Be(MemberData.Default()); //zoneReport.WorkerMeetingProgramData.Should().Be(overrideReportData // ? MeetingProgramData.Default() // : testParams.zoneReportData.WorkerMeetingProgramData); //zoneReport.WorkerMeetingProgramGeneratedData.Should().Be(MeetingProgramData.Default()); zoneReport.Timestamp.Should().Be(now); zoneReport.IsDeleted.Should().Be(false); evt.Should().BeEquivalentTo(testParams.expectedEvt, e => e.Excluding(p => p.SerializedData)); evt.SerializedData.Should().NotBe(null); }); }
public void CreateNewUnitPlanAi_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 lastPeriod1 = reportingPeriod.GetReportingPeriodOfPreviousTerm(); var lastPeriod1ReportingData = new ReportDataBuilder().Build(); var lastPeriod1UnitReport = new UnitReport(description, organization, lastPeriod1, lastPeriod1ReportingData); lastPeriod1UnitReport.MarkStatusAsSubmitted(); s.Save(lastPeriod1UnitReport); var lastPeriod2 = lastPeriod1.GetReportingPeriodOfPreviousTerm(); var lastPeriod2ReportingData = new ReportDataBuilder().Build(); var lastPeriod2UnitReport = new UnitReport(description, organization, lastPeriod2, lastPeriod2ReportingData); lastPeriod2UnitReport.MarkStatusAsSubmitted(); s.Save(lastPeriod2UnitReport); var expected = new UnitReportBuilder() .SetDescription(description) .SetOrganization(organization) .SetReportingPeriod(new ReportingPeriod(reportingFrequency, reportingTerm, year)) .Build(); return(new { description, organizationRef, reportingPeriod, lastPeriod1UnitReport, expected }); }); var result = Endpoint.Act(AssemblySetupFixture.EndpointTestContainer, c => { var unitReport = c.GetInstance <UnitReportFactory>() .CreateNewUnitPlanAi(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) .Excluding(p => p.AssociateMemberData) .Excluding(p => p.PreliminaryMemberData) .Excluding(p => p.WorkerMeetingProgramData) .Excluding(p => p.SupporterMemberData) .Excluding(p => p.DawahMeetingProgramData) .Excluding(p => p.MemberMemberData)); TestHelper.MemberDataForCreateUnitPlanShouldBeEquivalent(result.unitReport.AssociateMemberData, testParams.lastPeriod1UnitReport.AssociateMemberData); TestHelper.MemberDataForCreateUnitPlanShouldBeEquivalent(result.unitReport.PreliminaryMemberData, testParams.lastPeriod1UnitReport.PreliminaryMemberData); result.unitReport.PreliminaryMemberData.Should().BeEquivalentTo(testParams.lastPeriod1UnitReport.WorkerMeetingProgramData); }
public async Task Handle_SavesPlan(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 OrganizationBuilder() .SetOrganizationType(OrganizationType.Unit) .SetReportingFreQuency(reportingFrequency) .BuildAndPersist(s); var report = new UnitReportBuilder() .SetOrganization(organization) .SetReportingPeriod(new ReportingPeriod(reportingFrequency, reportingTerm, year)) .BuildAndPersist(s); var associateMemberData = new TestObjectBuilder <MemberData>() .Build(); var preliminaryMemberData = new TestObjectBuilder <MemberData>() .Build(); var workerMeetingProgramData = new TestObjectBuilder <MeetingProgramData>() .Build(); var supporterMemberData = new TestObjectBuilder <MemberData>() .Build(); var memberMemberData = new TestObjectBuilder <MemberData>() .Build(); PlanData planData = new ReportDataBuilder() .SetAssociateMemberData(associateMemberData) .SetPreliminaryMemberData(preliminaryMemberData) .SetWorkerMeetingProgramData(workerMeetingProgramData) .SetSupporterMemberData(supporterMemberData) .SetMemberMemberData(memberMemberData) .Build(); EntityReference reportRef = report; var expectedEvt = Test.CreateInstance <IUnitPlanUpdated>(e => { e.Organization = organization; e.Username = username; e.UnitReport = reportRef; }); return(new { Cmd = new UpdateUnitPlanCommand(report.Id, planData), Organization = organization, Report = report, username, expectedEvt }); }); var context = await Endpoint.Act <UpdateUnitPlanCommandHandler>(AssemblySetupFixture.EndpointTestContainer, (h, ctx) => { ctx.SetUsernameOnHeader(testParams.username); return(h.Handle(testParams.Cmd, ctx)); }); var evt = context.ExpectPublish <IUnitPlanUpdated>(); Endpoint.AssertOnSqlSessionThat(AssemblySetupFixture.EndpointTestContainer, s => { var unitReport = s.Get <UnitReport>(testParams.Cmd.ReportId); unitReport.Should().NotBeNull(); unitReport.Should().BeEquivalentTo(testParams.Report, e => e.Excluding(p => p.AssociateMemberData) .Excluding(p => p.PreliminaryMemberData) .Excluding(p => p.SupporterMemberData) .Excluding(p => p.WorkerMeetingProgramData) .Excluding(p => p.DawahMeetingProgramData) .Excluding(p => p.StateLeaderMeetingProgramData) .Excluding(p => p.StateOutingMeetingProgramData) .Excluding(p => p.IftarMeetingProgramData) .Excluding(p => p.LearningMeetingProgramData) .Excluding(p => p.SocialDawahMeetingProgramData) .Excluding(p => p.DawahGroupMeetingProgramData) .Excluding(p => p.NextGMeetingProgramData) .Excluding(p => p.CmsMeetingProgramData) .Excluding(p => p.SmMeetingProgramData) .Excluding(p => p.MemberMeetingProgramData) .Excluding(p => p.TafsirMeetingProgramData) .Excluding(p => p.UnitMeetingProgramData) .Excluding(p => p.FamilyVisitMeetingProgramData) .Excluding(p => p.EidReunionMeetingProgramData) .Excluding(p => p.BbqMeetingProgramData) .Excluding(p => p.GatheringMeetingProgramData) .Excluding(p => p.OtherMeetingProgramData) .Excluding(p => p.MemberMemberData) .Excluding(p => p.BaitulMalFinanceData) .Excluding(p => p.ADayMasjidProjectFinanceData) .Excluding(p => p.MasjidTableBankFinanceData) .Excluding(p => p.QardeHasanaSocialWelfareData) .Excluding(p => p.PatientVisitSocialWelfareData) .Excluding(p => p.SocialVisitSocialWelfareData) .Excluding(p => p.TransportSocialWelfareData) .Excluding(p => p.ShiftingSocialWelfareData) .Excluding(p => p.ShoppingSocialWelfareData) .Excluding(p => p.FoodDistributionSocialWelfareData) .Excluding(p => p.CleanUpAustraliaSocialWelfareData) .Excluding(p => p.OtherSocialWelfareData) .Excluding(p => p.BookSaleMaterialData) .Excluding(p => p.BookDistributionMaterialData) .Excluding(p => p.BookLibraryStockData) .Excluding(p => p.OtherSaleMaterialData) .Excluding(p => p.OtherDistributionMaterialData) .Excluding(p => p.OtherLibraryStockData) .Excluding(p => p.VhsSaleMaterialData) .Excluding(p => p.VhsDistributionMaterialData) .Excluding(p => p.VhsLibraryStockData) .Excluding(p => p.EmailDistributionMaterialData) .Excluding(p => p.IpdcLeafletDistributionMaterialData) .Excluding(p => p.GroupStudyTeachingLearningProgramData) .Excluding(p => p.StudyCircleTeachingLearningProgramData) .Excluding(p => p.PracticeDarsTeachingLearningProgramData) .Excluding(p => p.StateLearningCampTeachingLearningProgramData) .Excluding(p => p.QuranStudyTeachingLearningProgramData) .Excluding(p => p.QuranClassTeachingLearningProgramData) .Excluding(p => p.MemorizingAyatTeachingLearningProgramData) .Excluding(p => p.StateLearningSessionTeachingLearningProgramData) .Excluding(p => p.StateQiyamulLailTeachingLearningProgramData) // .Excluding(p => p.StudyCircleForAssociateMemberTeachingLearningProgramData) .Excluding(p => p.HadithTeachingLearningProgramData) .Excluding(p => p.WeekendIslamicSchoolTeachingLearningProgramData) .Excluding(p => p.MemorizingHadithTeachingLearningProgramData) .Excluding(p => p.MemorizingDoaTeachingLearningProgramData) .Excluding(p => p.OtherTeachingLearningProgramData) ); ReportData reportData = unitReport; PlanData planData = reportData; planData.Should().BeEquivalentTo(testParams.Cmd.PlanData); evt.Should().BeEquivalentTo(testParams.expectedEvt, e => e.Excluding(p => p.SerializedData)); evt.SerializedData.Should().NotBe(null); }); }
public async Task Handle_SavesRecord(OrganizationType newOrganizationType, ReportingFrequency newReportingFrequency) { var now = DateTimeDbTestExtensions.SetUtcNowToRandomDate(); var username = DataProvider.Get <string>(); var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { var org = new OrganizationBuilder().BuildAndPersist(s); EntityReference parent; switch (newOrganizationType) { case OrganizationType.State: parent = new OrganizationBuilder().SetOrganizationType(OrganizationType.Central).BuildAndPersist(s); break; case OrganizationType.Zone: case OrganizationType.Unit: parent = new OrganizationBuilder().SetOrganizationType(OrganizationType.State).BuildAndPersist(s); break; default: parent = new OrganizationBuilder().SetOrganizationType(OrganizationType.Central).BuildAndPersist(s); break; } var newDescription = DataProvider.Get <string>(); var newDetails = DataProvider.Get <string>(); var expectedEvt = Test.CreateInstance <IOrganizationUpdated>(e => { e.Organization = new OrganizationReference(org.Id, newOrganizationType, newDescription, newDetails, newReportingFrequency); e.Username = username; }); return(new { username, expectedEvt, Cmd = new UpdateOrganizationCommand(org.Id, newDescription, newDetails, newOrganizationType, newReportingFrequency, parent) }); }); var context = await Endpoint.Act <UpdateOrganizationCommandHandler>(AssemblySetupFixture.EndpointTestContainer, (h, ctx) => { ctx.SetUsernameOnHeader(testParams.username); return(h.Handle(testParams.Cmd, ctx)); }); var evt = context.ExpectPublish <IOrganizationUpdated>(); Endpoint.AssertOnSqlSessionThat(AssemblySetupFixture.EndpointTestContainer, s => { var organization = s.Query <Organization>().Single(x => x.Id == testParams.Cmd.OrganizationId); organization.Should().NotBeNull(); organization.OrganizationType.Should().Be(testParams.Cmd.OrganizationType); organization.ReportingFrequency.Should().Be(testParams.Cmd.ReportingFrequency); organization.Description.Should().Be(testParams.Cmd.Description); organization.Details.Should().Be(testParams.Cmd.Details); organization.Parent.Should().Be(testParams.Cmd.Parent); organization.Timestamp.Should().Be(now); organization.IsDeleted.Should().Be(false); }); evt.Should().BeEquivalentTo(testParams.expectedEvt, e => e.Excluding(p => p.SerializedData)); evt.SerializedData.Should().NotBe(null); }