示例#1
0
        public int Calculate()
        {
            var numbers = _inputParser1.ParseOrPassToNextInputParserIfNeeded(Input);

            if (!_numberValidator.IsValid(numbers))
            {
                throw new ArgumentException(
                          $"{_numberValidator.ViolatedConditionName}: {string.Join(',', _numberValidator.InvalidNumbers)}");
            }

            ParsedNumbers = _numberFilter.Filter(numbers);

            Result = ParsedNumbers?.Sum() ?? 0;

            return(Result);
        }
示例#2
0
        /// <summary>
        /// Process account number.
        /// </summary>
        /// <param name="accountNumber">Account number.</param>
        /// <returns>Valid number, similar number or invalid number with error mark.</returns>
        public string Process(string accountNumber)
        {
            if (m_NumberValidator.IsValid(accountNumber))
            {
                return(accountNumber);
            }

            var similarValidNumbers = GetSimilarValidNumbers(accountNumber);

            if (similarValidNumbers.Any())
            {
                return(similarValidNumbers.Count() == 1 ? similarValidNumbers.First() : string.Format("{0} AMB", accountNumber));
            }
            else
            {
                var hasWrongDigit = accountNumber.IndexOf('?') >= 0;
                return(string.Format("{0} {1}", accountNumber, hasWrongDigit ? "ILL" : "ERR"));
            }
        }
示例#3
0
        public bool Checkup(string firstname, string surname, string rodnecislo, DateTime dtbirth)
        {
            DateOfBirth = dtbirth;
            bool nameOK = false, surnameOK = false, rodnecisloOK = false;

            if (nameOK = stringValidator.IsValid(firstname))
            {
                FirstName = firstname;
            }
            if (surnameOK = stringValidator.IsValid(surname))
            {
                SurName = surname;
            }
            if (rodnecisloOK = numberValidator.IsValid(rodnecislo, dtbirth))
            {
                RodneCislo = rodnecislo;
            }

            return(nameOK && surnameOK && rodnecisloOK);
        }