/// <summary>
        /// Gets a slightly modified version of the weight item, which takes into consideration exception 7.
        /// </summary>
        /// <param name="weightItem">The weight item.</param>
        /// <remarks>Notations U to B are zeroised for exception 7</remarks>
        public ModulusWeightItem GetExceptionSevenWeightItem(ModulusWeightItem weightItem)
        {
            var modulusWeightItem = weightItem;

            modulusWeightItem.Weight = weightItem.Weight.Select((weight, index) => index < 8 ? 0 : weight).ToArray();
            return(modulusWeightItem);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DoubleAlternateModulusCheck"/> class.
 /// </summary>
 /// <param name="bankAccount">The bank account.</param>
 /// <param name="weightItem">The weight item.</param>
 /// <exception cref="System.InvalidOperationException">Incorrect modulus calcuation type</exception>
 public DoubleAlternateModulusCheck(BankAccount bankAccount, ModulusWeightItem weightItem)
     : base(weightItem, bankAccount)
 {
     if (weightItem.ModulusCalculationType != ModulusCalculationType.DblAl)
     {
         throw new InvalidOperationException("Incorrect modulus calcuation type");
     }
 }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StandardModulusTenCheck"/> class.
 /// </summary>
 /// <param name="weightItem">The weight item.</param>
 public StandardModulusTenCheck(BankAccount bankAccount, ModulusWeightItem weightItem)
     : base(weightItem, bankAccount)
 {
     if (weightItem.ModulusCalculationType != ModulusCalculationType.Mod10)
     {
         throw new InvalidOperationException("Incorrect modulus calcuation type");
     }
 }
Beispiel #4
0
        /// <summary>
        /// Gets the modulus sum.
        /// </summary>
        /// <param name="weightItem"></param>
        /// <returns></returns>
        public override int GetModulusSum(ModulusWeightItem weightItem)
        {
            var sum = 0;

            for (var i = 0; i < 14; i++)
            {
                sum += (int.Parse(BankAccount.ToString()[i].ToString(CultureInfo.InvariantCulture)) * weightItem.Weight[i]);
            }
            return(sum % Modulus);
        }
        /// <summary>
        /// Gets the modulus sum.
        /// </summary>
        /// <param name="weightItem"></param>
        /// <returns></returns>
        public override int GetModulusSum(ModulusWeightItem weightItem)
        {
            var sum = 0;

            for (var i = 0; i < 14; i++)
            {
                var multiplicationResult = (int.Parse(BankAccount.ToString()[i].ToString()) * weightItem.Weight[i]);
                sum += GetIntArray(multiplicationResult).Sum();
            }

            return(sum % Modulus);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ModulusCheck"/> class.
        /// </summary>
        /// <param name="weightItem">The weight item.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">weightItems - Weight items must be provided to perform a standard modulus check</exception>
        /// <exception cref="System.NotImplementedException">Only exceptions 7 and 4 are supported</exception>
        public ModulusCheck(ModulusWeightItem weightItem, BankAccount bankAccount)
        {
            if (bankAccount.ToString().Length != 14)
            {
                throw new ArgumentOutOfRangeException(nameof(bankAccount), "The sort code and account number should be a total of 14 characters in length");
            }

            if (weightItem == null)
            {
                throw new ArgumentOutOfRangeException(nameof(weightItem), "Weight items must be provided to perform a standard modulus check");
            }

            if (weightItem.Exception.HasValue && weightItem.Exception.Value != 7 && weightItem.Exception.Value != 4)
            {
                throw new NotImplementedException("Only exceptions 7 and 4 are supported");
            }

            ModulusWeightItem = weightItem;
            BankAccount       = bankAccount;
        }
        public void FailDoubleAlternateModulusCheck(string sortCode, string accountNumber)
        {
            var account = new BankAccount(sortCode, accountNumber);

            // As exception 6 is not currently supported, the weight item
            // needs to be mocked so that the exception isn't included.
            var modulusWeight = new ModulusWeightItem
            {
                SortCodeStart          = 202700,
                SortCodeEnd            = 203239,
                ModulusCalculationType = ModulusCalculationType.DblAl,
                Weight = new int[] { 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1 }
            };

            var doubleAltCalculator = new DoubleAlternateModulusCheck(account, modulusWeight);

            var modulsCheck = doubleAltCalculator.Process();

            Assert.AreEqual(modulsCheck, ModulusCheckResult.Fail);
        }
Beispiel #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ModulusWeightTable"/> class.
        /// </summary>
        /// <param name="modulusWeightTableFile">The modulus weight table file.</param>
        /// <exception cref="System.ArgumentNullException"></exception>
        public ModulusWeightTable(string modulusWeightTableFile)
        {
            if (string.IsNullOrEmpty(modulusWeightTableFile))
            {
                throw new ArgumentNullException();
            }

            var weightItems = modulusWeightTableFile.Split(new[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);

            if (weightItems == null || !weightItems.Any())
            {
                throw new NullReferenceException("No valid weight items were found");
            }

            ModulusWeightItems = new List <ModulusWeightItem>();

            foreach (var weightItem in weightItems)
            {
                var items = weightItem.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);

                var item = new ModulusWeightItem
                {
                    SortCodeStart          = double.Parse(items.ElementAt(0)),
                    SortCodeEnd            = double.Parse(items.ElementAt(1)),
                    ModulusCalculationType = (ModulusCalculationType)Enum.Parse(typeof(ModulusCalculationType), items.ElementAt(2), true),
                    Exception = items.Count() == 18 ? int.Parse(items.Last()) : (int?)null,
                    Weight    = new int[14]
                };

                for (int i = 0; i < 14; i++)
                {
                    item.Weight[i] = int.Parse(items.ElementAt(i + 3));
                }

                ModulusWeightItems.Add(item);
            }
        }
 /// <summary>
 /// Gets the modulus sum.
 /// </summary>
 /// <returns></returns>
 public abstract int GetModulusSum(ModulusWeightItem weightItem);