public void TestXmlValidationSuccessWithEmbeddedSchemaReference() { const string xmlPath = @"xml\shiporder_valid.xml"; string baseUri = System.IO.Path.GetFullPath(xmlPath); using (System.IO.TextReader textReader = new System.IO.StreamReader(xmlPath)) { XmlReader xmlReader = new XmlReader( new XmlReaderParameters(textReader) { BaseUri = baseUri, Mode = XmlMode.Default, ValidationOptions = XmlReaderValidationFlags.ValidateXsd | XmlReaderValidationFlags.ReportValidationWarnings }); Assert.That(() => { xmlReader.Read(); }, Throws.Nothing); } }
public void TestXmlValidationSuccessWithoutInferringTypesFromSchema() { using (System.IO.StringReader xmlStream = new System.IO.StringReader(c_validXml), xsdStream = new System.IO.StringReader(c_xsd)) { XmlReader xmlReader = new XmlReader( new XmlReaderParameters(xmlStream) { Mode = XmlMode.Default, XsdStream = xsdStream, ValidationOptions = XmlReaderValidationFlags.ValidateXsd }); Variant v1 = xmlReader.Read(); Assert.AreEqual(v1.Type, Variant.EnumType.Dictionary); foreach (VariantItem item in v1) { Assert.That(item.Value.Type, Is.EqualTo(Variant.EnumType.Any)); } } }
public void TestXmlValidationFailureWithEmbeddedSchemaReference(string xmlPath, string expectedMessage) { string baseUri = System.IO.Path.GetFullPath(xmlPath); using (System.IO.TextReader textReader = new System.IO.StreamReader(xmlPath)) { XmlReader xmlReader = new XmlReader( new XmlReaderParameters(textReader) { BaseUri = baseUri, Mode = XmlMode.Default, ValidationOptions = XmlReaderValidationFlags.ValidateXsd | XmlReaderValidationFlags.ReportValidationWarnings }); Assert.That(() => { xmlReader.Read(); }, Throws.InstanceOf<VariantException>().With.Message.StartsWith(expectedMessage)); } }