public void XDocumentSuccessValidate() { validationSucceded = true; ExtensionsClass.Validate(xmlDocument, schemaSet, new ValidationEventHandler(TestValidationHandler)); Assert.True(validationSucceded); }
public void XDocumentNoSchemaInfoValidate() { // no. of elements before validation IEnumerable <XElement> elements = xmlDocument.Elements(); IEnumerator <XElement> elementsEnumerator = elements.GetEnumerator(); int beforeNoOfElements = 0; int beforeNoOfAttributes = 0; while (elementsEnumerator.MoveNext()) { beforeNoOfElements++; if (!elementsEnumerator.Current.HasAttributes) { continue; } else { IEnumerable <XAttribute> attributes = elementsEnumerator.Current.Attributes(); IEnumerator <XAttribute> attributesEnumerator = attributes.GetEnumerator(); while (attributesEnumerator.MoveNext()) { beforeNoOfAttributes++; } } } // don't populate XML with PSVI validationSucceded = true; ExtensionsClass.Validate(xmlDocument, schemaSet, new ValidationEventHandler(TestValidationHandler), false); Assert.AreEqual(true, validationSucceded); // no. of elements after validation elements = xmlDocument.Elements(); elementsEnumerator = elements.GetEnumerator(); int afterNoOfElements = 0; int afterNoOfAttributes = 0; while (elementsEnumerator.MoveNext()) { afterNoOfElements++; if (!elementsEnumerator.Current.HasAttributes) { continue; } else { IEnumerable <XAttribute> attributes = elementsEnumerator.Current.Attributes(); IEnumerator <XAttribute> attributesEnumerator = attributes.GetEnumerator(); while (attributesEnumerator.MoveNext()) { afterNoOfAttributes++; } } } Assert.AreEqual(afterNoOfAttributes, beforeNoOfAttributes, "oldAttributes"); Assert.AreEqual(afterNoOfElements, beforeNoOfElements, "oldElements"); }
public void XDocumentAddSchemaInfoValidate() { // no. of elements before validation IEnumerable <XElement> elements = xmlDocument.Elements(); IEnumerator <XElement> elementsEnumerator = elements.GetEnumerator(); int beforeNoOfElements = 0; int beforeNoOfAttributes = 0; while (elementsEnumerator.MoveNext()) { beforeNoOfElements++; if (!elementsEnumerator.Current.HasAttributes) { continue; } IEnumerable <XAttribute> attributes = elementsEnumerator.Current.Attributes(); IEnumerator <XAttribute> attributesEnumerator = attributes.GetEnumerator(); while (attributesEnumerator.MoveNext()) { beforeNoOfAttributes++; } } // populate XML with PSVI validationSucceded = true; ExtensionsClass.Validate(xmlDocument, schemaSet, new ValidationEventHandler(TestValidationHandler), true); Assert.True(validationSucceded); // no. of elements after validation elements = xmlDocument.Elements(); elementsEnumerator = elements.GetEnumerator(); int afterNoOfElements = 0; int afterNoOfAttributes = 0; while (elementsEnumerator.MoveNext()) { afterNoOfElements++; if (!elementsEnumerator.Current.HasAttributes) { continue; } IEnumerable <XAttribute> attributes = elementsEnumerator.Current.Attributes(); IEnumerator <XAttribute> attributesEnumerator = attributes.GetEnumerator(); while (attributesEnumerator.MoveNext()) { afterNoOfAttributes++; } } Assert.True(afterNoOfAttributes >= beforeNoOfAttributes, "XDocumentAddSchemaInfoValidate, wrong newAttributes value."); Assert.True(afterNoOfElements >= beforeNoOfElements, "XDocumentAddSchemaInfoValidate, wrong newElements value."); }
public void XDocumentThrowExceptionValidate() { string elementName = "AlteringElementName"; object elementValue = "AlteringElementValue"; // alter XML document to invalidate var newElement = new XElement(elementName, elementValue); xmlDocument.Root.Add(newElement); Assert.Throws<XmlSchemaValidationException>(() => ExtensionsClass.Validate(xmlDocument, schemaSet, null)); }
public void XDocumentThrowExceptionValidate() { String elementName = "AlteringElementName"; object elementValue = "AlteringElementValue"; // alter XML document to invalidate XElement newElement = new XElement(elementName, elementValue); xmlDocument.Root.Add(newElement); ExtensionsClass.Validate(xmlDocument, schemaSet, null); }
public void XDocumentFailValidate() { string elementName = "AlteringElementName"; object elementValue = "AlteringElementValue"; // alter XML document to invalidate var newElement = new XElement(elementName, elementValue); xmlDocument.Root.Add(newElement); validationSucceeded = true; ExtensionsClass.Validate(xmlDocument, schemaSet, new ValidationEventHandler(TestValidationHandler)); Assert.False(validationSucceeded); }
public void XAttributeThrowExceptionValidate() { string elementName = "note"; string attributeName = "date"; object attributeValue = "2010-12-32"; // validate the entire document validationSucceeded = true; ExtensionsClass.Validate(xmlDocument, schemaSet, new ValidationEventHandler(TestValidationHandler),true); Assert.True(validationSucceeded); // change and re-validate attribute value XAttribute date = xmlDocument.Element(elementName).Attribute(attributeName); date.SetValue(attributeValue); Assert.Throws<XmlSchemaValidationException>(() => ExtensionsClass.Validate(date, date.GetSchemaInfo().SchemaAttribute, schemaSet, null)); }
public void XElementThrowExceptionValidate() { string parentElementName = "note" ; string childElementName = "body"; object childElementValue = "Don't forget to call me! Please!"; // validate the entire document validationSucceeded = true; ExtensionsClass.Validate(xmlDocument, schemaSet, new ValidationEventHandler(TestValidationHandler), true); Assert.True(validationSucceeded); // alter element XElement root = xmlDocument.Element(parentElementName); root.SetElementValue(childElementName, childElementValue); Assert.Throws<XmlSchemaValidationException>(() => ExtensionsClass.Validate(root, root.GetSchemaInfo().SchemaElement, schemaSet, null)); }
public void XElementGetSchemaInfo() { string elementName = "body"; // validate the entire document validationSucceeded = true; ExtensionsClass.Validate(xmlDocument, schemaSet, new ValidationEventHandler(TestValidationHandler), true); Assert.True(validationSucceeded); // validate element XElement body = xmlDocument.Root.Element(elementName); ExtensionsClass.Validate(body, body.GetSchemaInfo().SchemaElement, schemaSet, new ValidationEventHandler(TestValidationHandler)); Assert.True(validationSucceeded); IXmlSchemaInfo schemaInfo = ExtensionsClass.GetSchemaInfo(body); Assert.NotNull(schemaInfo); }
public void XAttributeFailValidate() { String elementName = "note"; String attributeName = "date"; object attributeValue = "2010-12-32"; // validate the entire document validationSucceded = true; ExtensionsClass.Validate(xmlDocument, schemaSet, new ValidationEventHandler(TestValidationHandler), true); Assert.AreEqual(true, validationSucceded); // change and re-validate attribute value XAttribute date = xmlDocument.Element(elementName).Attribute(attributeName); date.SetValue(attributeValue); ExtensionsClass.Validate(date, date.GetSchemaInfo().SchemaAttribute, schemaSet, new ValidationEventHandler(TestValidationHandler)); Assert.AreEqual(false, validationSucceded, "XAttributeFailValidate"); }
public void XAttributeGetSchemaInfo() { string elementName = "note"; string attributeName = "date"; // validate the entire document validationSucceeded = true; ExtensionsClass.Validate(xmlDocument, schemaSet, new ValidationEventHandler(TestValidationHandler), true); Assert.True(validationSucceeded); // validate attribute XAttribute date = xmlDocument.Element(elementName).Attribute(attributeName); ExtensionsClass.Validate(date, date.GetSchemaInfo().SchemaAttribute, schemaSet, new ValidationEventHandler(TestValidationHandler)); Assert.True(validationSucceeded); IXmlSchemaInfo schemaInfo = ExtensionsClass.GetSchemaInfo(date); Assert.NotNull(schemaInfo); }
public void XElementSuccessValidate() { string parentElementName = "note"; string childElementName = "body"; object childElementValue = "Please call me!"; // validate the entire document validationSucceeded = true; ExtensionsClass.Validate(xmlDocument, schemaSet, new ValidationEventHandler(TestValidationHandler), true); Assert.True(validationSucceeded); // alter element XElement root = xmlDocument.Element(parentElementName); root.SetElementValue(childElementName, childElementValue); ExtensionsClass.Validate(root, root.GetSchemaInfo().SchemaElement, schemaSet, new ValidationEventHandler(TestValidationHandler)); Assert.True(validationSucceeded); }
public void XElementFailValidate() { String parentElementName = "note"; String childElementName = "body"; object childElementValue = "Don't forget to call me! Please!"; // validate the entire document validationSucceded = true; ExtensionsClass.Validate(xmlDocument, schemaSet, new ValidationEventHandler(TestValidationHandler), true); Assert.AreEqual(true, validationSucceded); // alter element XElement root = xmlDocument.Element(parentElementName); root.SetElementValue(childElementName, childElementValue); ExtensionsClass.Validate(root, root.GetSchemaInfo().SchemaElement, schemaSet, new ValidationEventHandler(TestValidationHandler)); Assert.AreEqual(false, validationSucceded, "XElementFailValidate"); }