Example #1
0
        public static Iban Create(string countryCode, string checkDigits, string bban, IbanValidationLevels levels)
        {
            var parts = IbanParts.Create(countryCode, checkDigits, bban);

            IbanValidator.TryValidate(parts, levels)
            .OnError(err => { throw new ArgumentException(err); });

            return(new Iban(parts, levels));
        }
        public static void Validate3()
        {
            var value = "AL47212110090000000235698741";

            Assert.Throws <NotImplementedException>(
                () => IbanValidator.Validate(ParseFast(value), IbanValidationLevels.Bban));
            Assert.Throws <NotImplementedException>(
                () => IbanValidator.TryValidate(ParseFast(value), IbanValidationLevels.Bban));
        }
        public static void Validate4(string value)
        {
            Assert.False(IbanValidator.Validate(ParseFast(value), IbanValidationLevels.Integrity));

            var result = IbanValidator.TryValidate(ParseFast(value), IbanValidationLevels.Integrity);

            Assert.True(result.IsError);

#if !NO_INTERNALS_VISIBLE_TO
            result.OnError(err => Assert.Equal(Format.Current(Strings.IbanIntegrityCheckFailure, value), err));
#endif
        }
Example #4
0
        public static Iban?CheckIntegrity(Iban iban)
        {
            if (iban.VerificationLevels.Contains(IbanValidationLevels.Integrity))
            {
                return(iban);
            }
            if (!IbanValidator.VerifyIntegrity(iban._parts))
            {
                return(null);
            }

            return(new Iban(iban._parts, iban.VerificationLevels | IbanValidationLevels.Integrity));
        }
Example #5
0
        public static Outcome <Iban> TryParse(string value, IbanStyles styles, IbanValidationLevels levels)
        {
            if (value == null)
            {
                return(Outcome <Iban> .FromError(Format.Current(Strings.InvalidIbanValue, value)));
            }

            string input = PreprocessInput(value, styles);

            return(from val in IbanParts.TryParse(input)
                   where IbanValidator.TryValidate(val, levels)
                   select new Iban(val, levels));
        }
        public static void Validate5(string value)
        {
            Assert.False(IbanValidator.Validate(ParseFast(value), IbanValidationLevels.ISOCountryCode));

            var parts  = ParseFast(value);
            var result = IbanValidator.TryValidate(parts, IbanValidationLevels.ISOCountryCode);

            Assert.True(result.IsError);

#if !NO_INTERNALS_VISIBLE_TO
            result.OnError(err => Assert.Equal(Format.Current(Strings.UnknownISOCountryCode, parts.CountryCode), err));
#endif
        }
Example #7
0
        public static Iban?Parse(string value, IbanStyles styles, IbanValidationLevels levels)
        {
            if (value == null)
            {
                return(null);
            }

            var val = PreprocessInput(value, styles);

            var parts = IbanParts.Parse(val);

            if (!parts.HasValue)
            {
                return(null);
            }

            if (!IbanValidator.Validate(parts.Value, levels))
            {
                return(null);
            }

            return(new Iban(parts.Value, levels));
        }
 public static void Validate2(string value)
 {
     Assert.True(IbanValidator.Validate(ParseFast(value), IbanValidationLevels.ISOCountryCode));
     Assert.True(IbanValidator.TryValidate(ParseFast(value), IbanValidationLevels.ISOCountryCode).IsSuccess);
 }
 public static void Validate1(string value)
 {
     Assert.True(IbanValidator.Validate(ParseFast(value), IbanValidationLevels.Integrity));
     Assert.True(IbanValidator.TryValidate(ParseFast(value), IbanValidationLevels.Integrity).IsSuccess);
 }