本文整理汇总了C#中ModelValidationNode.CombineWith方法的典型用法代码示例。如果您正苦于以下问题:C# ModelValidationNode.CombineWith方法的具体用法?C# ModelValidationNode.CombineWith怎么用?C# ModelValidationNode.CombineWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelValidationNode
的用法示例。
在下文中一共展示了ModelValidationNode.CombineWith方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CombineWith
public void CombineWith() {
// Arrange
List<string> log = new List<string>();
ModelValidationNode[] allChildNodes = new ModelValidationNode[] {
new ModelValidationNode(GetModelMetadata(), "key1"),
new ModelValidationNode(GetModelMetadata(), "key2"),
new ModelValidationNode(GetModelMetadata(), "key3"),
};
ModelValidationNode parentNode1 = new ModelValidationNode(GetModelMetadata(), "parent1");
parentNode1.ChildNodes.Add(allChildNodes[0]);
parentNode1.Validating += delegate { log.Add("Validating parent1."); };
parentNode1.Validated += delegate { log.Add("Validated parent1."); };
ModelValidationNode parentNode2 = new ModelValidationNode(GetModelMetadata(), "parent2");
parentNode2.ChildNodes.Add(allChildNodes[1]);
parentNode2.ChildNodes.Add(allChildNodes[2]);
parentNode2.Validating += delegate { log.Add("Validating parent2."); };
parentNode2.Validated += delegate { log.Add("Validated parent2."); };
// Act
parentNode1.CombineWith(parentNode2);
parentNode1.Validate(new ControllerContext() { Controller = new EmptyController() });
// Assert
CollectionAssert.AreEqual(
new string[] { "Validating parent1.", "Validating parent2.", "Validated parent1.", "Validated parent2." },
log);
CollectionAssert.AreEqual(allChildNodes, parentNode1.ChildNodes.ToArray());
}
示例2: CombineWith_OtherNodeIsSuppressed_DoesNothing
public void CombineWith_OtherNodeIsSuppressed_DoesNothing()
{
// Arrange
List<string> log = new List<string>();
ModelValidationNode[] allChildNodes = new[]
{
new ModelValidationNode(GetModelMetadata(), "key1"),
new ModelValidationNode(GetModelMetadata(), "key2"),
new ModelValidationNode(GetModelMetadata(), "key3"),
};
ModelValidationNode[] expectedChildNodes = new[]
{
allChildNodes[0]
};
ModelValidationNode parentNode1 = new ModelValidationNode(GetModelMetadata(), "parent1");
parentNode1.ChildNodes.Add(allChildNodes[0]);
parentNode1.Validating += delegate { log.Add("Validating parent1."); };
parentNode1.Validated += delegate { log.Add("Validated parent1."); };
ModelValidationNode parentNode2 = new ModelValidationNode(GetModelMetadata(), "parent2");
parentNode2.ChildNodes.Add(allChildNodes[1]);
parentNode2.ChildNodes.Add(allChildNodes[2]);
parentNode2.Validating += delegate { log.Add("Validating parent2."); };
parentNode2.Validated += delegate { log.Add("Validated parent2."); };
parentNode2.SuppressValidation = true;
// Act
parentNode1.CombineWith(parentNode2);
parentNode1.Validate(new ControllerContext { Controller = new EmptyController() });
// Assert
Assert.Equal(new[] { "Validating parent1.", "Validated parent1." }, log.ToArray());
Assert.Equal(expectedChildNodes, parentNode1.ChildNodes.ToArray());
}