本文整理汇总了C#中ModelStateDictionary.IsValidField方法的典型用法代码示例。如果您正苦于以下问题:C# ModelStateDictionary.IsValidField方法的具体用法?C# ModelStateDictionary.IsValidField怎么用?C# ModelStateDictionary.IsValidField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelStateDictionary
的用法示例。
在下文中一共展示了ModelStateDictionary.IsValidField方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsValidFieldReturnsTrueIfModelStateDoesNotContainErrors
public void IsValidFieldReturnsTrueIfModelStateDoesNotContainErrors()
{
// Arrange
ModelStateDictionary msd = new ModelStateDictionary()
{
{ "foo", new ModelState() { Value = new ValueProviderResult(null, null, null) } }
};
// Act
bool isValid = msd.IsValidField("foo");
// Assert
Assert.True(isValid);
}
示例2: IsValidFieldThrowsIfKeyIsNull
public void IsValidFieldThrowsIfKeyIsNull()
{
// Arrange
ModelStateDictionary msd = new ModelStateDictionary();
// Act & assert
Assert.ThrowsArgumentNull(
delegate { msd.IsValidField(null); }, "key");
}
示例3: IsValidFieldReturnsFalseIfKeyContainsErrors
public void IsValidFieldReturnsFalseIfKeyContainsErrors()
{
// Arrange
ModelStateDictionary msd = new ModelStateDictionary();
msd.AddModelError("foo", "error text");
// Act
bool isValid = msd.IsValidField("foo");
// Assert
Assert.False(isValid);
}
示例4: IsValidFieldReturnsFalseIfDictionaryDoesNotContainKey
public void IsValidFieldReturnsFalseIfDictionaryDoesNotContainKey()
{
// Arrange
ModelStateDictionary msd = new ModelStateDictionary();
// Act
bool isValid = msd.IsValidField("foo");
// Assert
Assert.True(isValid);
}
示例5: IsValidFieldThrowsIfKeyIsNull
public void IsValidFieldThrowsIfKeyIsNull()
{
// Arrange
ModelStateDictionary msd = new ModelStateDictionary();
// Act & assert
ExceptionHelper.ExpectArgumentNullException(
delegate {
msd.IsValidField(null);
}, "key");
}
示例6: InvokingValidateMultipleTimesDoesNotCauseErrorMessagesToBeDuplicated
public void InvokingValidateMultipleTimesDoesNotCauseErrorMessagesToBeDuplicated()
{
// Arrange
RequestFieldValidatorBase.IgnoreUseUnvalidatedValues = true;
var modelStateDictionary = new ModelStateDictionary();
ValidationHelper validationHelper = GetValidationHelper(GetContext(), modelStateDictionary);
// Act
validationHelper.RequireField("foo", "Foo is required.");
validationHelper.RequireField("bar", "Bar is required.");
validationHelper.Validate();
Assert.False(validationHelper.IsValid());
validationHelper.Validate();
validationHelper.Validate();
// Assert
Assert.False(modelStateDictionary.IsValid);
Assert.False(modelStateDictionary.IsValidField("foo"));
Assert.False(modelStateDictionary.IsValidField("bar"));
Assert.Equal("Foo is required.", modelStateDictionary["foo"].Errors.Single());
Assert.Equal("Bar is required.", modelStateDictionary["bar"].Errors.Single());
}
示例7: GetErrorsPopulatesModelStateDictionary
public void GetErrorsPopulatesModelStateDictionary()
{
// Arrange
RequestFieldValidatorBase.IgnoreUseUnvalidatedValues = true;
var modelStateDictionary = new ModelStateDictionary();
ValidationHelper validationHelper = GetValidationHelper(GetContext(), modelStateDictionary);
// Act
validationHelper.RequireFields("foo", "bar");
validationHelper.GetErrors();
// Assert
Assert.False(modelStateDictionary.IsValid);
Assert.False(modelStateDictionary.IsValidField("foo"));
Assert.False(modelStateDictionary.IsValidField("bar"));
Assert.Equal("This field is required.", modelStateDictionary["foo"].Errors.Single());
Assert.Equal("This field is required.", modelStateDictionary["bar"].Errors.Single());
}