Exemplo n.º 1
0
 public void IbanNet_Strict()
 {
     // ReSharper disable once ForCanBeConvertedToForeach
     for (int i = 0; i < _testData.Count; i++)
     {
         _strictValidator.Validate(_testData[i]);
     }
 }
Exemplo n.º 2
0
        /// <inheritdoc />
        protected override System.ComponentModel.DataAnnotations.ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value is null)
            {
                return(System.ComponentModel.DataAnnotations.ValidationResult.Success);
            }

            if (!(value is string strValue))
            {
                return(base.IsValid(value, validationContext));
            }

            IIbanValidator   ibanValidator = GetValidator(validationContext);
            ValidationResult result        = ibanValidator.Validate(strValue);

            if (result.IsValid)
            {
                return(System.ComponentModel.DataAnnotations.ValidationResult.Success);
            }

            validationContext.Items.Add("Error", result.Error);

            IEnumerable <string>?memberNames = null;

            if (validationContext.MemberName is { })
Exemplo n.º 3
0
        /// <inheritdoc />
        protected override System.ComponentModel.DataAnnotations.ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value == null)
            {
                return(System.ComponentModel.DataAnnotations.ValidationResult.Success);
            }

            if (!(value is string strValue))
            {
                return(base.IsValid(value, validationContext));
            }

            IIbanValidator   ibanValidator = GetValidator(validationContext);
            ValidationResult result        = ibanValidator.Validate(strValue);

            if (result.Result == IbanValidationResult.Valid)
            {
                return(System.ComponentModel.DataAnnotations.ValidationResult.Success);
            }

            IEnumerable <string> memberNames = null;

            if (validationContext.MemberName != null)
            {
                memberNames = new[] { validationContext.MemberName };
            }

            return(new System.ComponentModel.DataAnnotations.ValidationResult(FormatErrorMessage(validationContext.DisplayName), memberNames));
        }
Exemplo n.º 4
0
        /// <inheritdoc />
        protected override bool IsValid(PropertyValidatorContext context)
        {
            if (context?.PropertyValue is null)
            {
                return(true);
            }

            ValidationResult result = _ibanValidator.Validate((string)context.PropertyValue);

            if (result.Error is { })
Exemplo n.º 5
0
        public void When_validating_with_unregistered_country_it_should_fail()
        {
            IIbanValidator validator = Subject.GetRequiredService <IIbanValidator>();

            validator.Validate("DE89370400440532013000").IsValid.Should().BeFalse();
        }
Exemplo n.º 6
0
        public void When_validating_with_registered_country_it_should_pass(string validIban)
        {
            IIbanValidator validator = Subject.GetRequiredService <IIbanValidator>();

            validator.Validate(validIban).IsValid.Should().BeTrue();
        }
Exemplo n.º 7
0
 /// <inheritdoc />
 protected override bool IsValid(PropertyValidatorContext context)
 {
     return(context.PropertyValue == null || _ibanValidator.Validate((string)context.PropertyValue).IsValid);
 }