public void CanValidateThroughValueAccessValidatorUsingValueAccess() { ValidationProvider validationProvider = new ValidationProvider(); validationProvider.SourceTypeName = typeof(PropertyMappedControlValueAccessFixtureTestClass).AssemblyQualifiedName; MockControl control = new MockControl(); control.Text = "control text"; validationProvider.SetSourcePropertyName(control, "StringProperty"); MockValidator valueValidator = new MockValidator(true, "message"); Validator validator = new ValueAccessValidator(new PropertyMappedControlValueAccess("StringProperty"), valueValidator); ValidationResults validationResults = validator.Validate(validationProvider.GetExistingValidatedControlItem(control)); Assert.IsFalse(validationResults.IsValid); IList <ValidationResult> resultsList = ValidationTestHelper.GetResultsList(validationResults); Assert.AreEqual(1, resultsList.Count); Assert.AreEqual("StringProperty", resultsList[0].Key); Assert.AreEqual("message", resultsList[0].Message); Assert.AreEqual(null, resultsList[0].Tag); Assert.AreSame(validationProvider.GetExistingValidatedControlItem(control), resultsList[0].Target); Assert.AreSame(valueValidator, resultsList[0].Validator); Assert.AreEqual("control text", valueValidator.ValidatedTargets[0]); }
public void ReturnsFailureIfParameterToValidateIsNull() { MockValueAccess valueAccess = new MockValueAccess("value"); MockValidator <object> valueValidator = new MockValidator <object>(false); Validator validator = new ValueAccessValidator(valueAccess, valueValidator); ValidationResults validationResults = validator.Validate(null); Assert.IsFalse(validationResults.IsValid); }
public void ReturnsFailureIfValueValidatorReturnsFailureAndValueValidatorIsInvoked() { object valueToValidate = new object(); MockValueAccess valueAccess = new MockValueAccess(valueToValidate); MockValidator <object> valueValidator = new MockValidator <object>(true); Validator validator = new ValueAccessValidator(valueAccess, valueValidator); ValidationResults validationResults = validator.Validate(this); Assert.IsFalse(validationResults.IsValid); Assert.AreEqual(1, valueValidator.ValidatedTargets.Count); Assert.AreSame(valueToValidate, valueValidator.ValidatedTargets[0]); }
public void CanValidateThroughPropertyAccess() { DerivedTestDomainObject targetToValidate = new DerivedTestDomainObject(); PropertyValueAccess valueAccess = new PropertyValueAccess(typeof(DerivedTestDomainObject).GetProperty("Property2")); MockValidator <object> valueValidator = new MockValidator <object>(false); Validator validator = new ValueAccessValidator(valueAccess, valueValidator); ValidationResults validationResults = validator.Validate(targetToValidate); Assert.IsTrue(validationResults.IsValid); Assert.AreEqual(1, valueValidator.ValidatedTargets.Count); Assert.AreSame(targetToValidate.Property2, valueValidator.ValidatedTargets[0]); }
public void FailureFromValueAccessHasCorrectValidationKey() { string key = new string(new char[0]); object valueToValidate = new object(); MockValueAccess valueAccess = new MockValueAccess(valueToValidate, key); MockValidator <object> valueValidator = new MockValidator <object>(true); Validator validator = new ValueAccessValidator(valueAccess, valueValidator); ValidationResults validationResults = validator.Validate(this); Assert.IsFalse(validationResults.IsValid); IList <ValidationResult> resultsList = ValidationTestHelper.GetResultsList(validationResults); Assert.AreEqual(1, resultsList.Count); Assert.AreEqual(key, resultsList[0].Key); }
private List <Validator> GenerateValidators(DESchemaObjectBase obj) { List <Validator> result = new List <Validator>(); foreach (SchemaPropertyValue pv in obj.Properties) { foreach (Validator v in pv.Validators) { ValueAccessValidator validator = new ValueAccessValidator(new DESchemaPropertyValueAccess(pv), v, pv.Definition.Name); result.Add(validator); } } return(result); }
public void ValueValidatorIsInvokedWithProperlySetObjectToValidateAndCurrentTargetAndKey() { object valueToValidate = new object(); string key = new string(new char[] { 'a', 'b', 'c' }); MockValueAccess valueAccess = new MockValueAccess(valueToValidate, key); MockValidator <object> valueValidator = new MockValidator <object>(true, "message"); Validator validator = new ValueAccessValidator(valueAccess, valueValidator); ValidationResults validationResults = validator.Validate(this); IDictionary <string, ValidationResult> resultsMapping = ValidationTestHelper.GetResultsMapping(validationResults); Assert.AreEqual(1, resultsMapping.Count); Assert.AreSame(this, resultsMapping["message"].Target); Assert.AreSame(key, resultsMapping["message"].Key); Assert.AreEqual(1, valueValidator.ValidatedTargets.Count); Assert.AreSame(valueToValidate, valueValidator.ValidatedTargets[0]); }
protected MemberAccessValidator(ValueAccess valueAccess, Validator valueValidator) : base((string)null, (string)null) { this.valueAccessValidator = new ValueAccessValidator(valueAccess, valueValidator); }
/// <summary> /// <para>Initializes a new instance of the <see cref="MemberAccessValidator{T}"/> class.</para> /// </summary> /// <param name="valueAccess">The <see cref="ValueAccess"/> to use when accessing the /// value of the validated member.</param> /// <param name="valueValidator">The <see cref="Validator"/> to validate the value of the /// validated member.</param> protected MemberAccessValidator(ValueAccess valueAccess, Validator valueValidator) : base(null, null) { this.valueAccessValidator = new ValueAccessValidator(valueAccess, valueValidator); Validator = valueValidator; }