本文整理汇总了C#中ModelStateDictionary.GetFieldValidationState方法的典型用法代码示例。如果您正苦于以下问题:C# ModelStateDictionary.GetFieldValidationState方法的具体用法?C# ModelStateDictionary.GetFieldValidationState怎么用?C# ModelStateDictionary.GetFieldValidationState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelStateDictionary
的用法示例。
在下文中一共展示了ModelStateDictionary.GetFieldValidationState方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFieldValidationState_ReturnsUnvalidatedIfDictionaryDoesNotContainKey
public void GetFieldValidationState_ReturnsUnvalidatedIfDictionaryDoesNotContainKey()
{
// Arrange
var msd = new ModelStateDictionary();
// Act
var validationState = msd.GetFieldValidationState("foo");
// Assert
Assert.Equal(ModelValidationState.Unvalidated, validationState);
}
示例2: GetFieldValidationState_ReturnsInvalidIfKeyChildContainsErrors
public void GetFieldValidationState_ReturnsInvalidIfKeyChildContainsErrors()
{
// Arrange
var msd = new ModelStateDictionary();
msd.AddModelError("foo.bar", "error text");
// Act
var validationState = msd.GetFieldValidationState("foo");
// Assert
Assert.Equal(ModelValidationState.Invalid, validationState);
}
示例3: GetFieldValidity_ReturnsValid_IfAllKeysAreValid
public void GetFieldValidity_ReturnsValid_IfAllKeysAreValid()
{
// Arrange
var dictionary = new ModelStateDictionary();
dictionary["user.Address"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
dictionary["user.Name"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
// Act
var validationState = dictionary.GetFieldValidationState("user");
// Assert
Assert.Equal(ModelValidationState.Valid, validationState);
}
示例4: GetFieldValidity_ReturnsInvalid_IfAllKeysAreValidatedAndAnyEntryIsInvalid
public void GetFieldValidity_ReturnsInvalid_IfAllKeysAreValidatedAndAnyEntryIsInvalid(string key)
{
// Arrange
var dictionary = new ModelStateDictionary();
dictionary["user.Address"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
dictionary["user.Name"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
dictionary.AddModelError("user.Age", "Age is not a valid int");
dictionary["[0].product.Name"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
dictionary["[0].product.Age[0]"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
dictionary.AddModelError("[1].product.Name", "Name is invalid");
// Act
var validationState = dictionary.GetFieldValidationState(key);
// Assert
Assert.Equal(ModelValidationState.Invalid, validationState);
}
示例5: GetFieldValidity_ReturnsUnvalidated_IfAnyItemInSubtreeIsInvalid
public void GetFieldValidity_ReturnsUnvalidated_IfAnyItemInSubtreeIsInvalid()
{
// Arrange
var dictionary = new ModelStateDictionary();
dictionary["user.Address"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
dictionary.SetModelValue("user.Name", new string[] { "some value" }, "some value");
dictionary.AddModelError("user.Age", "Age is not a valid int");
// Act
var validationState = dictionary.GetFieldValidationState("user");
// Assert
Assert.Equal(ModelValidationState.Unvalidated, validationState);
}
示例6: GetFieldValidity_ReturnsUnvalidated_IfNoEntryExistsForKey
public void GetFieldValidity_ReturnsUnvalidated_IfNoEntryExistsForKey()
{
// Arrange
var dictionary = new ModelStateDictionary();
dictionary.SetModelValue("user.Name", new string[] { "some value" }, "some value");
// Act
var validationState = dictionary.GetFieldValidationState("not-user");
// Assert
Assert.Equal(ModelValidationState.Unvalidated, validationState);
}
示例7: GetFieldValidationState_IndexedPrefix_ReturnsValidIfModelStateDoesNotContainErrors
public void GetFieldValidationState_IndexedPrefix_ReturnsValidIfModelStateDoesNotContainErrors(string key)
{
// Arrange
var validState = new ModelStateEntry
{
ValidationState = ModelValidationState.Valid
};
var dictionary = new ModelStateDictionary
{
{ key, validState }
};
// Act
var validationState = dictionary.GetFieldValidationState("[0].foo");
// Assert
Assert.Equal(ModelValidationState.Valid, validationState);
}
示例8: GetFieldValidationState_IndexedPrefix_ReturnsInvalidIfKeyChildContainsErrors
public void GetFieldValidationState_IndexedPrefix_ReturnsInvalidIfKeyChildContainsErrors(string key)
{
// Arrange
var dictionary = new ModelStateDictionary();
dictionary.AddModelError(key, "error text");
// Act
var validationState = dictionary.GetFieldValidationState("[0].foo");
// Assert
Assert.Equal(ModelValidationState.Invalid, validationState);
}
示例9: GetFieldValidationState_IndexedPrefix_ReturnsValidIfModelStateDoesNotContainErrors
public void GetFieldValidationState_IndexedPrefix_ReturnsValidIfModelStateDoesNotContainErrors(string key)
{
// Arrange
var validState = new ModelState
{
Value = new ValueProviderResult(null, null, null),
ValidationState = ModelValidationState.Valid
};
var msd = new ModelStateDictionary
{
{ key, validState }
};
// Act
var validationState = msd.GetFieldValidationState("[0].foo");
// Assert
Assert.Equal(ModelValidationState.Valid, validationState);
}
示例10: GetFieldValidationState_ReturnsValidIfModelStateDoesNotContainErrors
public void GetFieldValidationState_ReturnsValidIfModelStateDoesNotContainErrors(string key)
{
// Arrange
var validState = new ModelState
{
ValidationState = ModelValidationState.Valid
};
var msd = new ModelStateDictionary
{
{ key, validState }
};
// Act
var validationState = msd.GetFieldValidationState("foo");
// Assert
Assert.Equal(ModelValidationState.Valid, validationState);
}
示例11: GetFieldValidity_ReturnsInvalid_IfAllKeysAreValidatedAndAnyEntryIsInvalid_Collection
public void GetFieldValidity_ReturnsInvalid_IfAllKeysAreValidatedAndAnyEntryIsInvalid_Collection(string key)
{
// Arrange
var dictionary = new ModelStateDictionary();
dictionary.MarkFieldValid("[0].product.Name");
dictionary.MarkFieldValid("[0].product.Age[0]");
dictionary.AddModelError("[0].product.Name", "Name is invalid");
// Act
var validationState = dictionary.GetFieldValidationState(key);
// Assert
Assert.Equal(ModelValidationState.Invalid, validationState);
}
示例12: GetFieldValidity_ReturnsInvalid_IfAllKeysAreValidatedAndAnyEntryIsInvalid
public void GetFieldValidity_ReturnsInvalid_IfAllKeysAreValidatedAndAnyEntryIsInvalid(string key)
{
// Arrange
var dictionary = new ModelStateDictionary();
dictionary.MarkFieldValid("user.Address");
dictionary.MarkFieldValid("user.Name");
dictionary.AddModelError("user.Age", "Age is not a valid int");
// Act
var validationState = dictionary.GetFieldValidationState(key);
// Assert
Assert.Equal(ModelValidationState.Invalid, validationState);
}
示例13: GetFieldValidationState_ReturnsValidIfModelStateDoesNotContainErrors
public void GetFieldValidationState_ReturnsValidIfModelStateDoesNotContainErrors(string key)
{
// Arrange
var dictionary = new ModelStateDictionary();
dictionary.MarkFieldValid(key);
// Act
var validationState = dictionary.GetFieldValidationState("foo");
// Assert
Assert.Equal(ModelValidationState.Valid, validationState);
}