public static CreateXmlReaderFromString ( string data ) : XmlReader | ||
data | string | |
Результат | XmlReader |
public void Extensions_XmlIgnoreElement_Required_Failure_BadName() { using (XmlReader xml = Utilities.CreateXmlReaderFromString(simpleXmlDoc)) { xml.Read(); // <xml> xml.IgnoreElement(xml.NameTable.Add("skip_this"), IgnoreOptions.Required); } }
public void Extensions_XmlReadOptionalElementContentAsString_Failure_BadName() { using (XmlReader xml = Utilities.CreateXmlReaderFromString(simpleXmlDoc)) { xml.ReadStartElement("xml"); string elementName = xml.NameTable.Add("bad_name"); Assert.Null(xml.ReadOptionalElementContentAsString(elementName)); } }
public void Extensions_XmlReadOptionalElementContentAsString_Success() { using (XmlReader xml = Utilities.CreateXmlReaderFromString(simpleXmlDoc)) { xml.ReadStartElement("xml"); string elementName = xml.NameTable.Add("skip_this"); Assert.Equal("expected child content", xml.ReadOptionalElementContentAsString(elementName)); } }
public void Extensions_XmlIgnoreElement_Optional_Failure_BadName() { using (XmlReader xml = Utilities.CreateXmlReaderFromString(simpleXmlDoc)) { xml.Read(); // Position on <xml> xml.IgnoreElement(xml.NameTable.Add("skip_this"), IgnoreOptions.Optional); Assert.Equal("xml", xml.LocalName); } }
public void Extensions_XmlIgnoreElement_Optional_Success() { using (XmlReader xml = Utilities.CreateXmlReaderFromString(simpleXmlDoc)) { xml.ReadStartElement("xml"); xml.IgnoreElement(xml.NameTable.Add("skip_this"), IgnoreOptions.Optional); Assert.Equal("following", xml.LocalName); } }
public void Extensions_XmlIgnoreElement_Multiple_DoesNotOverread() { using (XmlReader xml = Utilities.CreateXmlReaderFromString(simpleXmlMulitDoc)) { xml.Read(); // Position on <xml> at depth 0 xml.Read(); // Position on <xml> at depth 1 xml.IgnoreElement(xml.NameTable.Add("xml"), IgnoreOptions.Multiple); Assert.Equal(XmlNodeType.EndElement, xml.NodeType); Assert.Equal(0, xml.Depth); } }
public void Extensions_XmlIgnoreElement_Singular_DoesNotOverread() { using (XmlReader xml = Utilities.CreateXmlReaderFromString(simpleXmlMulitDoc)) { xml.Read(); // Position on <xml> at depth 0 xml.Read(); // Position on <xml> at depth 1 xml.IgnoreElement(xml.NameTable.Add("xml"), IgnoreOptions.Optional); Assert.Equal(XmlNodeType.Element, xml.NodeType); Assert.Equal("following", xml.ReadElementContentAsString()); } }
public void Extensions_XmlReadOptionalElementContentAsString_Failure_BadNodeType() { using (XmlReader xml = Utilities.CreateXmlReaderFromString(simpleXmlDoc)) { xml.ReadStartElement("xml"); xml.ReadStartElement("skip_this"); // Position in the simple content inside <skip_this/> xml.Read(); // Now on end element Assert.Equal(XmlNodeType.EndElement, xml.NodeType); string elementName = xml.NameTable.Add("skip_this"); Assert.Null(xml.ReadOptionalElementContentAsString(elementName)); } }
public void Extensions_XmlCreateException_WithLineInfo() { // 0000000001111111111222222 // 1234567890123456789012345 using (XmlReader unitUnderTest = Utilities.CreateXmlReaderFromString("<hello> <world/> </hello>")) { unitUnderTest.Read(); // <hello> unitUnderTest.Read(); // <world> XmlException result = unitUnderTest.CreateException("cute fluffy kittens"); Assert.Equal(1, result.LineNumber); Assert.Equal(8, result.LinePosition); } }
public void Extensions_XmlIgnoreElement_OptionalMulti_Failure_BadNodeType() { using (XmlReader xml = Utilities.CreateXmlReaderFromString(simpleXmlDoc)) { xml.Read(); // Position on <xml> xml.Read(); // Position on <skip_this> xml.Read(); // Position on simple content xml.Read(); // Position on </skip_this> xml.IgnoreElement(xml.NameTable.Add("skip_this"), IgnoreOptions.Optional | IgnoreOptions.Multiple); xml.Read(); Assert.Equal("following", xml.LocalName); } }
public void Extensions_XmlIgnoreElement_Required_Failure_BadNodeType() { using (XmlReader xml = Utilities.CreateXmlReaderFromString(simpleXmlDoc)) { xml.Read(); // Position on <xml> xml.Read(); // Position on <skip_this> xml.Read(); // Position on simple content xml.Read(); // Position on </skip_this> Assert.Throws <XmlException>(() => xml.IgnoreElement(xml.NameTable.Add("skip_this"), IgnoreOptions.Required) ); } }
public void Extensions_XmlIgnoreElement_Multiple_WhenRequiredReadsZeroElements() { using (XmlReader xml = Utilities.CreateXmlReaderFromString(simpleXmlMulitDoc)) { xml.Read(); // Position on <xml> at depth 0 xml.Read(); // Position on <xml> at depth 1 try { xml.IgnoreElement(xml.NameTable.Add("different_element"), IgnoreOptions.Multiple); Assert.True(false); } catch (XmlException) { } Assert.Equal(XmlNodeType.Element, xml.NodeType); Assert.Equal("xml", xml.LocalName); Assert.Equal(1, xml.Depth); } }