コード例 #1
0
        public void WhitespaceInsideElement()
        {
            XmlSchemaValidator val = CreateValidator(XSDFILE_VALIDATE_TEXT);
            CValidationEventHolder holder = new CValidationEventHolder();
            XmlSchemaInfo info = new XmlSchemaInfo();

            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateElement("ElementOnlyElement", "", info);
            val.ValidateEndOfAttributes(null);

            val.ValidateWhitespace(" \t\r\n");

            val.ValidateElement("child", "", info);
            val.ValidateEndOfAttributes(null);
            val.ValidateEndElement(info);

            val.ValidateWhitespace(" \t\r\n");

            val.ValidateEndElement(info);
            val.EndValidation();

            Assert.True(!holder.IsCalledA);
            Assert.Equal(info.Validity, XmlSchemaValidity.Valid);
            Assert.Equal(info.ContentType, XmlSchemaContentType.ElementOnly);

            return;
        }
コード例 #2
0
        public void SanityTestForSimpleType_MultipleCallInOneContext(String param)
        {
            XmlSchemaValidator val = CreateValidator(XSDFILE_VALIDATE_TEXT);
            CValidationEventHolder holder = new CValidationEventHolder();
            XmlSchemaInfo info = new XmlSchemaInfo();

            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateElement("PatternElement", "", info);
            val.ValidateEndOfAttributes(null);

            if (param == "single")
                val.ValidateText(StringGetter("foo123bar"));
            else
            {
                val.ValidateText(StringGetter("foo"));
                val.ValidateText(StringGetter("123"));
                val.ValidateText(StringGetter("bar"));
            }

            val.ValidateEndElement(info);
            val.EndValidation();

            Assert.True(!holder.IsCalledA);
            Assert.Equal(info.Validity, XmlSchemaValidity.Valid);
            Assert.Equal(info.ContentType, XmlSchemaContentType.TextOnly);

            return;
        }
コード例 #3
0
        public void MixedContent()
        {
            XmlSchemaValidator     val    = CreateValidator(XSDFILE_VALIDATE_TEXT);
            CValidationEventHolder holder = new CValidationEventHolder();
            XmlSchemaInfo          info   = new XmlSchemaInfo();

            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateElement("MixedElement", "", info);
            val.ValidateEndOfAttributes(null);

            val.ValidateText(StringGetter("some text"));

            val.ValidateElement("child", "", info);
            val.ValidateEndOfAttributes(null);
            val.ValidateEndElement(info);

            val.ValidateText(StringGetter("some other text"));

            val.ValidateEndElement(info);
            val.EndValidation();

            Assert.True(!holder.IsCalledA);
            Assert.Equal(info.Validity, XmlSchemaValidity.Valid);
            Assert.Equal(info.ContentType, XmlSchemaContentType.Mixed);

            return;
        }
コード例 #4
0
        public void SanityTestForSimpleType_MultipleCallInOneContext(String param)
        {
            XmlSchemaValidator     val    = CreateValidator(XSDFILE_VALIDATE_TEXT);
            CValidationEventHolder holder = new CValidationEventHolder();
            XmlSchemaInfo          info   = new XmlSchemaInfo();

            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateElement("PatternElement", "", info);
            val.ValidateEndOfAttributes(null);

            if (param == "single")
            {
                val.ValidateText(StringGetter("foo123bar"));
            }
            else
            {
                val.ValidateText(StringGetter("foo"));
                val.ValidateText(StringGetter("123"));
                val.ValidateText(StringGetter("bar"));
            }

            val.ValidateEndElement(info);
            val.EndValidation();

            Assert.True(!holder.IsCalledA);
            Assert.Equal(info.Validity, XmlSchemaValidity.Valid);
            Assert.Equal(info.ContentType, XmlSchemaContentType.TextOnly);

            return;
        }
コード例 #5
0
        public void IncompleteContent__Invalid()
        {
            XmlSchemaValidator     val    = CreateValidator(XSDFILE_VALIDATE_END_ELEMENT);
            XmlSchemaInfo          info   = new XmlSchemaInfo();
            CValidationEventHolder holder = new CValidationEventHolder();

            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateElement("ComplexElement", "", info);
            val.ValidateEndOfAttributes(null);

            foreach (string name in new string[] { "e1", "e2" })
            {
                val.ValidateElement(name, "", info);
                val.ValidateEndOfAttributes(null);
                val.ValidateEndElement(info);
            }

            val.ValidateEndElement(info);

            Assert.True(holder.IsCalledA);
            Assert.Equal(holder.lastSeverity, XmlSeverityType.Error);
            Assert.Equal(info.Validity, XmlSchemaValidity.Invalid);

            return;
        }
