public void Setup() { Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { DomainDatabase.ClearAllReportingModuleTables(s); }); }
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 GetManagedOrganizationIds_For_Central_Should_Return_CorrectResult() { var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { var reportingFrequency = ReportingFrequency.Monthly; var organizations = IntegrationTestOrganizationHelper.SetupOrzanizations( stateReportingFrequency: reportingFrequency, zoneReportingFrequency: ReportingFrequency.Monthly); var central = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.Central).Value; return(new { organizations, central }); }); var result = NsbWebTest.Act(AssemblySetupFixture.WebTestContainer, c => c.GetInstance <OrganizationQueryService>() .GetManagedOrganizationIds(testParams.central.Id)); result.Should().NotBeNull(); result.Length.Should().Be(7); }
public async Task Handle_DeletesOrganization() { var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { var username = DataProvider.Get <string>(); var organization = new OrganizationBuilder().BuildAndPersist(s); return(new { username, cmd = new DeleteOrganizationCommand(organization.Id) }); }); await Endpoint.Act <DeleteOrganizationCommandHandler>(AssemblySetupFixture.EndpointTestContainer, (h, ctx) => { ctx.SetUsernameOnHeader(testParams.username); return(h.Handle(testParams.cmd, ctx)); }); Endpoint.AssertOnSqlSessionThat(AssemblySetupFixture.EndpointTestContainer, s => { var organization = s.Get <Organization>(testParams.cmd.OrganizationId); organization.Should().BeNull(); }); }
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 void GetManagedOrganizationViewModel_For_Zone_Should_Return_CorrectResult() { var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { var reportingFrequency = ReportingFrequency.Monthly; var organizations = IntegrationTestOrganizationHelper.SetupOrzanizations( stateReportingFrequency: reportingFrequency, zoneReportingFrequency: ReportingFrequency.Monthly); var zone = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.NswZoneOne).Value; return(new { organizations, zone }); }); var result = NsbWebTest.Act(AssemblySetupFixture.WebTestContainer, c => c.GetInstance <OrganizationQueryService>() .GetOrganizationViewModel(testParams.zone.Id)); result.Should().NotBeNull(); result.ManagedOrganizations.Count().Should().Be(2); }
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 void GetMyOrganizations_For_CentralUser_Should_Return_CorrectResult() { var username = DataProvider.Get <string>(); var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { var reportingFrequency = ReportingFrequency.Monthly; var organizations = IntegrationTestOrganizationHelper.SetupOrzanizations( stateReportingFrequency: reportingFrequency, zoneReportingFrequency: ReportingFrequency.Monthly); TestHelper.SetUserAccessAllOrganizationsClaim(username); return(new { organizations, }); }); var result = NsbWebTest.Act(AssemblySetupFixture.WebTestContainer, c => c.GetInstance <OrganizationQueryService>() .GetMyOrganizations()); result.Should().NotBeNull(); result.Length.Should().Be(testParams.organizations.Count); }
public void Has_Central_Should_Return_CorrectResult(bool isCentralUser) { var username = DataProvider.Get <string>(); var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { var reportingFrequency = ReportingFrequency.Monthly; var organizations = IntegrationTestOrganizationHelper.SetupOrzanizations( stateReportingFrequency: reportingFrequency, zoneReportingFrequency: ReportingFrequency.Monthly); var central = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.Central).Value; var nsw = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.NswState).Value; var organizationUser1 = new TestObjectBuilder <OrganizationUser>() .SetArgument(o => o.Username, username) .SetArgument(o => o.Organization, isCentralUser?central: nsw) .BuildAndPersist(s); new UserContextBuilder() .SetUsername(username) .AddClaims(TestHelper.GetOrganizationClaims(username, new[] { organizationUser1 })) .SetCurrentPrincipal(); return(new { organizationUser1 }); }); var result = NsbWebTest.Act(AssemblySetupFixture.WebTestContainer, c => c.GetInstance <OrganizationUserQueryService>() .HasCentralAccess(testParams.organizationUser1.Username)); result.Should().Be(isCentralUser); }
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_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_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_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_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 void SearchReportEventLog_Should_Return_NoResult_For_No_OrganizationClaims_Assigned_To_User() { var username1 = DataProvider.Get <string>(); var username2 = DataProvider.Get <string>(); Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { EntityReference organization1 = new OrganizationBuilder().BuildAndPersist(s); EntityReference organization2 = new OrganizationBuilder().BuildAndPersist(s); new TestObjectBuilder <OrganizationUser>() .SetArgument(o => o.Username, username1) .SetArgument(o => o.Organization, organization1) .BuildAndPersist(s); new TestObjectBuilder <ReportEventLog>() .SetArgument(o => o.CreatedByUsername, username1) .SetArgument(o => o.OrganizationId, null) .BuildAndPersist(s); new TestObjectBuilder <ReportEventLog>() .SetArgument(o => o.CreatedByUsername, username1) .SetArgument(o => o.OrganizationId, organization1.Id) .BuildAndPersist(s); new TestObjectBuilder <ReportEventLog>() .SetArgument(o => o.CreatedByUsername, username1) .SetArgument(o => o.OrganizationId, organization2.Id) .BuildAndPersist(s); new TestObjectBuilder <ReportEventLog>() .SetArgument(o => o.CreatedByUsername, username2) .SetArgument(o => o.OrganizationId, organization2.Id) .BuildAndPersist(s); new UserContextBuilder() .SetUsername(username1) .AddClaims(TestHelper.GetOrganizationClaims(username1, new OrganizationUser[0])) .SetCurrentPrincipal(); }); var result = NsbWebTest.Act(AssemblySetupFixture.WebTestContainer, c => c.GetInstance <IReportEventLogQueryService>() .SearchReportEventLog(new ReportEventLogSearchTerms())); result.Should().NotBeNull(); result.Items.Length.Should().Be(0); }
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 void GetMyOrganizations_For_User_Should_Return_CorrectResult(OrganizationType organizationType) { var username = DataProvider.Get <string>(); var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { var reportingFrequency = ReportingFrequency.Monthly; var organizations = IntegrationTestOrganizationHelper.SetupOrzanizations( stateReportingFrequency: reportingFrequency, zoneReportingFrequency: ReportingFrequency.Monthly); var state = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.NswState).Value; var unit = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.Footscray).Value; var organizationUser1 = new TestObjectBuilder <OrganizationUser>() .SetArgument(o => o.Username, username) .SetArgument(o => o.Organization, organizationType == OrganizationType.State? state : unit) .BuildAndPersist(s); new UserContextBuilder() .SetUsername(username) .AddClaims(TestHelper.GetOrganizationClaims(username, new[] { organizationUser1 })) .SetCurrentPrincipal(); return(new { state, unit }); }); var result = NsbWebTest.Act(AssemblySetupFixture.WebTestContainer, c => c.GetInstance <OrganizationQueryService>() .GetMyOrganizations()); var organizationId = organizationType == OrganizationType.State ? testParams.state.Id : testParams.unit.Id; result.Should().NotBeNull(); result.Where(o => o.Id == organizationId).Should().NotBeNull(); }
public void SearchReportEventLog_Should_Return_Result() { var username = DataProvider.Get <string>(); var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { EntityReference organization1 = new OrganizationBuilder().BuildAndPersist(s); EntityReference organization2 = new OrganizationBuilder().BuildAndPersist(s); var organizationUser1 = new TestObjectBuilder <OrganizationUser>() .SetArgument(o => o.Username, username) .SetArgument(o => o.Organization, organization1) .BuildAndPersist(s); var reportEventLog = new TestObjectBuilder <ReportEventLog>() .SetArgument(o => o.CreatedByUsername, username) .SetArgument(o => o.OrganizationId, organization1.Id) .BuildAndPersist(s); new TestObjectBuilder <ReportEventLog>() .SetArgument(o => o.CreatedByUsername, username) .SetArgument(o => o.OrganizationId, organization2.Id) .BuildAndPersist(s); new UserContextBuilder() .SetUsername(username) .AddClaims(TestHelper.GetOrganizationClaims(username, new [] { organizationUser1 })) .SetCurrentPrincipal(); return(new { reportEventLog, organizationUser1 }); }); var result = NsbWebTest.Act(AssemblySetupFixture.WebTestContainer, c => c.GetInstance <IReportEventLogQueryService>() .SearchReportEventLog(new ReportEventLogSearchTerms())); result.Should().NotBeNull(); result.Items.Length.Should().Be(1); result.Items[0].CreatedByUsername.Should().Be(testParams.organizationUser1.Username); result.Items[0].OrganizationId.Should().Be(testParams.organizationUser1.Organization.Id); }
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_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_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 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_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_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 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 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); }