本文整理汇总了C#中Validator.TryValidateProperty方法的典型用法代码示例。如果您正苦于以下问题:C# Validator.TryValidateProperty方法的具体用法?C# Validator.TryValidateProperty怎么用?C# Validator.TryValidateProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validator
的用法示例。
在下文中一共展示了Validator.TryValidateProperty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryValidatePropertyShouldReturnExpectedResult
public void TryValidatePropertyShouldReturnExpectedResult( IComponent instance, int resultCount, bool expected )
{
// arrange
var validator = new Validator();
var context = validator.CreateContext( instance, null );
var results = new List<IValidationResult>();
var value = instance.Site;
validator.For<IComponent>().Property( c => c.Site ).Required();
context.MemberName = "Site";
// act
var actual = validator.TryValidateProperty( value, context, results );
// assert
Assert.Equal( expected, actual );
Assert.Equal( resultCount, results.Count );
}
示例2: TryValidatePropertyShouldReturnTrueForTypeWithoutRules
public void TryValidatePropertyShouldReturnTrueForTypeWithoutRules()
{
// arrange
var instance = new Mock<IComponent>().Object;
var validator = new Validator();
var context = validator.CreateContext( instance, null );
var results = new List<IValidationResult>();
var value = instance.Site;
// act
var valid = validator.TryValidateProperty( value, context, results );
// assert
Assert.True( valid );
Assert.Equal( 0, results.Count );
}
示例3: TryValidationPropertyShouldNotAllowNullContext
public void TryValidationPropertyShouldNotAllowNullContext()
{
// arrange
IValidationContext context = null;
var validator = new Validator();
// act
var ex = Assert.Throws<ArgumentNullException>( () => validator.TryValidateProperty( null, context, null ) );
// assert
Assert.Equal( "validationContext", ex.ParamName );
}