public void Return_True_For_Valid_SortCode_AccountNumber_MOD11_With_Large_And_Negative_Weights() { //Exception 4: // After you have finished the check, ensure that the remainder is the same as the two-digit // checkdigit; the checkdigit for exception 4 is gh from the original account number // assign string sortCode = "774110"; string accountNo = "12335104"; Mock <IModulusWeightRepository> modulusWeightRepository = new Mock <IModulusWeightRepository>(); ModulusWeight modulusWeight = new ModulusWeight { SortCodeStart = 774100, SortCodeEnd = 774599, ModCheck = "MOD11", WeightU = 50, WeightV = 800, WeightW = 60, WeightX = -15, WeightY = -20, WeightZ = 400, WeightA = 20, WeightB = 100, WeightC = -22, WeightD = -111, WeightE = 200, WeightF = 10, WeightG = 70, WeightH = 800, Exception = 999 }; modulusWeightRepository.Setup(x => x.GetBySortCode(sortCode)).Returns(modulusWeight); var modulusCheck = new ModulusCheck(modulusWeightRepository.Object); // act var res = modulusCheck.ModulusCheckValidation(sortCode, accountNo); // assert Assert.AreEqual(true, res.IsCheckValid); Assert.AreEqual(999, res.ExceptionNotProcessed); }
/// <summary> /// Validates the account number as a Type 1 account. Will try to fix any errors in the account number. If not being able to /// fix an incomplete account number an exception will be thrown. /// </summary> /// <param name="clearingNumber">The clearing number should be 4 digits.</param> /// <param name="accountNumber">The account number should be max 7 digits. Will be leftpadded with zeroes if shorter.</param> private static void ValidateType1(string clearingNumber, ref string accountNumber) { // Def. Type 1 Account (BGC: Type 1, Remark 1) // (1) The clearing number should be 4 digits. // (2) The account number should be 7 digits (if less than 7 characters, leftpad with zeroes). // (3) Checksum calculation is made on the clearing number with the exception of the first digit, and seven digits of the actual account number. // Clearing number should be 4 digits if (clearingNumber.Length != 4) { throw new ArgumentException( string.Format("clearingNumber is {0} characters long. Expected 4 characters.", clearingNumber.Length)); } // Account numbers with less than 7 digits should be leftpadded with zeroes. accountNumber = accountNumber.PadLeft(7, '0'); // Acount number should be 7 digits if (accountNumber.Length != 7) { throw new ArgumentException( string.Format("accountNumber is {0} characters long. Expected 7 characters.", accountNumber.Length)); } // Checksum calculation is made on the clearing number with the exception of the first digit, // and seven digits of the actual account number. string checkValue = string.Concat(clearingNumber.Substring(1, 3), accountNumber); if (!ModulusCheck.Mod11(checkValue)) { throw new ArgumentException(string.Format("accountNumber has an invalid checksum (Type 1).")); } }
/// <summary> /// Validates the account number as a Type 4 account. Will try to fix any errors in the account number. If not being able to /// fix an incomplete account number an exception will be thrown. /// </summary> /// <param name="clearingNumber">The clearing number shoukld be 4 digits.</param> /// <param name="accountNumber">The account number should be max 9 characters. Will be leftpadded with zeroes if shorter.</param> private static void ValidateType4(string clearingNumber, ref string accountNumber) { // Def. Type 4 Account (BGC: Type 2, Remark 2) // (1) The clearing number should be 4 digits, and is not a part of the account number. // (2) The account number should be 9 digits (if less than 9 characters, leftpaded with zeroes). // (3) Checksum calculations is made on the last 9 digits in the account number (modulus 11 check). // Clearing number should be 4 digits if (clearingNumber.Length != 4) { throw new ArgumentException( string.Format("clearingNumber is {0} characters long. Expected 4 characters.", clearingNumber.Length)); } // Account numbers with less than 9 digits should be leftpadded with zeroes. accountNumber = accountNumber.PadLeft(9, '0'); if (accountNumber.Length != 9) { throw new ArgumentException( string.Format("accountNumber is {0} characters long. Expected 9 characters.", accountNumber.Length)); } if (!ModulusCheck.Mod11(accountNumber)) { throw new ArgumentException(string.Format("accountNumber has an invalid checksum (Type 4).")); } }
public void Return_False_For_InValid_SortCode_AccountNumber_MOD10() { // assign string sortCode = "774110"; string accountNo = "12135678"; Mock <IModulusWeightRepository> modulusWeightRepository = new Mock <IModulusWeightRepository>(); ModulusWeight modulusWeight = new ModulusWeight { SortCodeStart = 774100, SortCodeEnd = 774599, ModCheck = "MOD10", WeightU = 9, WeightV = 9, WeightW = 9, WeightX = 9, WeightY = 9, WeightZ = 9, WeightA = 2, WeightB = 1, WeightC = 2, WeightD = 1, WeightE = 2, WeightF = 1, WeightG = 9, WeightH = 1, Exception = null }; modulusWeightRepository.Setup(x => x.GetBySortCode(sortCode)).Returns(modulusWeight); var modulusCheck = new ModulusCheck(modulusWeightRepository.Object); // act var res = modulusCheck.ModulusCheckValidation(sortCode, accountNo); // assert Assert.AreEqual(false, res.IsCheckValid); Assert.AreEqual(null, res.ExceptionNotProcessed); }
public void Return_False_For_Valid_SortCode_AccountNumber_MOD11_Exception_4_Reminder_Doesnt_Matche_GH() { //Exception 4: // After you have finished the check, ensure that the remainder is the same as the two-digit // checkdigit; the checkdigit for exception 4 is gh from the original account number // assign string sortCode = "774110"; string accountNo = "12335104"; Mock <IModulusWeightRepository> modulusWeightRepository = new Mock <IModulusWeightRepository>(); ModulusWeight modulusWeight = new ModulusWeight { SortCodeStart = 774100, SortCodeEnd = 774599, ModCheck = "MOD11", WeightU = 5, WeightV = 8, WeightW = 6, WeightX = 2, WeightY = 3, WeightZ = 4, WeightA = 2, WeightB = 1, WeightC = 2, WeightD = 1, WeightE = 2, WeightF = 1, WeightG = 7, WeightH = 8, Exception = 4 }; modulusWeightRepository.Setup(x => x.GetBySortCode(sortCode)).Returns(modulusWeight); var modulusCheck = new ModulusCheck(modulusWeightRepository.Object); // act var res = modulusCheck.ModulusCheckValidation(sortCode, accountNo); // assert Assert.AreEqual(false, res.IsCheckValid); Assert.AreEqual(null, res.ExceptionNotProcessed); }
public void Return_True_For_Valid_SortCode_And_AccountNumber_DBLAL() { // assign string sortCode = "499273"; string accountNo = "12345678"; Mock <IModulusWeightRepository> modulusWeightRepository = new Mock <IModulusWeightRepository>(); ModulusWeight modulusWeight = new ModulusWeight { SortCodeStart = 400000, SortCodeEnd = 500000, ModCheck = "DBLAL", WeightU = 2, WeightV = 1, WeightW = 2, WeightX = 1, WeightY = 2, WeightZ = 1, WeightA = 2, WeightB = 1, WeightC = 2, WeightD = 1, WeightE = 2, WeightF = 1, WeightG = 2, WeightH = 1, Exception = null }; modulusWeightRepository.Setup(x => x.GetBySortCode(sortCode)).Returns(modulusWeight); var modulusCheck = new ModulusCheck(modulusWeightRepository.Object); // act var res = modulusCheck.ModulusCheckValidation(sortCode, accountNo); // assert Assert.AreEqual(true, res.IsCheckValid); Assert.AreEqual(null, res.ExceptionNotProcessed); }
public void Return_False_For_All_Nine_Value_Weights() { // This is to check all max values do not cause exceptions // assign string sortCode = "999999"; string accountNo = "99999999"; Mock <IModulusWeightRepository> modulusWeightRepository = new Mock <IModulusWeightRepository>(); ModulusWeight modulusWeight = new ModulusWeight { SortCodeStart = 999999, SortCodeEnd = 999999, ModCheck = "DBLAL", WeightU = 9, WeightV = 9, WeightW = 9, WeightX = 9, WeightY = 9, WeightZ = 9, WeightA = 9, WeightB = 9, WeightC = 9, WeightD = 9, WeightE = 9, WeightF = 9, WeightG = 9, WeightH = 9, Exception = null }; modulusWeightRepository.Setup(x => x.GetBySortCode(sortCode)).Returns(modulusWeight); var modulusCheck = new ModulusCheck(modulusWeightRepository.Object); // act var res = modulusCheck.ModulusCheckValidation(sortCode, accountNo); // assert Assert.AreEqual(false, res.IsCheckValid); Assert.AreEqual(null, res.ExceptionNotProcessed); }
public void Return_True_For_All_Zero_Value_Weights() { // assign string sortCode = "000000"; string accountNo = "00000000"; Mock <IModulusWeightRepository> modulusWeightRepository = new Mock <IModulusWeightRepository>(); ModulusWeight modulusWeight = new ModulusWeight { SortCodeStart = 100000, SortCodeEnd = 100000, ModCheck = "DBLAL", WeightU = 0, WeightV = 0, WeightW = 0, WeightX = 0, WeightY = 0, WeightZ = 0, WeightA = 0, WeightB = 0, WeightC = 0, WeightD = 0, WeightE = 0, WeightF = 0, WeightG = 0, WeightH = 0, Exception = null }; modulusWeightRepository.Setup(x => x.GetBySortCode(sortCode)).Returns(modulusWeight); var modulusCheck = new ModulusCheck(modulusWeightRepository.Object); // act var res = modulusCheck.ModulusCheckValidation(sortCode, accountNo); // assert Assert.AreEqual(true, res.IsCheckValid); Assert.AreEqual(null, res.ExceptionNotProcessed); }
public void Return_Exception_Not_Processed_For_Exception_Other_Than_4_7() { // assign string sortCode = "499273"; string accountNo = "12345678"; Mock <IModulusWeightRepository> modulusWeightRepository = new Mock <IModulusWeightRepository>(); ModulusWeight modulusWeight = new ModulusWeight { SortCodeStart = 400000, SortCodeEnd = 500000, ModCheck = "DBLAL", WeightU = 2, WeightV = 1, WeightW = 2, WeightX = 1, WeightY = 2, WeightZ = 1, WeightA = 2, WeightB = 1, WeightC = 2, WeightD = 1, WeightE = 2, WeightF = 1, WeightG = 2, WeightH = 1, Exception = 5 }; modulusWeightRepository.Setup(x => x.GetBySortCode(sortCode)).Returns(modulusWeight); var modulusCheck = new ModulusCheck(modulusWeightRepository.Object); // act var res = modulusCheck.ModulusCheckValidation(sortCode, accountNo); // assert Assert.AreEqual(5, res.ExceptionNotProcessed.Value); }
private static void ValidateType1(string clearingNumber, ref string accountNumber) { // Clearing number should be 4 digits if (clearingNumber.Length != 4) { throw new ArgumentException( string.Format("clearingNumber is {0} characters long. Expected 4 characters.", clearingNumber.Length)); } // Acount number should be 7 digits if (accountNumber.Length != 7) { throw new ArgumentException( string.Format("accountNumber is {0} characters long. Expected 7 characters.", accountNumber.Length)); } string checkValue = string.Concat(clearingNumber, accountNumber); if (!ModulusCheck.AccountMod11CheckNo(checkValue)) { throw new ArgumentException(string.Format("accountNumber has an invalid checksum (Type 1).")); } }
public void Return_False_If_Account_No_Is_Null() { // assign var modulusCheck = new ModulusCheck(); // act var res = modulusCheck.ModulusCheckValidation("123456", null); // assert Assert.AreEqual(false, res.IsCheckValid); Assert.AreEqual(false, res.IsAccountNoValid); }
public void Return_False_If_Sort_Code_Is_Null() { // assign var modulusCheck = new ModulusCheck(); // act var res = modulusCheck.ModulusCheckValidation(null, "12345678"); // assert Assert.AreEqual(false, res.IsCheckValid); Assert.AreEqual(false, res.IsSortCodeValid); }
public void Return_False_If_Account_No_Greater_Than_8_Digits() { // assign var modulusCheck = new ModulusCheck(); // act var res = modulusCheck.ModulusCheckValidation("999999", "100000000"); // assert Assert.AreEqual(false, res.IsCheckValid); Assert.AreEqual(null, res.ExceptionNotProcessed); Assert.AreEqual(false, res.IsAccountNoValid); }
public void Return_False_If_Sort_Code_Greater_Than_6_Digits() { // assign var modulusCheck = new ModulusCheck(); // act var res = modulusCheck.ModulusCheckValidation("1000000", "12345678"); //assert Assert.AreEqual(false, res.IsCheckValid); Assert.AreEqual(false, res.IsSortCodeValid); Assert.AreEqual(null, res.ExceptionNotProcessed); }
/// <summary> /// Validates the account number as a Type 5 account. Will try to fix any errors in the account number. If not being able to /// fix an incomplete account number an exception will be thrown. /// </summary> /// <param name="clearingNumber"></param> /// <param name="accountNumber"></param> private static void ValidateType5(string clearingNumber, ref string accountNumber) { // Def. Type 5 Account (BGC: Type 2, Remark 3) // (1) The clearing number should be 4-5 digits, and is not a part of the account number. // (2) The account number should be 7-10 digits (no padding). // (3) Checksum calculations is made on the last 7-10 digits in the account number (modulus 10 check). if (accountNumber.Length > 10 || accountNumber.Length < 7) { throw new ArgumentException( string.Format("accountNumber is {0} characters long. Expected 7-10 characters.", accountNumber.Length)); } if (!ModulusCheck.Mod10(accountNumber)) { throw new ArgumentException(string.Format("accountNumber has an invalid checksum (Type 5).")); } }
internal BankAccountValidationPipeline CreateValidationPipeline(BankAccountDetails bankAccountDetails) { var pipeline = new BankAccountValidationPipeline(); // note - EISCDSortCodeValidationStep does not do anything. pipeline.InitialValidationStep = new EISCDSortCodeValidationStep(bankAccountDetails, pipeline); var currentValidationStep = pipeline.InitialValidationStep; var modulusWeightings = (new VocalinkModulusWeightingData().GetModulusWeightings()); var weightingsForSortCode = modulusWeightings.Where(w => w.SortCodeStart <= bankAccountDetails.SortCode && w.SortCodeEnd <= bankAccountDetails.SortCode); // Create validation pipeline steps according to weightings from Vocalink foreach (var weighting in weightingsForSortCode) { ModulusCheck modulusCheck = null; // Apply Execptions when creating pipeline // Exception 4 - adjust expected result if (4 == weighting.ExceptionNumber) { modulusCheck = new Standard11ModulusCheck(bankAccountDetails, weighting); modulusCheck.ExpectedResult = int.Parse(bankAccountDetails.CombinedNumberDigits[12].ToString() + bankAccountDetails.CombinedNumberDigits[12].ToString()); } else { switch (weighting.ModulusAlgorithmEnum) { case Enums.ModulusAlgorithmEnum.MOD10: modulusCheck = new Standard10ModulusCheck(bankAccountDetails, weighting); break; case Enums.ModulusAlgorithmEnum.MOD11: modulusCheck = new Standard11ModulusCheck(bankAccountDetails, weighting); break; case Enums.ModulusAlgorithmEnum.DBLAL: modulusCheck = new DoubleAlternateModulusCheck(bankAccountDetails, weighting); break; } } // Excpetion 7 - if g=9 then zeroise u-b if (7 == weighting.ExceptionNumber) { if (9 == bankAccountDetails.CombinedNumberDigits[12]) { for (int i = 0; i < 8; i++) { bankAccountDetails.CombinedNumberDigits[i] = 0; } } } // Indicate Exceptions not applied if (weighting.ExceptionNumber.HasValue && (!(weighting.ExceptionNumber == 4 || weighting.ExceptionNumber == 7)) ) { modulusCheck.ValidationDetails = string.Format("Excluded adjustment for Exception {0}", weighting.ExceptionNumber.ToString()); } var validationStep = new ModulusCheckValidationStep(modulusCheck, pipeline); currentValidationStep.NextStep = validationStep; currentValidationStep = validationStep; } return pipeline; }