Пример #1
0
        public void ValidateTest()
        {
            IbanValidator v = new IbanValidator();

            Assert.IsFalse(v.Validate("222223600001111111111"));
            Assert.IsFalse(v.Validate("HR223600001111111111"));
            Assert.IsTrue(v.Validate("HR2223600001111111111"));
        }
Пример #2
0
        public void Given_iban_with_valid_national_check_digits_when_validating_it_should_validate(string ibanWithNationalCheckDigits)
        {
            string countryCode = ibanWithNationalCheckDigits.Substring(0, 2);

            // Act
            ValidationResult result = _validator.Validate(ibanWithNationalCheckDigits);

            // Assert
            result.Should().BeEquivalentTo(new ValidationResult
            {
                AttemptedValue = ibanWithNationalCheckDigits,
                Country        = _validator.SupportedCountries[countryCode]
            });
        }
Пример #3
0
        static void Main()
        {
            Console.WriteLine("1. Validate using Library");
            Console.WriteLine("2. Validate using regex");
            string input = Console.ReadLine();

            Console.WriteLine("enter IBAN");
            string IBAN = Console.ReadLine();

            if (input == "1")
            {
                IIbanValidator   validator        = new IbanValidator();
                ValidationResult validationResult = validator.Validate(IBAN);
                if (validationResult.IsValid)
                {
                    Console.WriteLine("IBAN is valid");
                }
                else if (!validationResult.IsValid)
                {
                    Console.WriteLine("IBAN is invalid");
                }
            }

            if (input == "2")
            {
                if (CheckIBAN(IBAN))
                {
                    Console.WriteLine("IBAN is valid");
                }
                else
                {
                    Console.WriteLine("IBAN is invalid");
                }
            }
        }
        public override bool IsValid(object value)
        {
            if (value == null)
            {
                return(true);
            }

            var valueAsAString = value as string;

            if (valueAsAString == null)
            {
                return(true);
            }

            var validator = new IbanValidator();

            var ibanWithoutWhitespace = Regex.Replace(valueAsAString, @"\s+", "");

            var ibanValidationResult = validator.Validate(ibanWithoutWhitespace);

            if (ibanValidationResult == IbanValidationResult.IsValid)
            {
                return(true);
            }

            return(false);
        }
    protected override ValidationResult IsValid(object value, ValidationContext validationContext)
    {
        ErrorMessageTranslationService errorTranslation = validationContext.GetService(typeof(ErrorMessageTranslationService)) as ErrorMessageTranslationService;

        return(IbanValidator.Validate(value as string)
                ? ValidationResult.Success
                : new ValidationResult(errorTranslation.GetLocalizedError(_errorMessage)));
    }
Пример #6
0
        public void Iban_Should_Be_Valid_With_Spaces(string country, string iban)
        {
            // Assert
            var validator = new IbanValidator();

            // Act
            var result = validator.Validate(iban);

            // Assert
            Assert.That(IbanValidationResult.IsValid, Is.EqualTo(result));
        }
Пример #7
0
        public void It_should_return_valid_when_a_valid_foreign_value_is_provided()
        {
            // Assert
            const string value     = "GB82WEST12345698765432";
            var          validator = new IbanValidator();

            // Act
            var result = validator.Validate(value);

            // Assert
            Assert.That(IbanValidationResult.IsValid, Is.EqualTo(result));
        }
Пример #8
0
        public void It_should_return_valid_when_a_valid_value_is_provided()
        {
            // Assert
            const string value     = "BE18001654923565";
            var          validator = new IbanValidator();

            // Act
            var result = validator.Validate(value);

            // Assert
            Assert.That(IbanValidationResult.IsValid, Is.EqualTo(result));
        }
Пример #9
0
        public void It_should_return_an_error_when_an_unkown_country_prefix_used()
        {
            // Assert
            const string value     = "XX82WEST12345698765432";
            var          validator = new IbanValidator();

            // Act
            var result = validator.Validate(value);

            // Assert
            Assert.That(IbanValidationResult.CountryCodeNotKnown, Is.EqualTo(result));
        }
Пример #10
0
        public void It_should_return_an_error_when_there_is_no_value_provided()
        {
            // Assert
            const string value     = null;
            var          validator = new IbanValidator();

            // Act
            var result = validator.Validate(value);

            // Assert
            Assert.That(IbanValidationResult.ValueMissing, Is.EqualTo(result));
        }
Пример #11
0
        public void It_should_return_an_error_when_the_value_fails_the_module_check()
        {
            // Assert
            const string value     = "BE18001654923566";
            var          validator = new IbanValidator();

            // Act
            var result = validator.Validate(value);

            // Assert
            Assert.That(IbanValidationResult.ValueFailsModule97Check, Is.EqualTo(result));
        }
Пример #12
0
    public void It_should_return_an_error_when_there_is_no_value_provided()
    {
        // Assert
            const string value = "";
            var validator = new IbanValidator();

            // Act
            var result = validator.Validate(value);

            // Assert
            Assert.Equal(ValidationResult.ValueMissing, result);
    }
