Example #1
0
 private static string PrintOnlyNumber(AccountNumber accountNumber)
 {
     var numberPart = "";
     var digits = accountNumber.Digits;
     if (digits.Any())
         numberPart = string.Join("", digits.Select(PrintSingleDigit()).ToArray());
     return numberPart;
 }
Example #2
0
        public static string PrintNumberRepresentation(AccountNumber accountNumber)
        {
            if (accountNumber == null)
                return "";

            var number = PrintOnlyNumber(accountNumber);
            var suffix = PrintSuffixPart(accountNumber, number);
            var result = string.Format("{0} {1}", number, suffix).TrimEnd();

            return result;
        }
Example #3
0
        public static int CalculateChecksum(AccountNumber accountNumber)
        {
            var factor = 1;
            var checksum = 0;
            foreach (var digit in accountNumber.Digits.Reverse())
            {
                checksum += factor * digit.Value;
                factor++;
            }

            return checksum;
        }
Example #4
0
 private static string PrintSuffixPart(AccountNumber accountNumber, string result)
 {
     if (result.Contains(IllegalDigitMark))
         return IllegalSuffix;
     else
     {
         var checksum = ChecksumCalculator.CalculateChecksum(accountNumber);
         var checksumValid = ChecksumValidator.IsChecksumValid(checksum);
         if (!checksumValid)
             return ErrorSuffix;
     }
     return "";
 }