示例#1
0
        public void AllExceptionNineRowsAreModEleven()
        {
            var modulusWeight     = new ModulusWeightTable(Resources.valacdos);
            var exceptionNineRows = modulusWeight.RuleMappings.Where(rm => rm.Exception == 9).ToList();

            Assert.IsTrue(exceptionNineRows.All(r => r.Algorithm == ModulusAlgorithm.Mod11));
        }
示例#2
0
        public void CanGetRuleMappings()
        {
            var modulusWeight = new ModulusWeightTable(Resources.valacdos);

            Assert.NotNull(modulusWeight.RuleMappings);
            const int numberOfLinesInTheValacdosFile = 1093;

            Assert.AreEqual(numberOfLinesInTheValacdosFile, modulusWeight.RuleMappings.Count());
            Assert.IsInstanceOf <ModulusWeightMapping>(modulusWeight.RuleMappings.ElementAt(0));
        }
示例#3
0
        private static void ValidateModulusCalculator(string sc, string an, bool expectedResult)
        {
            var accountDetails = new AccountDetails(sc, an);
            var modulusWeight  = new ModulusWeightTable(Resources.valacdos);

            accountDetails.WeightMappings = modulusWeight.GetRuleMappings(accountDetails.SortCode);
            var result = new ModulusCalculator().Process(accountDetails);

            Assert.AreEqual(expectedResult, result);
        }
示例#4
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));
        }
        public ModulusCheckExceptionTests()
        {
            var weightLoaderFile = Properties.Resources.valacdos;

            ModulusWeightTable = new ModulusWeightTable(weightLoaderFile);
        }
示例#7
0
        public void ThereAreNoMod10MappingsWithExceptionFive()
        {
            var modulusWeight = new ModulusWeightTable(Resources.valacdos);

            Assert.IsFalse(modulusWeight.RuleMappings.Any(rm => rm.Exception == 5 && rm.Algorithm == ModulusAlgorithm.Mod10));
        }
        public DoubleAlternateModulusCheckTests()
        {
            var weightLoaderFile = Properties.Resources.valacdos;

            ModulusWeightTable = new ModulusWeightTable(weightLoaderFile);
        }
示例#9
0
        public StandardModulusCheckTests()
        {
            var weightLoaderFile = Properties.Resources.valacdos;

            ModulusWeightTable = new ModulusWeightTable(weightLoaderFile);
        }