コード例 #1
0
        public void TestBatchLoadingRecalculations()
        {
            TVerificationResultCollection VerificationResult;

            Int64        RecipientKey;
            Int64        RealRecipientLedgerNumber;
            Int64        FalseRecipientLedgerNumber;
            const string REALCOSTCENTRECODE  = "4300";
            const string FALSECOSTCENTRECODE = "3500";
            Int32        GiftBatchNumber;

            //
            // Arrange: Create all data needed for this test (Gift Detail has a 'fake' RecipientLedgerNumber and CostCentreCode)
            //
            TestBatchPostingRecalculations_Arrange(out RecipientKey, out RealRecipientLedgerNumber,
                                                   out FalseRecipientLedgerNumber, REALCOSTCENTRECODE, FALSECOSTCENTRECODE, out GiftBatchNumber);

            //
            // Act: Load the batch
            //
            GiftBatchTDS GiftBatchDS = TGiftTransactionWebConnector.LoadAGiftBatchAndRelatedData(FLedgerNumber, GiftBatchNumber);

            //
            // Assert
            //

            // Initial Assert: Tests that the load returns results
            Assert.IsNotNull(GiftBatchDS, "TestBatchLoadingRecalculations fail: Loading GiftBatch failed");
            Assert.IsNotNull(GiftBatchDS.AGiftDetail, "TestBatchLoadingRecalculations fail: Loading GiftBatch failed");

            // Primary Assert: Chaeck that the gift has the correct RecipientLedgerNumber and CostCentreCode
            TDBTransaction Transaction           = null;
            AGiftDetailRow PositiveGiftDetailRow = null;
            AGiftDetailRow NegativeGiftDetailRow = null;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                                                                      TEnforceIsolationLevel.eilMinimum,
                                                                      ref Transaction,
                                                                      delegate
            {
                PositiveGiftDetailRow = AGiftDetailAccess.LoadByPrimaryKey(FLedgerNumber, GiftBatchNumber, 1, 1, Transaction)[0];
                NegativeGiftDetailRow = AGiftDetailAccess.LoadByPrimaryKey(FLedgerNumber, GiftBatchNumber, 2, 1, Transaction)[0];
            });

            Assert.IsNotNull(PositiveGiftDetailRow, "TestBatchPostingRecalculations fail: Obtaining PositiveGiftDetailRow from database failed");
            Assert.IsNotNull(NegativeGiftDetailRow, "TestBatchPostingRecalculations fail: Obtaining NegativeGiftDetailRow from database failed");

            Assert.AreEqual(RealRecipientLedgerNumber, PositiveGiftDetailRow.RecipientLedgerNumber,
                            "TestBatchPostingRecalculations fail: RecipientLedgerNumber for PositiveGiftDetailRow is incorrect");
            Assert.AreEqual(FalseRecipientLedgerNumber, NegativeGiftDetailRow.RecipientLedgerNumber,
                            "TestBatchPostingRecalculations fail: RecipientLedgerNumber for NegativeGiftDetailRow is incorrect");
            Assert.AreEqual(REALCOSTCENTRECODE, PositiveGiftDetailRow.CostCentreCode,
                            "TestBatchPostingRecalculations fail: CostCentreCode for PositiveGiftDetailRow is incorrect");
            Assert.AreEqual(FALSECOSTCENTRECODE, NegativeGiftDetailRow.CostCentreCode,
                            "TestBatchPostingRecalculations fail: CostCentreCode for NegativeGiftDetailRow is incorrect");

            // Cleanup: Delete test records

            bool SubmissionOK = true;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.Serializable,
                                                                  TEnforceIsolationLevel.eilMinimum,
                                                                  ref Transaction,
                                                                  ref SubmissionOK,
                                                                  delegate
            {
                AGiftDetailAccess.DeleteRow(AGiftDetailTable.TableId, PositiveGiftDetailRow, Transaction);
                AGiftDetailAccess.DeleteRow(AGiftDetailTable.TableId, NegativeGiftDetailRow, Transaction);
            });

            TPartnerWebConnector.DeletePartner(RecipientKey, out VerificationResult);
            TPartnerWebConnector.DeletePartner(RealRecipientLedgerNumber, out VerificationResult);
            TPartnerWebConnector.DeletePartner(FalseRecipientLedgerNumber, out VerificationResult);
        }
