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