Пример #13
0
        public void It_should_return_an_error_when_there_is_only_whitespace()
        {
            // Assert
            const string value     = "   ";
            var          validator = new IbanValidator();

            // Act
            var result = validator.Validate(value);

            // Assert
            Assert.That(IbanValidationResult.ValueMissing, Is.EqualTo(result));
        }
Пример #14
0
    public void It_should_return_an_error_when_the_value_length_is_to_short()
    {
        // Assert
        const string value     = "BE1800165492356";
        var          validator = new IbanValidator();

        // Act
        var result = validator.Validate(value);

        // Assert
        Assert.Equal(ValidationResult.ValueTooSmall, result);
    }
Пример #15
0
    public void It_should_return_an_error_when_the_value_fails_the_module_check()
    {
        // Assert
            const string value = "BE18001654923566";
            var validator = new IbanValidator();

            // Act
            var result = validator.Validate(value);

            // Assert
            Assert.Equal(ValidationResult.ValueFailsModule97Check, result);
    }
Пример #16
0
    public void It_should_return_valid_when_a_valid_foreign_value_is_provided()
    {
        // Assert
            const string value = "GB82WEST12345698765432";
            var validator = new IbanValidator();

            // Act
            var result = validator.Validate(value);

            // Assert
            Assert.Equal(ValidationResult.IsValid, result);
    }
Пример #17
0
    public void It_should_return_an_error_when_the_value_length_is_to_short()
    {
        // Assert
            const string value = "BE1800165492356";
            var validator = new IbanValidator();

            // Act
            var result = validator.Validate(value);

            // Assert
            Assert.Equal(ValidationResult.ValueTooSmall, result);
    }
Пример #18
0
    public void It_should_return_an_error_when_an_unkown_country_prefix_used()
    {
        // Assert
            const string value = "XX82WEST12345698765432";
            var validator = new IbanValidator();

            // Act
            var result = validator.Validate(value);

            // Assert
            Assert.Equal(ValidationResult.CountryCodeNotKnown, result);
    }
Пример #19
0
        public void It_should_return_an_error_when_the_value_length_is_to_big()
        {
            // Assert
            const string value     = "BE180016549235656";
            var          validator = new IbanValidator();

            // Act
            var result = validator.Validate(value);

            // Assert
            Assert.That(IbanValidationResult.ValueTooBig, Is.EqualTo(result));
        }
Пример #20
0
        public void IbanValidator_Validator()
        {
            IbanValidator testSubject = new IbanValidator("message {0}", "tag", false);
            string        input       = this.TestContext.DataRow["AccountNumber"].ToString();
            bool          expected    = Convert.ToBoolean(this.TestContext.DataRow["IsValid"]);

            EntLib.ValidationResults results = testSubject.Validate(input);
            Assert.AreEqual(expected, results.IsValid, input);

            testSubject = new IbanValidator("message {0}", "tag", true);
            results     = testSubject.Validate(input);
            Assert.AreEqual(!expected, results.IsValid, input);
        }
Пример #21
0
        public static bool ValidateIBAN(string IBANValue)
        {
            IIbanValidator   validator        = new IbanValidator();
            ValidationResult validationResult = validator.Validate(IBANValue);

            if (validationResult.IsValid)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public override string this[string columnName]
        {
            get
            {
                if (columnName == "Name" && string.IsNullOrWhiteSpace(Name))
                {
                    return("Artist name is required!");
                }
                if (columnName == "Phone" && (Phone.Length < 8 || !new PhoneAttribute().IsValid(Phone)))
                {
                    return("the specified phone number is incorrect!");
                }
                if (columnName == "Email")
                {
                    if (string.IsNullOrWhiteSpace(Email))
                    {
                        return("Email is a required field!");
                    }
                    else
                    {
                        var task = ValidateMail.MailIsValidAsync(Email);
                        task.Wait();
                        if (!task.Result)
                        {
                            return("the specified Email is incorrect!");
                        }
                    }
                }
                if (columnName == "BankAccountNo")
                {
                    IIbanValidator           validator        = new IbanValidator();
                    IbanNet.ValidationResult validationResult = validator.Validate(BankAccountNo);

                    if (string.IsNullOrWhiteSpace(BankAccountNo))
                    {
                        return("IBAN is a required field!");
                    }
                    else if (!validationResult.IsValid)
                    {
                        return("the specified IBAN is incorrect!");
                    }
                }
                return("");
            }
        }
Пример #23
0
        public override bool IsValid(object value)
        {
            var ibanValidator = new IbanValidator();

            return(ibanValidator.Validate((string)value).IsValid);
        }
Пример #24
0
    public void It_should_return_valid_when_a_valid_value_is_provided()
    {
        // Assert
            const string value = "BE18001654923565";
            var validator = new IbanValidator();

            // Act
            var result = validator.Validate(value);

            // Assert
            Assert.Equal(ValidationResult.IsValid, result);
    }