我一直在与这个问题作斗争,我最初认为这可能与影响我的验证的多态性/继承有关,但我把它缩小到这个......
这是类结构..
public class Employee {
[ObjectValidator(Ruleset = "A")]
public EmployeeName Name { get; set; }
public Employee()
{
Name = new EmployeeName();
}
}
public class EmployeeName
{
[StringLengthValidator(1,20,Ruleset = "A")]
public string First { get; set; }
public string Last { get; set; }
public EmployeeName()
{
First = string.Empty;
Last = string.Empty;
}
}
考试:
[TestFixture]
public class ObjectValidationWithRulesets
{
[Test]
public void wont_validate_with_a_ruleset()
{
var person = new Employee()
{
Name = new EmployeeName()
{
First = string.Empty,
Last = string.Empty
}
};
var ruleSetValidator =
ValidationFactory.CreateValidator<Employee>("A");
var validationResults = ruleSetValidator.Validate(person);
Assert.That(!validationResults.IsValid,
"Validation with rulsets failed");
}
}
如果我删除规则集的内容,则此测试通过。但是一旦应用了规则集,我就无法让对象正确验证。
任何人都可以对此有所了解吗?
干杯,