public void TestDeleteUnit() { DataSet ResponseDS = new PartnerEditTDS(); TVerificationResultCollection VerificationResult; String TextMessage; Boolean CanDeletePartner; PPartnerRow UnitPartnerRow; PUnitRow UnitRow; TSubmitChangesResult result; Int64 PartnerKey; TDataBase db = DBAccess.Connect("TestDeleteUnit"); TPartnerEditUIConnector connector = new TPartnerEditUIConnector(db); PartnerEditTDS MainDS = new PartnerEditTDS(); UnitPartnerRow = TCreateTestPartnerData.CreateNewUnitPartner(MainDS, db); result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult); // check if Unit partner can be deleted (still needs to be possible at this point) CanDeletePartner = TPartnerWebConnector.CanPartnerBeDeleted(UnitPartnerRow.PartnerKey, out TextMessage, db); if (TextMessage.Length > 0) { TLogging.Log(TextMessage); } Assert.IsTrue(CanDeletePartner); // set unit type to Key Ministry which means it is not allowed to be deleted any longer UnitRow = (PUnitRow)MainDS.PUnit.Rows[0]; UnitRow.UnitTypeCode = MPartnerConstants.UNIT_TYPE_KEYMIN; result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult); Assert.AreEqual(TSubmitChangesResult.scrOK, result, "set unit type to " + MPartnerConstants.UNIT_TYPE_KEYMIN); CanDeletePartner = TPartnerWebConnector.CanPartnerBeDeleted(UnitPartnerRow.PartnerKey, out TextMessage, db); if (TextMessage.Length > 0) { TLogging.Log(TextMessage); } Assert.IsTrue(!CanDeletePartner); // now test actual deletion of Unit partner UnitPartnerRow = TCreateTestPartnerData.CreateNewUnitPartner(MainDS, db); PartnerKey = UnitPartnerRow.PartnerKey; result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult); Assert.AreEqual(TSubmitChangesResult.scrOK, result, "create unit record for deletion"); // check if Unit record is being deleted Assert.IsTrue(TPartnerWebConnector.DeletePartner(PartnerKey, out VerificationResult, db)); // check that Unit record is really deleted Assert.IsTrue(!TPartnerServerLookups.VerifyPartner(PartnerKey)); }
public void TestDeletePerson() { DataSet ResponseDS = new PartnerEditTDS(); TVerificationResultCollection VerificationResult; String TextMessage; Boolean CanDeletePartner; PPartnerRow FamilyPartnerRow; PPartnerRow UnitPartnerRow; PPersonRow PersonRow; TSubmitChangesResult result; Int64 PartnerKey; TPartnerEditUIConnector connector = new TPartnerEditUIConnector(); PartnerEditTDS MainDS = new PartnerEditTDS(); // create new family, location and person FamilyPartnerRow = TCreateTestPartnerData.CreateNewFamilyPartner(MainDS); TCreateTestPartnerData.CreateNewLocation(FamilyPartnerRow.PartnerKey, MainDS); PersonRow = TCreateTestPartnerData.CreateNewPerson(MainDS, FamilyPartnerRow.PartnerKey, MainDS.PLocation[0].LocationKey, "Mike", "Mr", 0); result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult); Assert.AreEqual(TSubmitChangesResult.scrOK, result, "create family and person record"); // check if Family partner can be deleted (still needs to be possible at this point) CanDeletePartner = TPartnerWebConnector.CanPartnerBeDeleted(PersonRow.PartnerKey, out TextMessage); if (TextMessage.Length > 0) { TLogging.Log(TextMessage); } Assert.IsTrue(CanDeletePartner); // add a commitment for the person which means the person is not allowed to be deleted any longer UnitPartnerRow = TCreateTestPartnerData.CreateNewUnitPartner(MainDS); PmStaffDataTable CommitmentTable = new PmStaffDataTable(); PmStaffDataRow CommitmentRow = CommitmentTable.NewRowTyped(); CommitmentRow.Key = Convert.ToInt32(TSequenceWebConnector.GetNextSequence(TSequenceNames.seq_staff_data)); CommitmentRow.PartnerKey = PersonRow.PartnerKey; CommitmentRow.StartOfCommitment = DateTime.Today.Date; CommitmentRow.EndOfCommitment = DateTime.Today.AddDays(90).Date; CommitmentRow.OfficeRecruitedBy = UnitPartnerRow.PartnerKey; CommitmentRow.HomeOffice = UnitPartnerRow.PartnerKey; CommitmentRow.ReceivingField = UnitPartnerRow.PartnerKey; CommitmentTable.Rows.Add(CommitmentRow); result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult); Assert.AreEqual(TSubmitChangesResult.scrOK, result, "create unit to be used in commitment"); PmStaffDataAccess.SubmitChanges(CommitmentTable, DBAccess.GDBAccessObj.Transaction); // this should now not be allowed since person record has a commitment linked to it CanDeletePartner = TPartnerWebConnector.CanPartnerBeDeleted(PersonRow.PartnerKey, out TextMessage); if (TextMessage.Length > 0) { TLogging.Log(TextMessage); } Assert.IsTrue(!CanDeletePartner); // now test actual deletion of Person partner FamilyPartnerRow = TCreateTestPartnerData.CreateNewFamilyPartner(MainDS); TCreateTestPartnerData.CreateNewLocation(FamilyPartnerRow.PartnerKey, MainDS); PersonRow = TCreateTestPartnerData.CreateNewPerson(MainDS, FamilyPartnerRow.PartnerKey, MainDS.PLocation[0].LocationKey, "Mary", "Mrs", 0); PartnerKey = PersonRow.PartnerKey; result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult); Assert.AreEqual(TSubmitChangesResult.scrOK, result, "create family and person record to be deleted"); // check if Family record is being deleted Assert.IsTrue(TPartnerWebConnector.DeletePartner(PartnerKey, out VerificationResult)); // check that Family record is really deleted Assert.IsTrue(!TPartnerServerLookups.VerifyPartner(PartnerKey)); }
/// <summary> /// Creates data needed to test posting recalculations /// </summary> /// <param name="ARecipientKey">Partner Key of the recipient.</param> /// <param name="ARealRecipientLedgerNumber">What the RecipientLedgerNumber should be.</param> /// <param name="AFalseRecipientLedgerNumber">What the RecipientLedgerNumber is.</param> /// <param name="ARecurringGiftBatchNumber">Batch Number.</param> private void TestRecurringBatchSubmitRecalculations_Arrange(out long ARecipientKey, out long ARealRecipientLedgerNumber, out long AFalseRecipientLedgerNumber, out Int32 ARecurringGiftBatchNumber) { TVerificationResultCollection VerificationResult; TSubmitChangesResult Result; DataSet ResponseDS; TPartnerEditUIConnector PartnerEditUIUIConnector = new TPartnerEditUIConnector(); GiftBatchTDS MainDS = new GiftBatchTDS(); PartnerEditTDS PartnerEditDS = new PartnerEditTDS(); // this is a family partner in the test database const Int64 DONORKEY = 43005001; // create a new recipient TCreateTestPartnerData.CreateNewFamilyPartner(PartnerEditDS); ARecipientKey = PartnerEditDS.PFamily[0].PartnerKey; // create two new Unit partners TCreateTestPartnerData.CreateNewUnitPartner(PartnerEditDS); TCreateTestPartnerData.CreateNewUnitPartner(PartnerEditDS); AFalseRecipientLedgerNumber = PartnerEditDS.PPartner[0].PartnerKey; ARealRecipientLedgerNumber = PartnerEditDS.PPartner[1].PartnerKey; // create a Gift Destination for family PPartnerGiftDestinationRow GiftDestination = PartnerEditDS.PPartnerGiftDestination.NewRowTyped(true); GiftDestination.Key = TPartnerDataReaderWebConnector.GetNewKeyForPartnerGiftDestination(); GiftDestination.PartnerKey = ARecipientKey; GiftDestination.DateEffective = new DateTime(2011, 01, 01); GiftDestination.FieldKey = ARealRecipientLedgerNumber; PartnerEditDS.PPartnerGiftDestination.Rows.Add(GiftDestination); // Guard Assertions Assert.That(PartnerEditDS.PFamily[0], Is.Not.Null); Assert.That(PartnerEditDS.PPartner[0], Is.Not.Null); Assert.That(PartnerEditDS.PPartner[1], Is.Not.Null); // Submit the new PartnerEditTDS records to the database ResponseDS = new PartnerEditTDS(); Result = PartnerEditUIUIConnector.SubmitChanges(ref PartnerEditDS, ref ResponseDS, out VerificationResult); // Guard Assertion Assert.That(Result, Is.EqualTo( TSubmitChangesResult.scrOK), "SubmitChanges for PartnerEditDS failed: " + VerificationResult.BuildVerificationResultString()); // link unit to Cost Centre DataTable PartnerCostCentreTbl = TGLSetupWebConnector.LoadCostCentrePartnerLinks(FLedgerNumber, 0); DataRow PartnerCostCentreRow = PartnerCostCentreTbl.NewRow(); PartnerCostCentreRow["PartnerKey"] = ARealRecipientLedgerNumber; PartnerCostCentreRow["IsLinked"] = 4300; PartnerCostCentreTbl.Rows.Add(PartnerCostCentreRow); TGLSetupWebConnector.SaveCostCentrePartnerLinks(FLedgerNumber, PartnerCostCentreTbl); // create a new Recurring Gift Batch MainDS = TGiftTransactionWebConnector.CreateARecurringGiftBatch(FLedgerNumber); ARecurringGiftBatchNumber = MainDS.ARecurringGiftBatch[0].BatchNumber; // create a new recurring gifts ARecurringGiftRow RecurringGiftRow = MainDS.ARecurringGift.NewRowTyped(true); RecurringGiftRow.LedgerNumber = FLedgerNumber; RecurringGiftRow.BatchNumber = ARecurringGiftBatchNumber; RecurringGiftRow.DonorKey = DONORKEY; RecurringGiftRow.GiftTransactionNumber = 1; RecurringGiftRow.LastDetailNumber = 1; MainDS.ARecurringGift.Rows.Add(RecurringGiftRow); // create a new RecurringGiftDetail ARecurringGiftDetailRow RecurringGiftDetail = MainDS.ARecurringGiftDetail.NewRowTyped(true); RecurringGiftDetail.LedgerNumber = FLedgerNumber; RecurringGiftDetail.BatchNumber = ARecurringGiftBatchNumber; RecurringGiftDetail.GiftTransactionNumber = 1; RecurringGiftDetail.DetailNumber = 1; RecurringGiftDetail.RecipientLedgerNumber = AFalseRecipientLedgerNumber; RecurringGiftDetail.GiftAmount = 100; RecurringGiftDetail.MotivationGroupCode = "GIFT"; RecurringGiftDetail.MotivationDetailCode = "SUPPORT"; RecurringGiftDetail.RecipientKey = ARecipientKey; MainDS.ARecurringGiftDetail.Rows.Add(RecurringGiftDetail); // Submit the new GiftBatchTDS records to the database Result = TGiftTransactionWebConnector.SaveGiftBatchTDS(ref MainDS, out VerificationResult); // Guard Assertion Assert.That(Result, Is.EqualTo( TSubmitChangesResult.scrOK), "SaveGiftBatchTDS failed: " + VerificationResult.BuildVerificationResultString()); }