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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }