Hello,
I'm having problems with [ObjectValidator]. So, i have:
public class UserBO
{
public int ID
{
get;
set;
}
[NotNullValidator(MessageTemplate = "Can't be null!")]
[RegexValidator(@"[a-z]|[A-Z]|[0-9]*", MessageTemplate = "Must be valid!", Ruleset = "validate_username")]
[StringLengthValidator(5, RangeBoundaryType.Inclusive, 25, RangeBoundaryType.Inclusive, Ruleset = "validate_username")]
public string username
{
get;
set;
}
and another class:
public class PersonBO
{
public int ID
{
get;
set;
}
[NotNullValidator(MessageTemplate="Can't be null!")]
[ObjectValidator(MessageTemplate = "Must be valid!", Ruleset="validate_obj_user")]
public UserBO User
{
get;
set;
}
...
Now can you tell me why the following test passes?
[TestMethod()]
public void PersonBOConstructorTest()
{
PersonBO target = new PersonBO()
{
User = new UserBO
{
ID = 4,
username = "asd"
}
};
ValidationResults vr = Validation.Validate<PersonBO>(target, "validate_obj_user");
Assert.IsTrue(vr.IsValid);
}
This should not be valid, because: User attribute (of UserBO type) contains username "asd" (3 characters), and i defined for it a StringLengthValidator (between 5 and 25 characters).. so why the test passes? that object is not valid I can't understand.
Thanks.