本文整理汇总了C#中ModelStateDictionary.ClearValidationState方法的典型用法代码示例。如果您正苦于以下问题:C# ModelStateDictionary.ClearValidationState方法的具体用法?C# ModelStateDictionary.ClearValidationState怎么用?C# ModelStateDictionary.ClearValidationState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelStateDictionary
的用法示例。
在下文中一共展示了ModelStateDictionary.ClearValidationState方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ModelStateDictionary_ClearsAllEntries_EmptyKey
public void ModelStateDictionary_ClearsAllEntries_EmptyKey(string modelKey)
{
// Arrange
var dictionary = new ModelStateDictionary();
dictionary["Property1"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
dictionary["Property2"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("Property2", "Property2 invalid.");
dictionary["Property3"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("Property3", "Property invalid.");
dictionary["Property4"] = new ModelStateEntry { ValidationState = ModelValidationState.Skipped };
// Act
dictionary.ClearValidationState(modelKey);
// Assert
Assert.Equal(0, dictionary["Property1"].Errors.Count);
Assert.Equal(ModelValidationState.Unvalidated, dictionary["Property1"].ValidationState);
Assert.Equal(0, dictionary["Property2"].Errors.Count);
Assert.Equal(ModelValidationState.Unvalidated, dictionary["Property2"].ValidationState);
Assert.Equal(0, dictionary["Property3"].Errors.Count);
Assert.Equal(ModelValidationState.Unvalidated, dictionary["Property3"].ValidationState);
Assert.Equal(0, dictionary["Property4"].Errors.Count);
Assert.Equal(ModelValidationState.Unvalidated, dictionary["Property4"].ValidationState);
}
示例2: ModelStateDictionary_ClearEntriesPrefixedWithKey_NonEmptyKey
public void ModelStateDictionary_ClearEntriesPrefixedWithKey_NonEmptyKey()
{
// Arrange
var dictionary = new ModelStateDictionary();
dictionary["Product"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
dictionary["Product.Detail1"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("Product.Detail1", "Product Detail1 invalid.");
dictionary["Product.Detail2[0]"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("Product.Detail2[0]", "Product Detail2[0] invalid.");
dictionary["Product.Detail2[1]"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("Product.Detail2[1]", "Product Detail2[1] invalid.");
dictionary["Product.Detail2[2]"] = new ModelStateEntry { ValidationState = ModelValidationState.Skipped };
dictionary["Product.Detail3"] = new ModelStateEntry { ValidationState = ModelValidationState.Skipped };
dictionary["ProductName"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("ProductName", "ProductName invalid.");
// Act
dictionary.ClearValidationState("Product");
// Assert
Assert.Equal(0, dictionary["Product"].Errors.Count);
Assert.Equal(ModelValidationState.Unvalidated, dictionary["Product"].ValidationState);
Assert.Equal(0, dictionary["Product.Detail1"].Errors.Count);
Assert.Equal(ModelValidationState.Unvalidated, dictionary["Product.Detail1"].ValidationState);
Assert.Equal(0, dictionary["Product.Detail2[0]"].Errors.Count);
Assert.Equal(ModelValidationState.Unvalidated, dictionary["Product.Detail2[0]"].ValidationState);
Assert.Equal(0, dictionary["Product.Detail2[1]"].Errors.Count);
Assert.Equal(ModelValidationState.Unvalidated, dictionary["Product.Detail2[1]"].ValidationState);
Assert.Equal(0, dictionary["Product.Detail2[2]"].Errors.Count);
Assert.Equal(ModelValidationState.Unvalidated, dictionary["Product.Detail2[2]"].ValidationState);
Assert.Equal(0, dictionary["Product.Detail3"].Errors.Count);
Assert.Equal(ModelValidationState.Unvalidated, dictionary["Product.Detail3"].ValidationState);
Assert.Equal(1, dictionary["ProductName"].Errors.Count);
Assert.Equal(ModelValidationState.Invalid, dictionary["ProductName"].ValidationState);
}
示例3: ModelStateDictionary_ClearEntries_KeyHasDot_NonEmptyKey
public void ModelStateDictionary_ClearEntries_KeyHasDot_NonEmptyKey()
{
// Arrange
var dictionary = new ModelStateDictionary();
dictionary["Product"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
dictionary["Product.Detail1"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("Product.Detail1", "Product Detail1 invalid.");
dictionary["Product.Detail1.Name"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("Product.Detail1.Name", "Product Detail1 Name invalid.");
dictionary["Product.Detail1Name"] = new ModelStateEntry { ValidationState = ModelValidationState.Skipped };
// Act
dictionary.ClearValidationState("Product.Detail1");
// Assert
Assert.Equal(ModelValidationState.Valid, dictionary["Product"].ValidationState);
Assert.Equal(0, dictionary["Product.Detail1"].Errors.Count);
Assert.Equal(ModelValidationState.Unvalidated, dictionary["Product.Detail1"].ValidationState);
Assert.Equal(0, dictionary["Product.Detail1.Name"].Errors.Count);
Assert.Equal(ModelValidationState.Unvalidated, dictionary["Product.Detail1.Name"].ValidationState);
Assert.Equal(ModelValidationState.Skipped, dictionary["Product.Detail1Name"].ValidationState);
}
示例4: ModelStateDictionary_ClearEntriesThatMatchWithKey_NonEmptyKey
public void ModelStateDictionary_ClearEntriesThatMatchWithKey_NonEmptyKey()
{
// Arrange
var dictionary = new ModelStateDictionary();
dictionary["Property1"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
dictionary["Property2"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("Property2", "Property2 invalid.");
dictionary["Property3"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("Property3", "Property invalid.");
dictionary["Property4"] = new ModelStateEntry { ValidationState = ModelValidationState.Skipped };
// Act
dictionary.ClearValidationState("Property1");
dictionary.ClearValidationState("Property2");
dictionary.ClearValidationState("Property4");
// Assert
Assert.Equal(0, dictionary["Property1"].Errors.Count);
Assert.Equal(ModelValidationState.Unvalidated, dictionary["Property1"].ValidationState);
Assert.Equal(0, dictionary["Property2"].Errors.Count);
Assert.Equal(ModelValidationState.Unvalidated, dictionary["Property2"].ValidationState);
Assert.Equal(1, dictionary["Property3"].Errors.Count);
Assert.Equal(ModelValidationState.Invalid, dictionary["Property3"].ValidationState);
Assert.Equal(0, dictionary["Property4"].Errors.Count);
Assert.Equal(ModelValidationState.Unvalidated, dictionary["Property4"].ValidationState);
}