コード例 #6
0
        public void WhitespaceInsideElement_Single()
        {
            XmlSchemaValidator     val    = CreateValidator(XSDFILE_VALIDATE_TEXT);
            CValidationEventHolder holder = new CValidationEventHolder();
            XmlSchemaInfo          info   = new XmlSchemaInfo();

            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateElement("ElementOnlyElement", "", info);
            val.ValidateEndOfAttributes(null);

            val.ValidateWhitespace(StringGetter(" \t\r\n"));

            val.ValidateElement("child", "", info);
            val.ValidateEndOfAttributes(null);
            val.ValidateEndElement(info);

            val.ValidateWhitespace(StringGetter(" \t\r\n"));

            val.ValidateEndElement(info);
            val.EndValidation();

            Assert.True(!holder.IsCalledA);
            Assert.Equal(info.Validity, XmlSchemaValidity.Valid);
            Assert.Equal(info.ContentType, XmlSchemaContentType.ElementOnly);

            return;
        }
コード例 #7
0
        public void CheckThatWarningOccursWhenInvalidNoNamespaceSchemaLocationIsProvided()
        {
            XmlSchemaValidator     val;
            XmlSchemaSet           schemas = new XmlSchemaSet();
            XmlSchemaInfo          info    = new XmlSchemaInfo();
            CValidationEventHolder holder  = new CValidationEventHolder();

            schemas.Add("", XmlReader.Create(new StringReader("<?xml version=\"1.0\" ?>\n" +
                                                              "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" +
                                                              "    <xs:complexType name=\"rootType\">\n" +
                                                              "        <xs:sequence />\n" +
                                                              "    </xs:complexType>\n" +
                                                              "</xs:schema>")));
            val                         = CreateValidator(schemas);
            val.XmlResolver             = new XmlUrlResolver();
            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateElement("root", "", info, "rootType", null, null, Path.Combine(TestData, "__NonExistingFile__.xsd"));

            Assert.True(holder.IsCalledA);
            Assert.Equal(XmlSeverityType.Warning, holder.lastSeverity);
            _exVerifier.IsExceptionOk(holder.lastException, "Sch_CannotLoadSchema", new string[] { "", null });

            return;
        }
コード例 #8
0
        public void CheckNoNamespaceSchemaLocationIs_UsedWhenSpecified_NotUsedWhenFlagIsSet(XmlSchemaValidationFlags allFlags)
        {
            XmlSchemaValidator     val;
            XmlSchemaSet           schemas = new XmlSchemaSet();
            XmlSchemaInfo          info    = new XmlSchemaInfo();
            CValidationEventHolder holder  = new CValidationEventHolder();

            schemas.Add("", XmlReader.Create(new StringReader("<?xml version=\"1.0\" ?>\n" +
                                                              "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" +
                                                              "    <xs:element name=\"root\" />\n" +
                                                              "</xs:schema>")));
            val                         = CreateValidator(schemas, allFlags);
            val.XmlResolver             = new XmlUrlResolver();
            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateElement("root", "", info, "type1", null, null, Path.Combine(TestData, XSDFILE_NO_TARGET_NAMESPACE));

            if ((int)allFlags == (int)AllFlags)
            {
                Assert.True(!holder.IsCalledA);
                Assert.True(info.SchemaType is XmlSchemaComplexType);
            }
            else
            {
                Assert.True(holder.IsCalledA);
                _exVerifier.IsExceptionOk(holder.lastException, "Sch_XsiTypeNotFound", new string[] { "type1" });
            }

            return;
        }
