本文整理汇总了C#中Validation.CustomRule方法的典型用法代码示例。如果您正苦于以下问题:C# Validation.CustomRule方法的具体用法?C# Validation.CustomRule怎么用?C# Validation.CustomRule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validation
的用法示例。
在下文中一共展示了Validation.CustomRule方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CustomRuleShouldValidates
public void CustomRuleShouldValidates()
{
var data = new TestData {AString = "any would do"};
var validator = new Validation<TestData>(data);
var result =
validator.CustomRule(p => p.AString, p => p.Contains("would"), "Failed").ReadResults();
Assert.IsTrue(result.IsValid);
Assert.AreEqual(0, result.ValidationResults.Count);
}
示例2: CustomRuleShouldFail
public void CustomRuleShouldFail()
{
var data = new TestData {AString = "any would do"};
var validator = new Validation<TestData>(data);
var result =
validator.CustomRule(p => p.AString, p => p.Contains("not here"), "Failed").ReadResults();
Assert.IsFalse(result.IsValid);
Assert.AreEqual(1, result.ValidationResults.Count);
Assert.AreEqual(result.ValidationResults[0].PropertyName, "AString");
Assert.AreEqual("Failed", result.ValidationResults[0].ErrorMessage);
}