为什么 NotNullValidator 不起作用?
我正在使用 Microsoft 企业验证。但在这种情况下,即使我为该属性分配空值,测试也会通过。为什么?
[NotNullValidator(MessageTemplate = "Cannot be null!", Ruleset="validate_x")]
[StringLengthValidator(10, RangeBoundaryType.Inclusive, 40, RangeBoundaryType.Inclusive, Ruleset="validate_x")]
[RegexValidator(@"^[A-Z][a-z]*\s[A-Z][a-z]*$", MessageTemplate = "Not valid!", Ruleset="validate_x")]
public string x
{
get;
set;
}
在测试课中:
[TestMethod()]
public void xTest()
{
MyBO target = new MyBO() { x = null };
ValidationResults vr = Validation.Validate<MyBO>(target, "validate_x");
Assert.IsTrue(vr.IsValid);
}
所以我知道这是有效的,但它不应该是。 (x 为空!) 有什么想法吗?
谢谢
I'm using Microsoft Enterprise Validation. But in this case the test passes, even if i assign null value to that attribute. Why?
[NotNullValidator(MessageTemplate = "Cannot be null!", Ruleset="validate_x")]
[StringLengthValidator(10, RangeBoundaryType.Inclusive, 40, RangeBoundaryType.Inclusive, Ruleset="validate_x")]
[RegexValidator(@"^[A-Z][a-z]*\s[A-Z][a-z]*$", MessageTemplate = "Not valid!", Ruleset="validate_x")]
public string x
{
get;
set;
}
And in a test class:
[TestMethod()]
public void xTest()
{
MyBO target = new MyBO() { x = null };
ValidationResults vr = Validation.Validate<MyBO>(target, "validate_x");
Assert.IsTrue(vr.IsValid);
}
So i got that this is valid, but it should not be. (x is null!)
Any ideas?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将您提供的代码复制到简单的控制台应用程序时,我看到
ValidationResults
对象的IsValid
属性变为False
。我认为你在某个地方做错了什么,但这是不可能的,所以只需查看你的代码即可看到这一点。这是我使用的代码:When copying the code you supplied to a simple console application I see the
IsValid
property of theValidationResults
object becomeFalse
. I think you're doing something wrong somewhere, but it is impossible so see this by just looking at your code. Here is the code I used: