public void ValidateExceptionFour(string sortCode, string accountNumber)
        {
            var account = new BankAccount(sortCode, accountNumber);

            var modulusWeight = ModulusWeightTable.GetModulusWeight(account)
                                .FirstOrDefault();

            var mod11Calculator = new StandardModulusElevenCheck(account, modulusWeight);

            var modulsCheck = mod11Calculator.Process();

            Assert.AreEqual(modulsCheck, ModulusCheckResult.Pass);
        }
Exemplo n.º 2
0
        [TestCase("820000", "1")] // Invalid account number length
        public void InvalidBankAccountShouldError(string sortCode, string accountNumber)
        {
            var modulusWeightTable = new ModulusWeightTable(Properties.Resources.valacdos);

            var account = new BankAccount(sortCode, accountNumber);

            var modulusWeight = modulusWeightTable.GetModulusWeight(account)
                                .FirstOrDefault();

            Assert.Throws <ArgumentOutOfRangeException>(
                () => new StandardModulusTenCheck(account, modulusWeight)
                );
        }
        public IHttpActionResult IsAccountValid(string sortCode, string accountNumber)
        {
            var bankAccount = new BankAccount(sortCode.ToString(), accountNumber.ToString());

            try
            {
                var weightTable = new ModulusWeightTable(Properties.Resources.valacdos);

                foreach (var item in weightTable.GetModulusWeight(bankAccount))
                {
                    // Step 1 - Check for modulus 10
                    if (item.ModulusCalculationType == Business.Entities.ModulusCalculationType.Mod10)
                    {
                        if (new StandardModulusTenCheck(bankAccount, item).Process() == Business.Entities.ModulusCheckResult.Fail)
                        {
                            return(Ok(false));
                        }
                    }

                    // Step 2 - Modulus 11
                    else if (item.ModulusCalculationType == Business.Entities.ModulusCalculationType.Mod11)
                    {
                        if (new StandardModulusElevenCheck(bankAccount, item).Process() == Business.Entities.ModulusCheckResult.Fail)
                        {
                            return(Ok(false));
                        }
                    }

                    // Step 3 - Double Alternate
                    else if (item.ModulusCalculationType == Business.Entities.ModulusCalculationType.DblAl)
                    {
                        if (new DoubleAlternateModulusCheck(bankAccount, item).Process() == Business.Entities.ModulusCheckResult.Fail)
                        {
                            return(Ok(false));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error($"Error validating account with parameters: {sortCode},{accountNumber}", ex);
                return(InternalServerError(ex));
            }

            return(Ok(true));
        }