コード例 #2
0
        public void TestMultipleGifts()
        {
            // import the test gift batch, and post it
            TGiftImporting importer = new TGiftImporting();

            string       dirTestData = "../../csharp/ICT/Testing/lib/MFinance/server/BankImport/";
            string       testFile    = dirTestData + "GiftBatch.csv";
            StreamReader sr          = new StreamReader(testFile);
            string       FileContent = sr.ReadToEnd();

            sr.Close();
            FileContent = FileContent.Replace("2010-09-30", DateTime.Now.Year.ToString("0000") + "-09-30");

            Hashtable parameters = new Hashtable();

            parameters.Add("Delimiter", ",");
            parameters.Add("ALedgerNumber", FLedgerNumber);
            parameters.Add("DateFormatString", "yyyy-MM-dd");
            parameters.Add("NumberFormat", "American");
            parameters.Add("NewLine", Environment.NewLine);
            parameters.Add("DatesMayBeIntegers", false);

            TVerificationResultCollection VerificationResult;
            GiftBatchTDSAGiftDetailTable  NeedRecipientLedgerNumber;
            bool refreshRequired;

            if (!importer.ImportGiftBatches(parameters, FileContent, out NeedRecipientLedgerNumber, out refreshRequired, out VerificationResult))
            {
                Assert.Fail("Gift Batch was not imported: " + VerificationResult.BuildVerificationResultString());
            }

            int BatchNumber = importer.GetLastGiftBatchNumber();

            Assert.AreNotEqual(-1, BatchNumber, "Failed to import gift batch: " + VerificationResult.BuildVerificationResultString());

            Int32 generatedGlBatchNumber;

            if (!TGiftTransactionWebConnector.PostGiftBatch(FLedgerNumber, BatchNumber, out generatedGlBatchNumber, out VerificationResult))
            {
                Assert.Fail("Gift Batch was not posted: " + VerificationResult.BuildVerificationResultString());
            }

            // import the test csv file, will already do the training
            testFile    = dirTestData + "BankStatement.csv";
            sr          = new StreamReader(testFile);
            FileContent = sr.ReadToEnd();
            sr.Close();
            FileContent = FileContent.Replace("30.09.2010", "30.09." + DateTime.Now.Year.ToString("0000"));

            Int32         StatementKey;
            BankImportTDS BankImportDS = TBankStatementImportCSV.ImportBankStatementHelper(
                FLedgerNumber,
                "6200",
                ";",
                "DMY",
                "European",
                "EUR",
                "unused,DateEffective,Description,Amount,Currency",
                "",
                "BankStatementSeptember.csv",
                FileContent);

            Assert.AreNotEqual(null, BankImportDS, "valid bank import dataset september");

            Assert.AreEqual(TSubmitChangesResult.scrOK, TBankStatementImport.StoreNewBankStatement(
                                BankImportDS,
                                out StatementKey), "save statement September");

            // revert the gift batch, so that the training does not get confused if the test is run again;
            // the training needs only one gift batch for that date
            Hashtable requestParams = new Hashtable();

            requestParams.Add("Function", GiftAdjustmentFunctionEnum.ReverseGiftBatch);
            requestParams.Add("ALedgerNumber", FLedgerNumber);
            requestParams.Add("BatchNumber", BatchNumber);
            requestParams.Add("GiftDetailNumber", -1);
            requestParams.Add("GiftNumber", -1);
            requestParams.Add("NewBatchSelected", false);
            requestParams.Add("NoReceipt", true);
            requestParams.Add("NewPct", 0.0m);
            requestParams.Add("UpdateTaxDeductiblePct", new System.Collections.Generic.List <string[]>());
            requestParams.Add("GlEffectiveDate", new DateTime(DateTime.Now.Year, 09, 30));
            requestParams.Add("AutoCompleteComments", false);
            requestParams.Add("ReversalCommentOne", String.Empty);
            requestParams.Add("ReversalCommentTwo", String.Empty);
            requestParams.Add("ReversalCommentThree", String.Empty);
            requestParams.Add("ReversalCommentOneType", String.Empty);
            requestParams.Add("ReversalCommentTwoType", String.Empty);
            requestParams.Add("ReversalCommentThreeType", String.Empty);

            int          AdjustmentBatchNumber;
            bool         BatchIsUnposted;
            GiftBatchTDS GiftReverseDS = TGiftTransactionWebConnector.LoadGiftTransactionsForBatch(FLedgerNumber, BatchNumber, out BatchIsUnposted);

            Assert.AreEqual(true, TAdjustmentWebConnector.GiftRevertAdjust(requestParams, out AdjustmentBatchNumber, GiftReverseDS), "reversing the gift batch");

            if (!TGiftTransactionWebConnector.PostGiftBatch(FLedgerNumber, AdjustmentBatchNumber, out generatedGlBatchNumber, out VerificationResult))
            {
                Assert.Fail("Gift Reverse Batch was not posted: " + VerificationResult.BuildVerificationResultString());
            }

            // duplicate the bank import file, for the next month
            FileContent = FileContent.Replace("30.09." + DateTime.Now.Year.ToString("0000"),
                                              "30.10." + DateTime.Now.Year.ToString("0000"));

            BankImportDS = TBankStatementImportCSV.ImportBankStatementHelper(
                FLedgerNumber,
                "6200",
                ";",
                "DMY",
                "European",
                "EUR",
                "unused,DateEffective,Description,Amount,Currency",
                "",
                "BankStatementOctober.csv",
                FileContent);
            Assert.AreNotEqual(null, BankImportDS, "valid bank import dataset october");

            Assert.AreEqual(TSubmitChangesResult.scrOK, TBankStatementImport.StoreNewBankStatement(
                                BankImportDS,
                                out StatementKey), "save statement October");

            // create gift batch from imported statement
            Int32 GiftBatchNumber;

            TBankImportWebConnector.CreateGiftBatch(
                FLedgerNumber,
                StatementKey,
                out VerificationResult,
                out GiftBatchNumber);

            CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResult,
                                                                                "cannot create gift batch from bank statement:");

            // check if the gift batch is correct
            GiftBatchTDS GiftDS = TGiftTransactionWebConnector.LoadAGiftBatchAndRelatedData(FLedgerNumber, GiftBatchNumber);

            // since we are not able to match the split gifts, only 1 donation should be matched.
            // TODO: allow 2 gifts to be merged in OpenPetra, even when they come separate on the bank statement.
            //           then 4 gifts could be matched.
            Assert.AreEqual(1, GiftDS.AGift.Rows.Count, "expected two matched gifts");
        }