Beispiel #1
0
 public BicFormatException(string message, BicFormatViolation violation, object actual, object expected)
     : base(message)
 {
     ActualObject = actual;
     ExpectedObject = expected;
     FormatViolation = violation;
 }
Beispiel #2
0
        public void BicIsValidWithUnsupportedCountryShouldReturnRightResult()
        {
            BicFormatViolation validationResult = BicFormatViolation.NO_VIOLATION;

            BicUtils.IsValid("DEUTXXFF", out validationResult);

            Assert.AreEqual(BicFormatViolation.COUNTRY_CODE_UNSUPPORTED, validationResult);
        }
Beispiel #3
0
        public void BicIsValidWithInvalidCountryCodeShouldReturnRightResult()
        {
            BicFormatViolation validationResult = BicFormatViolation.NO_VIOLATION;

            BicUtils.IsValid("DEUT_1FF", out validationResult);

            Assert.AreEqual(BicFormatViolation.COUNTRY_CODE_ONLY_UPPER_CASE_LETTERS, validationResult);
        }
Beispiel #4
0
        public void BicIsValidWithInvalidBankCodeShouldReturnRightResult()
        {
            BicFormatViolation validationResult = BicFormatViolation.NO_VIOLATION;

            BicUtils.IsValid("DEU1DEFF", out validationResult);

            Assert.AreEqual(BicFormatViolation.BANK_CODE_ONLY_LETTERS, validationResult);
        }
Beispiel #5
0
        public void BicIsValidWithInvalidBranchCodeShouldReturnRightResult()
        {
            BicFormatViolation validationResult = BicFormatViolation.NO_VIOLATION;

            BicUtils.IsValid("DEUTDEFF50_", out validationResult);

            Assert.AreEqual(BicFormatViolation.BRANCH_CODE_ONLY_LETTERS_OR_DIGITS, validationResult);
        }
Beispiel #6
0
        public void BicIsValidWithMoreCharactersShouldReturnRightResult()
        {
            BicFormatViolation validationResult = BicFormatViolation.NO_VIOLATION;

            BicUtils.IsValid("DEUTFFDEUTFF", out validationResult);

            Assert.AreEqual(BicFormatViolation.BIC_LENGTH_8_OR_11, validationResult);
        }
Beispiel #7
0
        public void BicIsValidWithLowercaseCharactersShouldReturnRightResult()
        {
            BicFormatViolation validationResult = BicFormatViolation.NO_VIOLATION;

            BicUtils.IsValid("DEUTdeFF", out validationResult);

            Assert.AreEqual(BicFormatViolation.BIC_ONLY_UPPER_CASE_LETTERS, validationResult);
        }
Beispiel #8
0
        private static bool hasValidCase(string bic, out BicFormatViolation validationResult)
        {
            validationResult = BicFormatViolation.NO_VIOLATION;

            if (!bic.Equals(bic.ToUpper()))
            {
                validationResult = BicFormatViolation.BIC_ONLY_UPPER_CASE_LETTERS;
            }

            return(validationResult == BicFormatViolation.NO_VIOLATION);
        }
Beispiel #9
0
        private static bool hasValidLength(string bic, out BicFormatViolation validationResult)
        {
            validationResult = BicFormatViolation.NO_VIOLATION;

            if (bic.Length != _BIC8_LENGTH && bic.Length != _BIC11_LENGTH)
            {
                validationResult = BicFormatViolation.BIC_LENGTH_8_OR_11;
            }

            return(validationResult == BicFormatViolation.NO_VIOLATION);
        }
Beispiel #10
0
        private static bool hasValidBranchCode(string bic, out BicFormatViolation validationResult)
        {
            validationResult = BicFormatViolation.NO_VIOLATION;

            string branchCode = GetBranchCode(bic);

            foreach (char c in branchCode.ToCharArray())
            {
                if (!char.IsLetterOrDigit(c))
                {
                    validationResult = BicFormatViolation.BRANCH_CODE_ONLY_LETTERS_OR_DIGITS;
                    break;
                }
            }

            return(validationResult == BicFormatViolation.NO_VIOLATION);
        }
Beispiel #11
0
        private static bool hasValidBankCode(string bic, out BicFormatViolation validationResult)
        {
            validationResult = BicFormatViolation.NO_VIOLATION;

            string bankCode = GetBankCode(bic);

            foreach (char c in bankCode.ToCharArray())
            {
                if (!char.IsLetter(c))
                {
                    validationResult = BicFormatViolation.BANK_CODE_ONLY_LETTERS;
                    break;
                }
            }

            return(validationResult == BicFormatViolation.NO_VIOLATION);
        }
