public void CanCreateValidatorForValidatorAndValidationAttributes() { var validator = PropertyValidationFactory.GetPropertyValidator( typeof(TestObjectWithMultipleSourceValidationAttributesOnProperties), StaticReflection.GetPropertyInfo((TestObjectWithMultipleSourceValidationAttributesOnProperties t) => t.PropertyWithMixedAttributes), "", ValidationSpecificationSource.DataAnnotations | ValidationSpecificationSource.Attributes, new MemberAccessValidatorBuilderFactory()); var invalidResults = validator.Validate( new TestObjectWithMultipleSourceValidationAttributesOnProperties { PropertyWithMixedAttributes = "invalid" }); Assert.IsFalse(invalidResults.IsValid); Assert.AreEqual(2, invalidResults.Count); Assert.IsTrue( invalidResults.Any(vr => vr.Key == "PropertyWithMixedAttributes" && vr.Message == "data annotations-mixed")); Assert.IsTrue( invalidResults.Any(vr => vr.Key == "PropertyWithMixedAttributes" && vr.Message == "vab-mixed")); }
public void InstanceConfiguredWithNullPropertyNameThrows() { PropertyValidationFactory.GetPropertyValidator(typeof(TestObjectWithFailingAttributesOnProperties), null, "", ValidationSpecificationSource.Attributes, new MemberAccessValidatorBuilderFactory()); }
/// <summary> /// Returns the <see cref="Validator"/> represented by the configuration in the <see cref="IValidationIntegrationProxy"/>, linked /// with the integration scenario as necessary. /// </summary> public Validator GetValidator() { return(PropertyValidationFactory.GetPropertyValidator(validatedType, validatedProperty, integrationProxy.Ruleset, integrationProxy.SpecificationSource, integrationProxy.GetMemberValueAccessBuilder())); }
private Validator GetPropertyValidator(Type entityType, PropertyInfo property) { string ruleset = string.Empty; var source = ValidationSpecificationSource.All; var builder = new ReflectionMemberValueAccessBuilder(); return(PropertyValidationFactory.GetPropertyValidator(entityType, property, ruleset, source, builder)); }
public void RequestForValidatorBasedOnAttributesAndConfigurationWithRulesetThroughStaticFacadeReturnsNullIfNoValidationInfomationExistsForProperty() { Validator validator = PropertyValidationFactory.GetPropertyValidator(typeof(TestObjectWithFailingAttributesOnProperties), typeof(TestObjectWithFailingAttributesOnProperties).GetProperty("PropertyWithoutAttributes"), "RuleA", ValidationSpecificationSource.Both, new MemberAccessValidatorBuilderFactory()); Assert.IsNull(validator); }
private Validator CreateValidator(PropertyInfo validatedProperty) { var validator = PropertyValidationFactory.GetPropertyValidator( validatedProperty.ReflectedType, validatedProperty, this.RulesetName ?? string.Empty, this.ValidationSpecificationSource, new FixedPropertyMemberValueAccessBuilder(validatedProperty)); return(validator); }
public void RequestForValidatorBasedOnAttributesWithRulesetAndValidationSpecificationSourceReturnsAppropriateValidator() { Validator validator = PropertyValidationFactory.GetPropertyValidator(typeof(TestObjectWithFailingAttributesOnProperties), typeof(TestObjectWithFailingAttributesOnProperties).GetProperty("FailingProperty1"), "RuleA", ValidationSpecificationSource.Attributes, new MemberAccessValidatorBuilderFactory()); TestObjectWithFailingAttributesOnProperties objectToTest = new TestObjectWithFailingAttributesOnProperties(); objectToTest.FailingProperty1 = "property value"; ValidationResults validationResults = validator.Validate(objectToTest); IList <ValidationResult> resultsList = ValidationTestHelper.GetResultsList(validationResults); Assert.AreEqual(1, resultsList.Count); Assert.AreEqual("message1-RuleA", resultsList[0].Message); }
public void RequestForValidatorBasedOnAttributesAndConfigurationWithRulesetThroughStaticFacadeReturnsAppropriateValidator() { Validator validator = PropertyValidationFactory.GetPropertyValidator(typeof(TestObjectWithFailingAttributesOnProperties), typeof(TestObjectWithFailingAttributesOnProperties).GetProperty("FailingProperty1"), "RuleA", ValidationSpecificationSource.Both, new MemberAccessValidatorBuilderFactory()); TestObjectWithFailingAttributesOnProperties objectToTest = new TestObjectWithFailingAttributesOnProperties(); objectToTest.FailingProperty1 = "property value"; ValidationResults validationResults = validator.Validate(objectToTest); IDictionary <string, ValidationResult> resultsMapping = ValidationTestHelper.GetResultsMapping(validationResults); Assert.AreEqual(3, resultsMapping.Count); Assert.IsTrue(resultsMapping.ContainsKey("message-from-config1-RuleA")); Assert.IsTrue(resultsMapping.ContainsKey("message-from-config2-RuleA")); Assert.IsTrue(resultsMapping.ContainsKey("message1-RuleA")); }