/// <summary> /// Facilitates Registering a RuleValidator on the PropertyValidator /// </summary> /// <param name="validator"><see cref="RuleValidator<T, TProperty>"/></param> /// <returns><see cref="IRuleBuilder<T, TProperty>"/></returns> IRuleBuilder <T, TProperty> IRuleBuilder <T, TProperty> .RegisterValidator(RuleValidator <T, TProperty> validator) { validator.Negate = _negate; if (OrNextRule) { _propertyValidator.OrRule(validator); OrNextRule = false; } else { _propertyValidator.AndRule(validator); } return(this); }
public void Validate_OptionalProperty_WithNoValue_IsValid() { var emptyContact = new Contact(); emptyContact.FirstName = string.Empty; emptyContact.LastName = string.Empty; var propertyValidator = new PropertyValidator<Contact, string>(contact => contact.LastName); //add a single rule var lengthValidator = new LengthBetween<Contact>(1, 5); propertyValidator.AndRule(lengthValidator); //.Rules.Add(lengthValidator); var notification = new ValidationNotification(); //Validate var result = propertyValidator.Validate(emptyContact, null, notification); Assert.That(result, Is.True); Assert.That(notification.Errors, Is.Empty); }
public void Validate_OptionalProperty_WithNoValue_IsValid() { var emptyContact = new Contact(); emptyContact.FirstName = string.Empty; emptyContact.LastName = string.Empty; var propertyValidator = new PropertyValidator <Contact, string>(contact => contact.LastName); //add a single rule var lengthValidator = new LengthBetween <Contact>(1, 5); propertyValidator.AndRule(lengthValidator); //.Rules.Add(lengthValidator); var notification = new ValidationNotification(); //Validate var result = propertyValidator.Validate(emptyContact, null, notification); Assert.That(result, Is.True); Assert.That(notification.Errors, Is.Empty); }
public void Validate_Property_With_PropertyNameOverrideExpression_IsValid() { var emptyContact = new Contact(); emptyContact.FirstName = "George's last name"; emptyContact.LastName = string.Empty; var propertyValidator = new PropertyValidator <Contact, string>(contact => contact.LastName); propertyValidator.PropertyNameOverrideExpression = new Func <Contact, string>(o => o.FirstName); //add a single rule var lengthValidator = new LengthBetween <Contact>(1, 5); propertyValidator.AndRule(lengthValidator); //Validate ValidationNotification notification = new ValidationNotification(); propertyValidator.Validate(emptyContact, null, notification); Assert.That(notification.Errors, Is.Not.Empty); }
public void Validate_Property_With_PropertyNameOverrideExpression_IsValid() { var emptyContact = new Contact(); emptyContact.FirstName = "George's last name"; emptyContact.LastName = string.Empty; var propertyValidator = new PropertyValidator<Contact, string>(contact => contact.LastName); propertyValidator.PropertyNameOverrideExpression = new Func<Contact, string>( o => o.FirstName); //add a single rule var lengthValidator = new LengthBetween<Contact>(1, 5); propertyValidator.AndRule(lengthValidator); //Validate ValidationNotification notification = new ValidationNotification(); propertyValidator.Validate(emptyContact, null, notification); Assert.That(notification.Errors, Is.Not.Empty); }