public void IbanNet_Strict() { // ReSharper disable once ForCanBeConvertedToForeach for (int i = 0; i < _testData.Count; i++) { _strictValidator.Validate(_testData[i]); } }
/// <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 { })
/// <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)); }
/// <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 { })
public void When_validating_with_unregistered_country_it_should_fail() { IIbanValidator validator = Subject.GetRequiredService <IIbanValidator>(); validator.Validate("DE89370400440532013000").IsValid.Should().BeFalse(); }
public void When_validating_with_registered_country_it_should_pass(string validIban) { IIbanValidator validator = Subject.GetRequiredService <IIbanValidator>(); validator.Validate(validIban).IsValid.Should().BeTrue(); }
/// <inheritdoc /> protected override bool IsValid(PropertyValidatorContext context) { return(context.PropertyValue == null || _ibanValidator.Validate((string)context.PropertyValue).IsValid); }