本文整理汇总了C#中ModelStateDictionary.MarkFieldSkipped方法的典型用法代码示例。如果您正苦于以下问题:C# ModelStateDictionary.MarkFieldSkipped方法的具体用法?C# ModelStateDictionary.MarkFieldSkipped怎么用?C# ModelStateDictionary.MarkFieldSkipped使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelStateDictionary
的用法示例。
在下文中一共展示了ModelStateDictionary.MarkFieldSkipped方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MarkFieldSkipped_MarksFieldAsSkipped_IfKeyIsNotPresent
public void MarkFieldSkipped_MarksFieldAsSkipped_IfKeyIsNotPresent()
{
// Arrange
var entry = new ModelStateEntry
{
ValidationState = ModelValidationState.Valid
};
var source = new ModelStateDictionary();
// Act
source.MarkFieldSkipped("key");
// Assert
Assert.Equal(0, source.ErrorCount);
Assert.Equal(1, source.Count);
Assert.Equal(ModelValidationState.Skipped, source["key"].ValidationState);
}
示例2: MarkFieldSkipped_MarksFieldAsSkipped_IfStateIsNotInValid
public void MarkFieldSkipped_MarksFieldAsSkipped_IfStateIsNotInValid(ModelValidationState validationState)
{
// Arrange
var entry = new ModelStateEntry
{
ValidationState = validationState
};
var source = new ModelStateDictionary
{
{ "key", entry }
};
// Act
source.MarkFieldSkipped("key");
// Assert
Assert.Equal(ModelValidationState.Skipped, source["key"].ValidationState);
}
示例3: MarkFieldSkipped_MarksFieldAsSkipped_IfStateIsNotInValid
public void MarkFieldSkipped_MarksFieldAsSkipped_IfStateIsNotInValid(ModelValidationState validationState)
{
// Arrange
var modelState = new ModelState
{
Value = GetValueProviderResult("value"),
ValidationState = validationState
};
var source = new ModelStateDictionary
{
{ "key", modelState }
};
// Act
source.MarkFieldSkipped("key");
// Assert
Assert.Equal(ModelValidationState.Skipped, source["key"].ValidationState);
}
示例4: MarkFieldSkipped_Throws_IfStateIsInvalid
public void MarkFieldSkipped_Throws_IfStateIsInvalid()
{
// Arrange
var entry = new ModelStateEntry
{
ValidationState = ModelValidationState.Invalid
};
var source = new ModelStateDictionary
{
{ "key", entry }
};
// Act
var exception = Assert.Throws<InvalidOperationException>(() => source.MarkFieldSkipped("key"));
// Assert
Assert.Equal(
"A field previously marked invalid should not be marked skipped.",
exception.Message);
}
示例5: MarkFieldSkipped_MarksFieldAsSkipped_IfKeyIsNotPresent
public void MarkFieldSkipped_MarksFieldAsSkipped_IfKeyIsNotPresent()
{
// Arrange
var modelState = new ModelState
{
Value = GetValueProviderResult("value"),
ValidationState = ModelValidationState.Valid
};
var source = new ModelStateDictionary
{
};
// Act
source.MarkFieldSkipped("key");
// Assert
Assert.Equal(0, source.ErrorCount);
Assert.Equal(1, source.Count);
Assert.Equal(ModelValidationState.Skipped, source["key"].ValidationState);
}
示例6: ModelStateDictionary_ClearEntries_KeyHasDot_NonEmptyKey
public void ModelStateDictionary_ClearEntries_KeyHasDot_NonEmptyKey()
{
// Arrange
var dictionary = new ModelStateDictionary();
dictionary.MarkFieldValid("Product");
dictionary.AddModelError("Product.Detail1", "Product Detail1 invalid.");
dictionary.AddModelError("Product.Detail1.Name", "Product Detail1 Name invalid.");
dictionary.MarkFieldSkipped("Product.Detail1Name");
// 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);
}
示例7: ModelStateDictionary_ClearEntriesPrefixedWithKey_NonEmptyKey
public void ModelStateDictionary_ClearEntriesPrefixedWithKey_NonEmptyKey()
{
// Arrange
var dictionary = new ModelStateDictionary();
dictionary.MarkFieldValid("Product");
dictionary.AddModelError("Product.Detail1", "Product Detail1 invalid.");
dictionary.AddModelError("Product.Detail2[0]", "Product Detail2[0] invalid.");
dictionary.AddModelError("Product.Detail2[1]", "Product Detail2[1] invalid.");
dictionary.MarkFieldSkipped("Product.Detail2[2]");
dictionary.MarkFieldSkipped("Product.Detail3");
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);
}
示例8: ModelStateDictionary_ClearEntriesThatMatchWithKey_NonEmptyKey
public void ModelStateDictionary_ClearEntriesThatMatchWithKey_NonEmptyKey()
{
// Arrange
var dictionary = new ModelStateDictionary();
dictionary.MarkFieldValid("Property1");
dictionary.AddModelError("Property2", "Property2 invalid.");
dictionary.AddModelError("Property3", "Property invalid.");
dictionary.MarkFieldSkipped("Property4");
// 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);
}
示例9: MarkFieldSkipped_Throws_IfStateIsInvalid
public void MarkFieldSkipped_Throws_IfStateIsInvalid()
{
// Arrange
var source = new ModelStateDictionary();
source.AddModelError("key", "some error");
// Act
var exception = Assert.Throws<InvalidOperationException>(() => source.MarkFieldSkipped("key"));
// Assert
Assert.Equal(
"A field previously marked invalid should not be marked skipped.",
exception.Message);
}
示例10: MarkFieldValid_MarksFieldAsValid_IfStateIsSkipped
public void MarkFieldValid_MarksFieldAsValid_IfStateIsSkipped()
{
// Arrange
var source = new ModelStateDictionary();
source.MarkFieldSkipped("key");
// Act
source.MarkFieldValid("key");
// Assert
Assert.Equal(ModelValidationState.Valid, source["key"].ValidationState);
}
示例11: KeysEnumerable_ReturnsAllKeys
public void KeysEnumerable_ReturnsAllKeys()
{
// Arrange
var expected = new[] { "Property1", "Property4", "Property1.Property2", "Property2[Property3]" };
var dictionary = new ModelStateDictionary();
dictionary.MarkFieldValid("Property1");
dictionary.AddModelError("Property1.Property2", "Property2 invalid.");
dictionary.AddModelError("Property2", "Property invalid.");
dictionary.AddModelError("Property2[Property3]", "Property2[Property3] invalid.");
dictionary.MarkFieldSkipped("Property4");
dictionary.Remove("Property2");
// Act
var keys = dictionary.Keys;
// Assert
Assert.Equal(expected, keys);
}
示例12: IsValidPropertyReturnsTrueIfNoErrors
public void IsValidPropertyReturnsTrueIfNoErrors()
{
// Arrange
var dictionary = new ModelStateDictionary();
dictionary.MarkFieldValid("foo");
dictionary.MarkFieldSkipped("bar");
// Act
var isValid = dictionary.IsValid;
var validationState = dictionary.ValidationState;
// Assert
Assert.True(isValid);
Assert.Equal(ModelValidationState.Valid, validationState);
}
示例13: GetEnumerable_ReturnsAllNonContainerNodes
public void GetEnumerable_ReturnsAllNonContainerNodes()
{
// Arrange
var dictionary = new ModelStateDictionary();
dictionary.MarkFieldValid("Property1");
dictionary.SetModelValue("Property1.Property2", "value", "value");
dictionary.AddModelError("Property2", "Property invalid.");
dictionary.AddModelError("Property2[Property3]", "Property2[Property3] invalid.");
dictionary.MarkFieldSkipped("Property4");
dictionary.Remove("Property2");
// Act & Assert
Assert.Collection(
dictionary,
entry =>
{
Assert.Equal("Property1", entry.Key);
Assert.Equal(ModelValidationState.Valid, entry.Value.ValidationState);
Assert.Null(entry.Value.RawValue);
Assert.Null(entry.Value.AttemptedValue);
Assert.Empty(entry.Value.Errors);
},
entry =>
{
Assert.Equal("Property4", entry.Key);
Assert.Equal(ModelValidationState.Skipped, entry.Value.ValidationState);
Assert.Null(entry.Value.RawValue);
Assert.Null(entry.Value.AttemptedValue);
Assert.Empty(entry.Value.Errors);
},
entry =>
{
Assert.Equal("Property1.Property2", entry.Key);
Assert.Equal(ModelValidationState.Unvalidated, entry.Value.ValidationState);
Assert.Equal("value", entry.Value.RawValue);
Assert.Equal("value", entry.Value.AttemptedValue);
Assert.Empty(entry.Value.Errors);
},
entry =>
{
Assert.Equal("Property2[Property3]", entry.Key);
Assert.Equal(ModelValidationState.Invalid, entry.Value.ValidationState);
Assert.Null(entry.Value.RawValue);
Assert.Null(entry.Value.AttemptedValue);
Assert.Collection(entry.Value.Errors,
error => Assert.Equal("Property2[Property3] invalid.", error.ErrorMessage));
});
}
示例14: ContainsKey_ReturnsTrue_IfNodeHasBeenMutated
public void ContainsKey_ReturnsTrue_IfNodeHasBeenMutated(string key)
{
// Arrange
var dictionary = new ModelStateDictionary();
dictionary.MarkFieldSkipped(key);
// Act
var result = dictionary.ContainsKey(key);
// Assert
Assert.True(result);
}
示例15: ModelStateDictionary_ClearsAllEntries_EmptyKey
public void ModelStateDictionary_ClearsAllEntries_EmptyKey(string modelKey)
{
// Arrange
var dictionary = new ModelStateDictionary();
dictionary.MarkFieldValid("Property1");
dictionary.AddModelError("Property2", "Property2 invalid.");
dictionary.AddModelError("Property3", "Property invalid.");
dictionary.MarkFieldSkipped("Property4");
// 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);
}