コード例 #9
0
        public void Default_Null_ArbitraryObject_XmlReader_XmlDocument_XPathNavigator_ProvidedAsValidationEventSender(string param)
        {
            XmlSchemaInfo          info   = new XmlSchemaInfo();
            XmlSchemaValidator     val    = CreateValidator(CreateSchemaSetFromXml("<root>foo</root>"));
            CValidationEventHolder holder = new CValidationEventHolder();
            object sender = null;

            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            switch (param)
            {
            case "default":
                sender = val;
                break;

            case "null":
                sender = null;
                break;

            case "arbitrary":
                sender = new ArrayList();
                break;

            case "reader":
                sender = XmlReader.Create(new StringReader("<root/>"));
                break;

            case "document":
                sender = new XmlDocument();
                break;

            case "navigator":
                XmlDocument d = new XmlDocument();
                sender = d.CreateNavigator();
                break;

            default:
                Assert.True(false);
                break;
            }

            if (param != "default")
            {
                val.ValidationEventSender = sender;
            }

            val.Initialize();
            val.ValidateElement("bar", "", info);

            Assert.True(holder.IsCalledA);
            Assert.Equal(sender, holder.lastObjectSent);

            return;
        }
コード例 #10
0
        public void TopLevelText()
        {
            XmlSchemaValidator     val    = CreateValidator(XSDFILE_VALIDATE_TEXT);
            CValidationEventHolder holder = new CValidationEventHolder();

            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateText(StringGetter("foo"));
            val.EndValidation();

            Assert.True(!holder.IsCalledA);

            return;
        }
コード例 #11
0
        public void TopLevelWhitespace()
        {
            XmlSchemaValidator     val    = CreateValidator(XSDFILE_VALIDATE_TEXT);
            CValidationEventHolder holder = new CValidationEventHolder();

            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateWhitespace(" \t" + Environment.NewLine);
            val.EndValidation();

            Assert.True(!holder.IsCalledA);

            return;
        }
コード例 #12
0
        public void SanityTestsForValidationEventHandler()
        {
            XmlSchemaInfo          info   = new XmlSchemaInfo();
            XmlSchemaValidator     val    = CreateValidator(CreateSchemaSetFromXml("<root>foo</root>"));
            CValidationEventHolder holder = new CValidationEventHolder();

            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateElement("bar", "", info);

            Assert.True(holder.IsCalledA);

            return;
        }
コード例 #13
0
        public void TopLevelText()
        {
            XmlSchemaValidator val = CreateValidator(XSDFILE_VALIDATE_TEXT);
            CValidationEventHolder holder = new CValidationEventHolder();

            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateText(StringGetter("foo"));
            val.EndValidation();

            Assert.True(!holder.IsCalledA);

            return;
        }
コード例 #14
0
        public void ValidationCallProducesValidationErrorInsideValidationEventHandler__Nesting()
        {
            XmlSchemaInfo          info   = new XmlSchemaInfo();
            XmlSchemaValidator     val    = CreateValidator(CreateSchemaSetFromXml("<root>foo</root>"));
            CValidationEventHolder holder = new CValidationEventHolder();

            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackNested);

            val.Initialize();
            val.ValidateElement("bar", "", info);

            Assert.Equal(holder.NestingDepth, 3);

            return;
        }
コード例 #15
0
        public void TopLevelWhitespace()
        {
            XmlSchemaValidator val = CreateValidator(XSDFILE_VALIDATE_TEXT);
            CValidationEventHolder holder = new CValidationEventHolder();

            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateWhitespace(" \t\r\n");
            val.EndValidation();

            Assert.True(!holder.IsCalledA);

            return;
        }
コード例 #16
0
        public void CheckThatWarningsDontOccurWhenIgnoreValidationWarningsIsSet()
        {
            XmlSchemaValidator     val;
            CValidationEventHolder holder = new CValidationEventHolder();

            val = CreateValidator(XSDFILE_VALIDATE_END_ELEMENT, "", XmlSchemaValidationFlags.ProcessIdentityConstraints | XmlSchemaValidationFlags.ProcessInlineSchema | XmlSchemaValidationFlags.ProcessSchemaLocation);
            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateElement("LaxElement", "", null);
            val.ValidateEndOfAttributes(null);
            val.ValidateElement("undefined", "", null);

            Assert.True(!holder.IsCalledA);

            return;
        }
コード例 #17
0
        public void CheckThatWarningOccursWhenUndefinedElementIsValidatedWithLaxValidation()
        {
            XmlSchemaValidator     val;
            CValidationEventHolder holder = new CValidationEventHolder();

            val = CreateValidator(XSDFILE_VALIDATE_END_ELEMENT);
            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateElement("LaxElement", "", null);
            val.ValidateEndOfAttributes(null);
            val.ValidateElement("undefined", "", null);

            Assert.True(holder.IsCalledA);
            Assert.Equal(XmlSeverityType.Warning, holder.lastSeverity);
            _exVerifier.IsExceptionOk(holder.lastException, "Sch_NoElementSchemaFound", new string[] { "undefined" });

            return;
        }
