コード例 #1
0
 public void XDocumentSuccessValidate()
 {
     validationSucceded = true;
     ExtensionsClass.Validate(xmlDocument, schemaSet,
                              new ValidationEventHandler(TestValidationHandler));
     Assert.True(validationSucceded);
 }
コード例 #2
0
        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");
        }
コード例 #3
0
        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.");
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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));
        }
コード例 #8
0
        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));
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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");
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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");
        }