Beispiel #12
0
        /// <summary>
        /// Validation of BIC string
        /// </summary>
        /// <param name="bic">BIC to be validated</param>
        /// <param name="validationResult">Validation result</param>
        /// <returns>True if BIC is valid, false if it encounters any problem</returns>
        public static bool IsValid(string bic, out BicFormatViolation validationResult)
        {
            bool result = false;

            validationResult = BicFormatViolation.NO_VIOLATION;

            if (!string.IsNullOrEmpty(bic))
            {
                if (hasValidLength(bic, out validationResult))
                {
                    if (hasValidCase(bic, out validationResult))
                    {
                        if (hasValidBankCode(bic, out validationResult))
                        {
                            if (hasValidCountryCode(bic, out validationResult))
                            {
                                if (hasValidLocationCode(bic, out validationResult))
                                {
                                    if (HasBranchCode(bic))
                                    {
                                        if (hasValidBranchCode(bic, out validationResult))
                                        {
                                            result = true;
                                        }
                                    }
                                    else
                                    {
                                        result = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                validationResult = BicFormatViolation.BIC_NOT_EMPTY_OR_NULL;
            }

            return(result);
        }
Beispiel #13
0
        private static bool hasValidCountryCode(string bic, out BicFormatViolation validationResult)
        {
            validationResult = BicFormatViolation.NO_VIOLATION;

            string countryCode = GetCountryCode(bic);

            if (countryCode.Trim().Length < _COUNTRY_CODE_LENGTH || !countryCode.Equals(countryCode.ToUpper()) || !Char.IsLetter(countryCode[0]) || !Char.IsLetter(countryCode[1]))
            {
                validationResult = BicFormatViolation.COUNTRY_CODE_ONLY_UPPER_CASE_LETTERS;
            }
            else
            {
                if (CountryCode.GetCountryCode(countryCode) == null)
                {
                    validationResult = BicFormatViolation.COUNTRY_CODE_UNSUPPORTED;
                }
            }

            return(validationResult == BicFormatViolation.NO_VIOLATION);
        }
Beispiel #14
0
        public void BicIsValidWithInvalidBranchCodeShouldReturnFalse()
        {
            BicFormatViolation validationResult = BicFormatViolation.NO_VIOLATION;

            Assert.IsFalse(BicUtils.IsValid("DEUTDEFF50_", out validationResult));
        }
Beispiel #15
0
        public void BicIsValidWithMoreCharactersShouldReturnFalse()
        {
            BicFormatViolation validationResult = BicFormatViolation.NO_VIOLATION;

            Assert.IsFalse(BicUtils.IsValid("DEUTFFDEUTFF", out validationResult));
        }
Beispiel #16
0
        public void BicIsValidWithEmptyStringShouldReturnFalse()
        {
            BicFormatViolation validationResult = BicFormatViolation.NO_VIOLATION;

            Assert.IsFalse(BicUtils.IsValid("", out validationResult));
        }
Beispiel #17
0
 public BicFormatException(string message, BicFormatViolation violation, Exception innerException )
     : base(message, innerException)
 {
     FormatViolation = violation;
 }
Beispiel #18
0
        public void BicIsValidWithUnsupportedCountryShouldReturnFalse()
        {
            BicFormatViolation validationResult = BicFormatViolation.NO_VIOLATION;

            Assert.IsFalse(BicUtils.IsValid("DEUTXXFF", out validationResult));
        }
Beispiel #19
0
 public BicFormatException(string message, BicFormatViolation violation, object actual) : base(message)
 {
     ActualObject    = actual;
     FormatViolation = violation;
 }
Beispiel #20
0
 public BicFormatException(string message, BicFormatViolation violation, Exception innerException) : base(message, innerException)
 {
     FormatViolation = violation;
 }
Beispiel #21
0
 public BicFormatException(string message, BicFormatViolation violation, object actual, object expected) : base(message)
 {
     ActualObject    = actual;
     ExpectedObject  = expected;
     FormatViolation = violation;
 }
Beispiel #22
0
 public BicFormatException(string message, BicFormatViolation violation, object actual )
     : base(message)
 {
     ActualObject = actual;
     FormatViolation = violation;
 }
Beispiel #23
0
        public void BicIsValidWithValidBicShouldReturnTrue()
        {
            BicFormatViolation validationResult = BicFormatViolation.NO_VIOLATION;

            Assert.IsTrue(BicUtils.IsValid("DEUTDEFF500", out validationResult));
        }