public string Verify() { string messages = ""; messages += LengthCheck.CheckLength("Header Record Type", HeaderRecordType, HEADER_RECORD_TYPE_LENGTH); messages += ExpectedString.CheckString("Header Record Type", HeaderRecordType, new string[] { HEADER_RECORD_TYPE }); messages += LengthCheck.CheckLength("Header Service Class", HeaderServiceClass, HEADER_SERVICE_CLASS_LENGTH); messages += ExpectedString.CheckString("Header Service Class", HeaderServiceClass, SERVICE_CLASS_CODES); messages += LengthCheck.CheckLength("Header Company Name", HeaderCompanyName, COMPANY_NAME_LENGTH); messages += LengthCheck.CheckLength("Company Discretionary Data", CompanyDiscretionary, COMPANY_DISCRETIONARY_DATA_LENGTH); messages += LengthCheck.CheckLength("Header Company Identification", HeaderCompanyIdentification, HCOMPANY_IDENTIFICATION_LENGTH); messages += LengthCheck.CheckLength("Standard Entry", StandardEntry, STANDARD_ENTRY_LENGTH); messages += ExpectedString.CheckString("Standard Entry", StandardEntry, STANDARD_ENTRY_CODES); messages += LengthCheck.CheckLength("Company Entry", CompanyEntry, COMPANY_ENTRY_LENGTH); messages += LengthCheck.CheckLength("Company Description", CompanyDescriptionDate, COMPANY_DESCRIPTION_DATE_LENGTH); messages += LengthCheck.CheckLength("Effective Entry Date", EffectiveEntryDate, EFFECTIVE_ENTRY_DATE_LENGTH); messages += LengthCheck.CheckLength("Settlement Date", SettlementDate, SETTLEMENT_DATE_LENGTH); messages += LengthCheck.CheckLength("Originator Status", OriginatorStatus, ORIGINATOR_STATUS_LENGTH); messages += LengthCheck.CheckLength("Header Originator DFI", HeaderOriginatorDFI, HEADER_ORIGINATOR_DFI_LENGTH); messages += LengthCheck.CheckLength("Header Batch Number", HeaderBatchNumber, HEADER_BATCH_NUMBER_LENGTH); messages += LengthCheck.CheckLength("Control Record Type", ControlRecordType, CONTROL_RECORD_TYPE_LENGTH); messages += ExpectedString.CheckString("Control Record Type", ControlRecordType, new string[] { CONTROL_RECORD_TYPE }); messages += LengthCheck.CheckLength("Control Service Class", ControlServiceClass, CONTROL_SERVICE_CLASS_LENGTH); messages += ExpectedString.CheckString("Control Service Class", ControlServiceClass, SERVICE_CLASS_CODES); messages += LengthCheck.CheckLength("Entry Count", EntryCount, ENTRY_COUNT_LENGTH); messages += LengthCheck.CheckLength("Entry Hash", EntryHash, ENTRY_HASH_LENGTH); messages += LengthCheck.CheckLength("Total Debit", TotalDebit, TOTAL_DEBIT_LENGTH); messages += LengthCheck.CheckLength("Total Credit", TotalCredit, TOTAL_CREDIT_LENGTH); messages += LengthCheck.CheckLength("Control Batch Number", ControlBatchNumber, CONTROL_BATCH_NUMBER_LENGTH); messages += LengthCheck.CheckLength("Control Company Identification", ControlCompanyIdentification, CCOMPANY_IDENTIFICATION_LENGTH); messages += LengthCheck.CheckLength("Message Authentication", MessageAuthentication, MESSAGE_AUTH_LENGTH); messages += LengthCheck.CheckLength("Reserved", Reserved, RESERVED_LENGTH); messages += LengthCheck.CheckLength("Control Originating DFI", ControlOriginatingDFI, CONTROL_ORIGINATING_DFI_LENGTH); if (!HeaderServiceClass.Equals(ControlServiceClass)) { messages += "\nHeader service class of '" + HeaderServiceClass + "' is different than control service class '" + ControlServiceClass + "'"; } if (!HeaderCompanyIdentification.Equals(ControlCompanyIdentification)) { messages += "\nHeader company ID of '" + HeaderCompanyIdentification + "' is different than control company ID '" + ControlCompanyIdentification + "'"; } if (!HeaderOriginatorDFI.Equals(ControlOriginatingDFI)) { messages += "\nHeader originating DFI of '" + HeaderOriginatorDFI + "' is different than the control originating DFI '" + ControlOriginatingDFI + "'"; } if (!HeaderBatchNumber.Equals(ControlBatchNumber)) { messages += "\nHeader batch number of '" + HeaderBatchNumber + "' is different than the control batch number '" + ControlBatchNumber + "'"; } if (BatchPrinter.PrintHeader(this).Length != 94) { messages += "\nBatch header is not 94 characters long: '" + BatchPrinter.PrintHeader(this) + "'"; } if (BatchPrinter.PrintControl(this).Length != 94) { messages += "\nBatch control footer is not 94 characters long: '" + BatchPrinter.PrintControl(this) + "'"; } int entrySequence = 1; foreach (Entry entry in Entries) { string entryMessage = entry.Verify(); if (!string.IsNullOrEmpty(entryMessage)) { messages += "\n" + entryMessage; } string expectedEntryTrace = GenerateEntryTraceNumber(entrySequence); if (!expectedEntryTrace.Equals(entry.TraceNumber)) { messages += "\nEntry has trace number '" + entry.TraceNumber + "' when '" + expectedEntryTrace + "' was expected: " + EntryPrinter.PrintEntryMembers(entry); } entrySequence++; } int entryCount = 0; if (int.TryParse(EntryCount, out entryCount)) { int actualEntryCount = EntryAddendaCount(); if (entryCount != actualEntryCount) { messages += "\nEntry/Addenda count was '" + EntryCount + "' when '" + actualEntryCount.ToString() + "' was expected"; } } else { messages += "\nEntry count could not be parsed as a number: '" + EntryCount + "'"; } string expectedHash = GenerateHash(); if (!expectedHash.Equals(EntryHash)) { messages += "\nEntry hash is '" + EntryHash + "' when '" + expectedHash + "' was expected"; } string expectedTotalDebit = GenerateTotalDebit(); if (!expectedTotalDebit.Equals(TotalDebit)) { messages += "\nTotal debit is '" + TotalDebit + "' when '" + expectedTotalDebit + "' was expected"; } string expectedTotalCredit = GenerateTotalCredit(); if (!expectedTotalCredit.Equals(TotalCredit)) { messages += "\nTotal credit is '" + TotalCredit + "' when '" + expectedTotalCredit + "' was expected"; } if (!string.IsNullOrEmpty(messages)) { messages = "Errors in batch: " + BatchPrinter.PrintBatchMembers(this) + ": " + messages; } return(messages); }
public string Verify() { string messages = ""; messages += LengthCheck.CheckLength("Header Record Type", HeaderRecordTypeCode, HEADER_RECORD_TYPE_LENGTH); messages += ExpectedString.CheckString("Record Type", HeaderRecordTypeCode, new string[] { HEADER_RECORD_TYPE }); messages += LengthCheck.CheckLength("Priority Code", PriorityCode, PRIORITY_CODE_LENGTH); messages += ExpectedString.CheckString("Priority Code", PriorityCode, new string[] { PRIORITY_CODE_EXPECTED_VALUE }); messages += LengthCheck.CheckLength("Immediate Destination", ImmediateDestination, IMMEDIATE_DESTINATION_LENGTH); messages += LengthCheck.CheckLength("Immediate Origin", ImmediateOrigin, IMMEDIATE_ORIGIN_LENGTH); messages += LengthCheck.CheckLength("File Creation Date", FileCreationDate, FILE_CREATION_DATE_LENGTH); messages += LengthCheck.CheckLength("File Creation Time", FileCreationTime, FILE_CREATION_TIME_LENGTH); messages += LengthCheck.CheckLength("File ID Modifier", FileIdModifier, FILE_ID_MODIFIER_LENGTH); messages += LengthCheck.CheckLength("Record Size", RecordSize, RECORD_SIZE_LENGTH); messages += ExpectedString.CheckString("Record Size", RecordSize, new string[] { RECORD_SIZE_EXPECTED_VALUE }); messages += LengthCheck.CheckLength("Control Record Type Code", ControlRecordTypeCode, CONTROL_RECORD_TYPE_LENGTH); messages += ExpectedString.CheckString("Control Record Type Code", ControlRecordTypeCode, new string[] { CONTROL_RECORD_TYPE }); messages += LengthCheck.CheckLength("Blocking Factor", BlockingFactor, BLOCKING_FACTOR_LENGTH); messages += ExpectedString.CheckString("Blocking Factor", BlockingFactor, new string[] { BLOCKING_FACTOR_EXPECTED_VALUE }); messages += LengthCheck.CheckLength("Format Code", FormatCode, FORMAT_CODE_LENGTH); messages += ExpectedString.CheckString("Format Code", FormatCode, new string[] { FORMAT_CODE_EXPECTED_VALUE }); messages += LengthCheck.CheckLength("Immediate Destination Name", ImmediateDestinationName, IMMEDIATE_DESTINATION_NAME_LENGTH); messages += LengthCheck.CheckLength("Immediate Origin Name", ImmediateOriginName, IMMEDIATE_ORIGIN_NAME_LENGTH); messages += LengthCheck.CheckLength("Reference Code", ReferenceCode, REFERENCE_CODE_LENGTH); messages += LengthCheck.CheckLength("Batch Count", BatchCount, BATCH_COUNT_LEGTH); messages += LengthCheck.CheckLength("Block Count", BlockCount, BLOCK_COUNT_LENGTH); messages += LengthCheck.CheckLength("Entry Addenda Count", EntryAddendaCount, ENTRY_ADDENDA_COUNT_LENGTH); messages += LengthCheck.CheckLength("Entry Hash", EntryHash, ENTRY_HASH_LENGTH); messages += LengthCheck.CheckLength("Total Debit", TotalDebit, TOTAL_DEBIT_LENGTH); messages += LengthCheck.CheckLength("Total Credit", TotalCredit, TOTAL_CREDIT_LENGTH); messages += LengthCheck.CheckLength("Reserved", Reserved, RESERVED_LENGTH); if (ACHPrinter.PrintHeader(this).Length != 94) { messages += "\nACH header is not 94 characters long: '" + ACHPrinter.PrintHeader(this) + "'"; } if (ACHPrinter.PrintControl(this).Length != 94) { messages += "\nACH control footer is not 94 characters long: '" + ACHPrinter.PrintControl(this) + "'"; } foreach (Batch batch in Batches) { string batchMessage = batch.Verify(); if (!ImmediateOrigin.Equals(batch.HeaderCompanyIdentification)) { batchMessage += "\nBatch Company ID '" + batch.HeaderCompanyIdentification + "' doesn't match ACH Immediate Origin '" + ImmediateOrigin + "'"; } if (!ImmediateDestination.Substring(1, 8).Equals(batch.HeaderOriginatorDFI)) { batchMessage += "\nBatch Originator DFI '" + batch.HeaderOriginatorDFI + "' doesn't match ACH Immediate Destination '" + ImmediateDestination + "'"; } if (!string.IsNullOrEmpty(batchMessage)) { messages += "\nErrors in Batch: " + BatchPrinter.PrintBatchMembers(batch) + ": " + batchMessage; } } int batchCountNum = -1; if (int.TryParse(BatchCount, out batchCountNum)) { if (batchCountNum != Batches.Count) { messages += "\nACH value for Batch Count of " + batchCountNum.ToString() + " does not match the actual number of batches of " + Batches.Count.ToString(); } } else { messages += "\nACH Batch Count could not be parsed as an integer"; } int blockCountNum = 0; if (int.TryParse(BlockCount, out blockCountNum)) { int expectedBlockCount = GenerateBlockCount(); if (blockCountNum != expectedBlockCount) { messages += "\nACH block count of " + blockCountNum.ToString() + " did not match expected block count of " + expectedBlockCount.ToString(); } } else { messages += "\nACH block count could not be parsed as an integer"; } int entryCountNum = 0; if (int.TryParse(EntryAddendaCount, out entryCountNum)) { int expectedEntryCount = GenerateEntryAddendaCount(); if (entryCountNum != expectedEntryCount) { messages += "\nACH entry and addenda count of " + entryCountNum.ToString() + " did not match expected count of " + expectedEntryCount.ToString(); } } else { messages += "\nACH entry and addenda count could not be parsed as an integer"; } string expectedEntryHash = GenerateEntryHash(); if (!EntryHash.Equals(expectedEntryHash)) { messages += "\nACH entry hash of '" + EntryHash + "' does not match expected value of '" + expectedEntryHash + "'"; } int totalDebitNum = 0; if (int.TryParse(TotalDebit, out totalDebitNum)) { int expectedTotalDebit = GenerateTotalDebit(); if (totalDebitNum != expectedTotalDebit) { messages += "\nACH total debit was " + totalDebitNum.ToString() + " when the expected value was " + expectedTotalDebit.ToString(); } } else { messages += "\nACH total debit could not be parsed as an integer"; } int totalCreditNum = 0; if (int.TryParse(TotalCredit, out totalCreditNum)) { int expectedTotalCredit = GenerateTotalCredit(); if (totalCreditNum != expectedTotalCredit) { messages += "\nACH total credit was " + totalCreditNum.ToString() + " when the expected value was " + expectedTotalCredit.ToString(); } } else { messages += "\nACH total credit could not be parsed as an integer"; } return(messages); }