public string Generate(string enrollmentNumber)
        {
            if (string.IsNullOrWhiteSpace(enrollmentNumber))
            {
                throw new FormatException(ErrorMessage.INVALID_ENROLLMENT_NUMBER_FORMAT);
            }

            int    decimalCheckDigit = _checkDigitCalculator.Calculate(enrollmentNumber);
            string checkDigit        = _hexadecimalConverter.ConvertToHexadecimal(decimalCheckDigit);

            enrollmentNumber = FormatEnrollmentNumber(enrollmentNumber);

            return($"{enrollmentNumber}-{checkDigit}");
        }
Beispiel #2
0
        public bool Validate(string fullEnrollmentNumber) //TODO: adicionar out de motivo para resultado falso
        {
            if (string.IsNullOrWhiteSpace(fullEnrollmentNumber))
            {
                return(false);
            }

            var splittedEnrNumber = fullEnrollmentNumber.Split('-');

            if (splittedEnrNumber.Length != 2)
            {
                return(false);
            }

            int decimalCheckDigit;

            try
            {
                decimalCheckDigit = _checkDigitCalculator.Calculate(splittedEnrNumber[0].Trim());
            }
            catch (FormatException)
            {
                return(false);
            }

            string checkDigit;

            try
            {
                checkDigit = _hexadecimalConverter.ConvertToHexadecimal(decimalCheckDigit);
            }
            catch (Exception)
            {
                return(false);
            }

            return(checkDigit.Equals(splittedEnrNumber[1].Trim(), StringComparison.OrdinalIgnoreCase));
        }