コード例 #18
0
        public void LineInfoProviderChangesDuringValidation()
        {
            string                 xmlSrc = "<root><foo>FooText</foo></root>";
            XmlSchemaInfo          info   = new XmlSchemaInfo();
            CValidationEventHolder holder = new CValidationEventHolder();

            int lineNum = -1;
            int linePos = -1;

            XmlSchemaValidator val = CreateValidator(CreateSchemaSetFromXml(xmlSrc));

            val.ValidationEventHandler += holder.CallbackA;
            val.Initialize();

            foreach (int i in new int[] { 1111, 1333, 0 })
            {
                lineNum = i;
                linePos = i * 2;
                if (i == 0)
                {
                    val.LineInfoProvider = null;
                }
                else
                {
                    val.LineInfoProvider = new CDummyLineInfo(lineNum, linePos);
                }

                val.ValidateElement("root", "", info);
                val.ValidateEndOfAttributes(null);
                val.ValidateElement("bar", "", info);
                Assert.True(holder.IsCalledA);

                Assert.Equal(holder.lastException.LineNumber, lineNum);
                Assert.Equal(holder.lastException.LinePosition, linePos);

                val.SkipToEndElement(info);
                val.SkipToEndElement(info);
                holder.IsCalledA = false;
            }

            return;
        }
コード例 #19
0
        public void ErrorHandlingAfterValidationError()
        {
            XmlSchemaInfo          info   = new XmlSchemaInfo();
            XmlSchemaValidator     val    = CreateValidator(CreateSchemaSetFromXml("<root><foo/></root>"));
            CValidationEventHolder holder = new CValidationEventHolder();

            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateElement("root", "", info);
            val.ValidateEndOfAttributes(null);

            val.ValidateElement("bar", "", info);
            Assert.True(holder.IsCalledA);
            val.SkipToEndElement(info);
            val.SkipToEndElement(info);

            holder.IsCalledA = false;
            val.ValidateElement("bar", "", info);
            Assert.True(holder.IsCalledA);

            return;
        }
コード例 #20
0
ファイル: PropertiesTests.cs プロジェクト: geoffkizer/corefx
        public void Default_Null_ArbitraryObject_XmlReader_XmlDocument_XPathNavigator_ProvidedAsValidationEventSender(String param)
        {
            XmlSchemaInfo info = new XmlSchemaInfo();
            XmlSchemaValidator val = CreateValidator(CreateSchemaSetFromXml("<root>foo</root>"));
            CValidationEventHolder holder = new CValidationEventHolder();
            object sender = null;

            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            switch (param)
            {
                case "default":
                    sender = val;
                    break;

                case "null":
                    sender = null;
                    break;

                case "arbitrary":
                    sender = new ArrayList();
                    break;

                case "reader":
                    sender = XmlReader.Create(new StringReader("<root/>"));
                    break;

                case "document":
                    sender = new XmlDocument();
                    break;

                case "navigator":
                    XmlDocument d = new XmlDocument();
                    sender = d.CreateNavigator();
                    break;

                default:
                    Assert.True(false);
                    break;
            }

            if (param != "default")
                val.ValidationEventSender = sender;

            val.Initialize();
            val.ValidateElement("bar", "", info);

            Assert.True(holder.IsCalledA);
            Assert.Equal(sender, holder.lastObjectSent);

            return;
        }
コード例 #21
0
        public void IncompleteContent__Invalid()
        {
            XmlSchemaValidator val = CreateValidator(XSDFILE_VALIDATE_END_ELEMENT);
            XmlSchemaInfo info = new XmlSchemaInfo();
            CValidationEventHolder holder = new CValidationEventHolder();

            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateElement("ComplexElement", "", info);
            val.ValidateEndOfAttributes(null);

            foreach (string name in new string[] { "e1", "e2" })
            {
                val.ValidateElement(name, "", info);
                val.ValidateEndOfAttributes(null);
                val.ValidateEndElement(info);
            }

            val.ValidateEndElement(info);

            Assert.True(holder.IsCalledA);
            Assert.Equal(holder.lastSeverity, XmlSeverityType.Error);
            Assert.Equal(info.Validity, XmlSchemaValidity.Invalid);

            return;
        }
