Add 'when' condition to the Reference Validator (SPRNET-1370)

This commit is contained in:
bbaia
2010-09-22 09:26:05 +00:00
parent 2086abb67d
commit bc3e560ad3
4 changed files with 81 additions and 11 deletions

View File

@@ -40,7 +40,7 @@ namespace Spring.Validation
StaticListableObjectFactory factory = new StaticListableObjectFactory();
factory.AddObject("validator", new TrueValidator());
ValidatorReference v = new ValidatorReference();
ValidatorReference v = new ValidatorReference("true");
v.ObjectFactory = factory;
v.Name = "validator";
@@ -65,6 +65,21 @@ namespace Spring.Validation
Assert.IsFalse(v.Validate(null, errors));
}
[Test]
public void FalseValidatorReferenceNotEvaluatedBecauseWhenExpressionReturnsFalse()
{
StaticListableObjectFactory factory = new StaticListableObjectFactory();
factory.AddObject("validator", new FalseValidator());
ValidatorReference v = new ValidatorReference("false");
v.ObjectFactory = factory;
v.Name = "validator";
IValidationErrors errors = new ValidationErrors();
Assert.IsTrue(v.Validate(null, null, errors));
Assert.IsTrue(v.Validate(null, errors));
}
[Test]
public void ContextNarrowing()
{
@@ -93,7 +108,13 @@ namespace Spring.Validation
Assert.IsTrue(v2.Validate(context, null, errors));
Assert.IsTrue(v2.Validate(context, errors));
}
ValidatorReference v3 = new ValidatorReference("false");
v3.ObjectFactory = factory;
v3.Name = "cv2";
v3.Context = Expression.Parse("DOB");
Assert.IsTrue(v3.Validate(null, errors));
}
}
}