public void CombineWith() { // Arrange List <string> log = new List <string>(); ModelValidationNode[] allChildNodes = new[] { 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 Assert.Equal(new[] { "Validating parent1.", "Validating parent2.", "Validated parent1.", "Validated parent2." }, log.ToArray()); Assert.Equal(allChildNodes, parentNode1.ChildNodes.ToArray()); }
public void CombineWith_OtherNodeIsSuppressed_DoesNothing() { // Arrange List <string> log = new List <string>(); ModelValidationNode[] allChildNodes = new ModelValidationNode[] { new ModelValidationNode(GetModelMetadata(), "key1"), new ModelValidationNode(GetModelMetadata(), "key2"), new ModelValidationNode(GetModelMetadata(), "key3"), }; ModelValidationNode[] expectedChildNodes = new ModelValidationNode[] { 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 CollectionAssert.AreEqual( new string[] { "Validating parent1.", "Validated parent1." }, log); CollectionAssert.AreEqual(expectedChildNodes, parentNode1.ChildNodes.ToArray()); }
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()); }
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()); }