コード例 #22
0
        public void MixedContent()
        {
            XmlSchemaValidator val = CreateValidator(XSDFILE_VALIDATE_TEXT);
            CValidationEventHolder holder = new CValidationEventHolder();
            XmlSchemaInfo info = new XmlSchemaInfo();

            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateElement("MixedElement", "", info);
            val.ValidateEndOfAttributes(null);

            val.ValidateText(StringGetter("some text"));

            val.ValidateElement("child", "", info);
            val.ValidateEndOfAttributes(null);
            val.ValidateEndElement(info);

            val.ValidateText(StringGetter("some other text"));

            val.ValidateEndElement(info);
            val.EndValidation();

            Assert.True(!holder.IsCalledA);
            Assert.Equal(info.Validity, XmlSchemaValidity.Valid);
            Assert.Equal(info.ContentType, XmlSchemaContentType.Mixed);

            return;
        }
コード例 #23
0
ファイル: PropertiesTests.cs プロジェクト: geoffkizer/corefx
        public void LineInfoProviderChangesDuringValidation()
        {
            string xmlSrc = "<root><foo>FooText</foo></root>";
            XmlSchemaInfo info = new XmlSchemaInfo();
            CValidationEventHolder holder = new CValidationEventHolder();

            int lineNum = -1;
            int linePos = -1;

            XmlSchemaValidator val = CreateValidator(CreateSchemaSetFromXml(xmlSrc));

            val.ValidationEventHandler += holder.CallbackA;
            val.Initialize();

            foreach (int i in new int[] { 1111, 1333, 0 })
            {
                lineNum = i;
                linePos = i * 2;
                if (i == 0)
                    val.LineInfoProvider = null;
                else
                    val.LineInfoProvider = new CDummyLineInfo(lineNum, linePos);

                val.ValidateElement("root", "", info);
                val.ValidateEndOfAttributes(null);
                val.ValidateElement("bar", "", info);
                Assert.True(holder.IsCalledA);

                Assert.Equal(holder.lastException.LineNumber, lineNum);
                Assert.Equal(holder.lastException.LinePosition, linePos);

                val.SkipToEndElement(info);
                val.SkipToEndElement(info);
                holder.IsCalledA = false;
            }

            return;
        }
コード例 #24
0
ファイル: ValidateElement.cs プロジェクト: dotnet/corefx
        public void CheckNoNamespaceSchemaLocationIs_UsedWhenSpecified_NotUsedWhenFlagIsSet(XmlSchemaValidationFlags allFlags)
        {
            XmlSchemaValidator val;
            XmlSchemaSet schemas = new XmlSchemaSet();
            XmlSchemaInfo info = new XmlSchemaInfo();
            CValidationEventHolder holder = new CValidationEventHolder();

            schemas.Add("", XmlReader.Create(new StringReader("<?xml version=\"1.0\" ?>\n" +
                                                              "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" +
                                                              "    <xs:element name=\"root\" />\n" +
                                                              "</xs:schema>")));
            val = CreateValidator(schemas, allFlags);
            val.XmlResolver = new XmlUrlResolver();
            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateElement("root", "", info, "type1", null, null, Path.Combine(TestData, XSDFILE_NO_TARGET_NAMESPACE));

            if ((int)allFlags == (int)AllFlags)
            {
                Assert.True(!holder.IsCalledA);
                Assert.True(info.SchemaType is XmlSchemaComplexType);
            }
            else
            {
                Assert.True(holder.IsCalledA);
                //XmlExceptionVerifier.IsExceptionOk(holder.lastException);
            }

            return;
        }
コード例 #25
0
ファイル: ValidateElement.cs プロジェクト: dotnet/corefx
        public void CheckThatWarningOccursWhenUndefinedElementIsValidatedWithLaxValidation()
        {
            XmlSchemaValidator val;
            CValidationEventHolder holder = new CValidationEventHolder();

            val = CreateValidator(XSDFILE_VALIDATE_END_ELEMENT);
            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateElement("LaxElement", "", null);
            val.ValidateEndOfAttributes(null);
            val.ValidateElement("undefined", "", null);

            Assert.True(holder.IsCalledA);
            Assert.Equal(holder.lastSeverity, XmlSeverityType.Warning);
            //XmlExceptionVerifier.IsExceptionOk(holder.lastException, "Sch_NoElementSchemaFound", new string[] { "undefined" });

            return;
        }
