Beispiel #1
0
        public List <AccountNumber> GetAlternativeNumbers()
        {
            var result = new List <AccountNumber>();
            var digits = new List <Digit>();

            Number.ForEach(x =>
            {
                if (!digits.Any(y => y.DigitValue == x.DigitValue))
                {
                    digits.Add(x);
                }
            });

            var numberAsText = this.ToString().Substring(0, 9);

            foreach (var digit in digits)
            {
                var digitOccurrences  = numberAsText.Count(x => x.ToString() == digit.DigitValue.ToString());
                var alternativeValues = digit.GetAlternativeValues();
                foreach (var newValue in alternativeValues)
                {
                    var digitValueIndex = 0;
                    for (int i = 0; i < digitOccurrences; i++)
                    {
                        digitValueIndex = numberAsText.IndexOf(digit.DigitValue.ToString(), digitValueIndex);

                        var newAccountNumber = new AccountNumber(numberAsText
                                                                 .Remove(digitValueIndex, 1)
                                                                 .Insert(digitValueIndex, newValue.ToString()));

                        if (newAccountNumber.HasValidChecksum() && !result.Any(x => x.Equals(newAccountNumber)))
                        {
                            result.Add(newAccountNumber);
                        }

                        digitValueIndex++;
                    }
                }
            }

            return(result.Distinct().ToList());
        }
Beispiel #2
0
        public void Tests(string accountNumber, bool isValid)
        {
            var account = new AccountNumber(accountNumber);

            Assert.AreEqual(isValid, account.HasValidChecksum());
        }