コード例 #26
0
ファイル: PropertiesTests.cs プロジェクト: geoffkizer/corefx
        public void ValidationCallProducesValidationErrorInsideValidationEventHandler__Nesting()
        {
            XmlSchemaInfo info = new XmlSchemaInfo();
            XmlSchemaValidator val = CreateValidator(CreateSchemaSetFromXml("<root>foo</root>"));
            CValidationEventHolder holder = new CValidationEventHolder();

            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackNested);

            val.Initialize();
            val.ValidateElement("bar", "", info);

            Assert.Equal(holder.NestingDepth, 3);

            return;
        }
コード例 #27
0
ファイル: ValidateElement.cs プロジェクト: dotnet/corefx
        public void CheckThatWarningOccursWhenInvalidNoNamespaceSchemaLocationIsProvided()
        {
            XmlSchemaValidator val;
            XmlSchemaSet schemas = new XmlSchemaSet();
            XmlSchemaInfo info = new XmlSchemaInfo();
            CValidationEventHolder holder = new CValidationEventHolder();

            schemas.Add("", XmlReader.Create(new StringReader("<?xml version=\"1.0\" ?>\n" +
                                                              "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" +
                                                              "    <xs:complexType name=\"rootType\">\n" +
                                                              "        <xs:sequence />\n" +
                                                              "    </xs:complexType>\n" +
                                                              "</xs:schema>")));
            val = CreateValidator(schemas);
            val.XmlResolver = new XmlUrlResolver();
            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateElement("root", "", info, "rootType", null, null, Path.Combine(TestData, "__NonExistingFile__.xsd"));

            Assert.True(holder.IsCalledA);
            Assert.Equal(holder.lastSeverity, XmlSeverityType.Warning);
            //XmlExceptionVerifier.IsExceptionOk(holder.lastException, "Sch_CannotLoadSchema", new string[] { "", null });

            return;
        }
コード例 #28
0
ファイル: PropertiesTests.cs プロジェクト: geoffkizer/corefx
        public void ErrorHandlingAfterValidationError()
        {
            XmlSchemaInfo info = new XmlSchemaInfo();
            XmlSchemaValidator val = CreateValidator(CreateSchemaSetFromXml("<root><foo/></root>"));
            CValidationEventHolder holder = new CValidationEventHolder();

            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateElement("root", "", info);
            val.ValidateEndOfAttributes(null);

            val.ValidateElement("bar", "", info);
            Assert.True(holder.IsCalledA);
            val.SkipToEndElement(info);
            val.SkipToEndElement(info);

            holder.IsCalledA = false;
            val.ValidateElement("bar", "", info);
            Assert.True(holder.IsCalledA);

            return;
        }
コード例 #29
0
ファイル: ValidateElement.cs プロジェクト: dotnet/corefx
        public void CheckThatWarningsDontOccurWhenIgnoreValidationWarningsIsSet()
        {
            XmlSchemaValidator val;
            CValidationEventHolder holder = new CValidationEventHolder();

            val = CreateValidator(XSDFILE_VALIDATE_END_ELEMENT, "", XmlSchemaValidationFlags.ProcessIdentityConstraints | XmlSchemaValidationFlags.ProcessInlineSchema | XmlSchemaValidationFlags.ProcessSchemaLocation);
            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateElement("LaxElement", "", null);
            val.ValidateEndOfAttributes(null);
            val.ValidateElement("undefined", "", null);

            Assert.True(!holder.IsCalledA);

            return;
        }
コード例 #30
0
ファイル: PropertiesTests.cs プロジェクト: geoffkizer/corefx
        public void MultipleEventHandlersAttachedToValidator()
        {
            XmlSchemaInfo info = new XmlSchemaInfo();
            XmlSchemaValidator val = CreateValidator(CreateSchemaSetFromXml("<root>foo</root>"));
            CValidationEventHolder holder = new CValidationEventHolder();

            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);
            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackB);

            val.Initialize();
            val.ValidateElement("bar", "", info);

            Assert.True(holder.IsCalledA);
            Assert.True(holder.IsCalledB);

            return;
        }