From: Oleg T. <he...@us...> - 2005-10-16 15:17:16
|
Update of /cvsroot/mvp-xml/XPointer/v2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18461/v2/test Added Files: .cvsignore EntryPoint.cs XPointerParserTests.cs XPointerReaderTests.cs XPointerTest.csproj changelog.txt northwind.dtd northwind.xml pubNS.xsd pubsNS.xml Log Message: --- NEW FILE: .cvsignore --- bin obj *.user *.suo --- NEW FILE: EntryPoint.cs --- using System; namespace Mvp.Xml.XPointer.Test { /// <summary> /// Entry point for console application. /// </summary> public class EntryPoint { public static void Main() { //XPointerParserTests pt = new XPointerParserTests(); //pt.CircumflexErrorTest(); XPointerReaderTests rt = new XPointerReaderTests(); try { rt.XSDDefnedIDTest(); } catch (Exception e) { Console.WriteLine(e); } } } } --- NEW FILE: changelog.txt --- --------------------------------------------------------- October 11, 2004 Added test XML/XSD and unit test for schema-determined IDs. --------------------------------------------------------- October 9, 2004 Added unit tests. --------------------------------------------------------- September 28, 2004 Initial setup. Will contain the project's tests. --- NEW FILE: XPointerTest.csproj --- (This appears to be a binary file; contents omitted.) --- NEW FILE: XPointerParserTests.cs --- using System; using System.Diagnostics; using Mvp.Xml.XPointer; using NUnit.Framework; namespace Mvp.Xml.XPointer.Test { /// <summary> /// Summary description for XPointerParserTests. /// </summary> [TestFixture] public class XPointerParserTests { public XPointerParserTests() { Debug.Listeners.Add(new TextWriterTraceListener(Console.Error)); } [Test] [ExpectedException(typeof(XPointerSyntaxException))] public void SyntaxErrorTest() { Pointer p = Pointer.Compile("too bad"); } [Test] public void ParenthesisTest() { Pointer p = Pointer.Compile("xmlns(p=http://foo.com^))"); p = Pointer.Compile("xmlns(p=http://foo.com^()"); } [Test] public void EscapingCircumflexTest() { Pointer p = Pointer.Compile("xmlns(p=http://foo.com^^)"); } [Test] [ExpectedException(typeof(XPointerSyntaxException))] public void CircumflexErrorTest() { Pointer p = Pointer.Compile("xmlns(p=http://fo^o.com)"); } [Test] [ExpectedException(typeof(XPointerSyntaxException))] public void BadNCName() { Pointer p = Pointer.Compile("foo:bar"); } [Test] [ExpectedException(typeof(XPointerSyntaxException))] public void BadElementPointer() { Pointer p = Pointer.Compile("element(1/33/foo)"); } [Test] public void UnknownSchemePointer() { Pointer p = Pointer.Compile("xpath1(/foo) foo(abr)"); } } } --- NEW FILE: pubsNS.xml --- <?xml version="1.0"?> <dsPubs id="123" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="pubNS.xsd"> <publishers pub_id="id07364"> <pub_name>New Moon Books</pub_name> <city>Boston</city> <state>MA</state> <country>USA</country> <titles> <title_id>BU2075</title_id> <title>You Can Combat Computer Stress!</title> <type>business </type> <pub_id>0736</pub_id> <price>2.99</price> <advance>10125</advance> <royalty>24</royalty> <ytd_sales>18722</ytd_sales> <notes>The latest medical and psychological techniques for living with the electronic office. Easy-to-understand explanations.</notes> <pubdate>1991-06-30T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>PS2091</title_id> <title>Is Anger the Enemy?</title> <type>psychology </type> <pub_id>0736</pub_id> <price>10.95</price> <advance>2275</advance> <royalty>12</royalty> <ytd_sales>2045</ytd_sales> <notes>Carefully researched study of the effects of strong emotions on the body. Metabolic charts included.</notes> <pubdate>1991-06-15T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>PS2106</title_id> <title>Life Without Fear</title> <type>psychology </type> <pub_id>0736</pub_id> <price>7</price> <advance>6000</advance> <royalty>10</royalty> <ytd_sales>111</ytd_sales> <notes>New exercise, meditation, and nutritional techniques that can reduce the shock of daily interactions. Popular audience. Sample menus included, exercise video available separately.</notes> <pubdate>1991-10-05T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>PS3333</title_id> <title>Prolonged Data Deprivation: Four Case Studies</title> <type>psychology </type> <pub_id>0736</pub_id> <price>19.99</price> <advance>2000</advance> <royalty>10</royalty> <ytd_sales>4072</ytd_sales> <notes>What happens when the data runs dry? Searching evaluations of information-shortage effects.</notes> <pubdate>1991-06-12T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>PS7777</title_id> <title>Emotional Security: A New Algorithm</title> <type>psychology </type> <pub_id>0736</pub_id> <price>7.99</price> <advance>4000</advance> <royalty>10</royalty> <ytd_sales>3336</ytd_sales> <notes>Protecting yourself and your loved ones from undue emotional stress in the modern world. Use of computer and nutritional aids emphasized.</notes> <pubdate>1991-06-12T00:00:00.0000000-03:00</pubdate> </titles> </publishers> <publishers pub_id="id0877"> <pub_name>Binnet & Hardley</pub_name> <city>Washington</city> <state>DC</state> <country>USA</country> <titles> <title_id>MC2222</title_id> <title>Silicon Valley Gastronomic Treats</title> <type>mod_cook </type> <pub_id>0877</pub_id> <price>19.99</price> <advance>0</advance> <royalty>12</royalty> <ytd_sales>2032</ytd_sales> <notes>Favorite recipes for quick, easy, and elegant meals.</notes> <pubdate>1991-06-09T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>MC3021</title_id> <title>The Gourmet Microwave</title> <type>mod_cook </type> <pub_id>0877</pub_id> <price>2.99</price> <advance>15000</advance> <royalty>24</royalty> <ytd_sales>22246</ytd_sales> <notes>Traditional French gourmet recipes adapted for modern microwave cooking.</notes> <pubdate>1991-06-18T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>MC3026</title_id> <title>The Psychology of Computer Cooking</title> <type>UNDECIDED </type> <pub_id>0877</pub_id> <pubdate>2000-08-06T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>PS1372</title_id> <title>Computer Phobic AND Non-Phobic Individuals: Behavior Variations</title> <type>psychology </type> <pub_id>0877</pub_id> <price>21.59</price> <advance>7000</advance> <royalty>10</royalty> <ytd_sales>375</ytd_sales> <notes>A must for the specialist, this book examines the difference between those who hate and fear computers and those who don't.</notes> <pubdate>1991-10-21T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>TC3218</title_id> <title>Onions, Leeks, and Garlic: Cooking Secrets of the Mediterranean</title> <type>trad_cook </type> <pub_id>0877</pub_id> <price>20.95</price> <advance>7000</advance> <royalty>10</royalty> <ytd_sales>375</ytd_sales> <notes>Profusely illustrated in color, this makes a wonderful gift book for a cuisine-oriented friend.</notes> <pubdate>1991-10-21T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>TC4203</title_id> <title>Fifty Years in Buckingham Palace Kitchens</title> <type>trad_cook </type> <pub_id>0877</pub_id> <price>11.95</price> <advance>4000</advance> <royalty>14</royalty> <ytd_sales>15096</ytd_sales> <notes>More anecdotes from the Queen's favorite cook describing life among English royalty. Recipes, techniques, tender vignettes.</notes> <pubdate>1991-06-12T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>TC7777</title_id> <title>Sushi, Anyone?</title> <type>trad_cook </type> <pub_id>0877</pub_id> <price>14.99</price> <advance>8000</advance> <royalty>10</royalty> <ytd_sales>4095</ytd_sales> <notes>Detailed instructions on how to make authentic Japanese sushi in your spare time.</notes> <pubdate>1991-06-12T00:00:00.0000000-03:00</pubdate> </titles> </publishers> <publishers pub_id="id1389"> <pub_name>Algodata Infosystems</pub_name> <city>Berkeley</city> <state>CA</state> <country>USA</country> <titles> <title_id>BU1032</title_id> <title>The Busy Executive's Database Guide</title> <type>business </type> <pub_id>1389</pub_id> <price>19.99</price> <advance>5000</advance> <royalty>10</royalty> <ytd_sales>4095</ytd_sales> <notes>An overview of available database systems with emphasis on common business applications. Illustrated.</notes> <pubdate>1991-06-12T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>BU1111</title_id> <title>Cooking with Computers: Surreptitious Balance Sheets</title> <type>business </type> <pub_id>1389</pub_id> <price>11.95</price> <advance>5000</advance> <royalty>10</royalty> <ytd_sales>3876</ytd_sales> <notes>Helpful hints on how to use your electronic resources to the best advantage.</notes> <pubdate>1991-06-09T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>BU7832</title_id> <title>Straight Talk About Computers</title> <type>business </type> <pub_id>1389</pub_id> <price>19.99</price> <advance>5000</advance> <royalty>10</royalty> <ytd_sales>4095</ytd_sales> <notes>Annotated analysis of what computers can do for you: a no-hype guide for the critical user.</notes> <pubdate>1991-06-22T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>PC1035</title_id> <title>But Is It User Friendly?</title> <type>popular_comp</type> <pub_id>1389</pub_id> <price>22.95</price> <advance>7000</advance> <royalty>16</royalty> <ytd_sales>8780</ytd_sales> <notes>A survey of software for the naive user, focusing on the 'friendliness' of each.</notes> <pubdate>1991-06-30T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>PC8888</title_id> <title>Secrets of Silicon Valley</title> <type>popular_comp</type> <pub_id>1389</pub_id> <price>20</price> <advance>8000</advance> <royalty>10</royalty> <ytd_sales>4095</ytd_sales> <notes>Muckraking reporting on the world's largest computer hardware and software manufacturers.</notes> <pubdate>1994-06-12T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>PC9999</title_id> <title>Net Etiquette</title> <type>popular_comp</type> <pub_id>1389</pub_id> <notes>A must-read for computer conferencing.</notes> <pubdate>2000-08-06T00:00:00.0000000-03:00</pubdate> </titles> </publishers> <publishers pub_id="id1622"> <pub_name>Five Lakes Publishing</pub_name> <city>Chicago</city> <state>IL</state> <country>USA</country> </publishers> <publishers pub_id="id1756"> <pub_name>Ramona Publishers</pub_name> <city>Dallas</city> <state>TX</state> <country>USA</country> </publishers> <publishers pub_id="id9901"> <pub_name>GGG&G</pub_name> <city>München</city> <country>Germany</country> </publishers> <publishers pub_id="id9952"> <pub_name>Scootney Books</pub_name> <city>New York</city> <state>NY</state> <country>USA</country> </publishers> <publishers pub_id="id9999"> <pub_name>Lucerne Publishing</pub_name> <city>Paris</city> <country>France</country> </publishers> <publishers pub_id="id0736"> <pub_name>New Moon Books</pub_name> <city>Boston</city> <state>MA</state> <country>USA</country> <titles> <title_id>BU2075</title_id> <title>You Can Combat Computer Stress!</title> <type>business </type> <pub_id>0736</pub_id> <price>2.99</price> <advance>10125</advance> <royalty>24</royalty> <ytd_sales>18722</ytd_sales> <notes>The latest medical and psychological techniques for living with the electronic office. Easy-to-understand explanations.</notes> <pubdate>1991-06-30T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>PS2091</title_id> <title>Is Anger the Enemy?</title> <type>psychology </type> <pub_id>0736</pub_id> <price>10.95</price> <advance>2275</advance> <royalty>12</royalty> <ytd_sales>2045</ytd_sales> <notes>Carefully researched study of the effects of strong emotions on the body. Metabolic charts included.</notes> <pubdate>1991-06-15T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>PS2106</title_id> <title>Life Without Fear</title> <type>psychology </type> <pub_id>0736</pub_id> <price>7</price> <advance>6000</advance> <royalty>10</royalty> <ytd_sales>111</ytd_sales> <notes>New exercise, meditation, and nutritional techniques that can reduce the shock of daily interactions. Popular audience. Sample menus included, exercise video available separately.</notes> <pubdate>1991-10-05T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>PS3333</title_id> <title>Prolonged Data Deprivation: Four Case Studies</title> <type>psychology </type> <pub_id>0736</pub_id> <price>19.99</price> <advance>2000</advance> <royalty>10</royalty> <ytd_sales>4072</ytd_sales> <notes>What happens when the data runs dry? Searching evaluations of information-shortage effects.</notes> <pubdate>1991-06-12T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>PS7777</title_id> <title>Emotional Security: A New Algorithm</title> <type>psychology </type> <pub_id>0736</pub_id> <price>7.99</price> <advance>4000</advance> <royalty>10</royalty> <ytd_sales>3336</ytd_sales> <notes>Protecting yourself and your loved ones from undue emotional stress in the modern world. Use of computer and nutritional aids emphasized.</notes> <pubdate>1991-06-12T00:00:00.0000000-03:00</pubdate> </titles> </publishers> </dsPubs> --- NEW FILE: northwind.xml --- (This appears to be a binary file; contents omitted.) --- NEW FILE: XPointerReaderTests.cs --- using System; using System.Xml.XPath; using System.Xml; using System.Text; using System.IO; using Mvp.Xml.Tests; using Mvp.Xml.XPointer; using NUnit.Framework; namespace Mvp.Xml.XPointer.Test { /// <summary> /// Unit tests for XPointerReader class. /// </summary> [TestFixture] public class XPointerReaderTests { /// <summary> /// xmlns() + xpath1() + namespaces works /// </summary> [Test] public void XmlNsXPath1SchemeTest() { string xptr = "xmlns(m=mvp-xml)xpath1(m:dsPubs/m:publishers[m:pub_id='1389']/m:pub_name)"; XmlReader reader = new XmlTextReader(Globals.GetResource(Globals.PubsNsResource)); XPointerReader xpr = new XPointerReader(reader, xptr); StringBuilder sb = new StringBuilder(); while (xpr.Read()) { sb.Append(xpr.ReadOuterXml()); } string expected = @"<pub_name xmlns=""mvp-xml"">Algodata Infosystems</pub_name><pub_name xmlns=""mvp-xml"">Algodata Infosystems</pub_name><pub_name xmlns=""mvp-xml"">Algodata Infosystems</pub_name><pub_name xmlns=""mvp-xml"">Algodata Infosystems</pub_name><pub_name xmlns=""mvp-xml"">Algodata Infosystems</pub_name>"; Assert.AreEqual(sb.ToString(), expected); } /// <summary> /// xpath1() + namespaces doesn't work w/o xmlns() /// </summary> [Test] [ExpectedException(typeof(NoSubresourcesIdentifiedException))] public void XPath1SchemeWithoutXmlnsTest() { string xptr = "xpath1(m:dsPubs/m:publishers[m:pub_id='1389']/m:pub_name)"; XmlReader reader = new XmlTextReader(Globals.GetResource(Globals.PubsNsResource)); XPointerReader xpr = new XPointerReader(reader, xptr); StringBuilder sb = new StringBuilder(); while (xpr.Read()) { sb.Append(xpr.ReadOuterXml()); } string expected = @"<pub_name xmlns=""mvp-xml"">Algodata Infosystems</pub_name><pub_name xmlns=""mvp-xml"">Algodata Infosystems</pub_name><pub_name xmlns=""mvp-xml"">Algodata Infosystems</pub_name><pub_name xmlns=""mvp-xml"">Algodata Infosystems</pub_name><pub_name xmlns=""mvp-xml"">Algodata Infosystems</pub_name>"; Assert.AreEqual(sb.ToString(), expected); } /// <summary> /// xpath1() that doesn't select a node w/o namespaces /// </summary> [Test] [ExpectedException(typeof(NoSubresourcesIdentifiedException))] public void XPath1SchemeNoSelectedNodeTest() { string xptr = "xpath1(no-such-node/foo)"; XmlReader reader = new XmlTextReader(Globals.GetResource(Globals.PubsNsResource)); XPointerReader xpr = new XPointerReader(reader, xptr); while (xpr.Read()) {} } /// <summary> /// xpath1() that returns scalar value, not a node /// </summary> [Test] [ExpectedException(typeof(NoSubresourcesIdentifiedException))] public void XPath1SchemeScalarResultTest() { string xptr = "xpath1(2+2)"; XmlReader reader = new XmlTextReader(Globals.GetResource(Globals.PubsNsResource)); XPointerReader xpr = new XPointerReader(reader, xptr); while (xpr.Read()) {} } /// <summary> /// xmlns() + xpointer() + namespaces works /// </summary> [Test] public void XmlNsXPointerSchemeTest() { string xptr = "xmlns(m=mvp-xml)xpointer(m:dsPubs/m:publishers[m:pub_id='1389']/m:pub_name)"; XmlReader reader = new XmlTextReader(Globals.GetResource(Globals.PubsNsResource)); XPointerReader xpr = new XPointerReader(reader, xptr); StringBuilder sb = new StringBuilder(); while (xpr.Read()) { sb.Append(xpr.ReadOuterXml()); } string expected = @"<pub_name xmlns=""mvp-xml"">Algodata Infosystems</pub_name><pub_name xmlns=""mvp-xml"">Algodata Infosystems</pub_name><pub_name xmlns=""mvp-xml"">Algodata Infosystems</pub_name><pub_name xmlns=""mvp-xml"">Algodata Infosystems</pub_name><pub_name xmlns=""mvp-xml"">Algodata Infosystems</pub_name>"; Assert.AreEqual(sb.ToString(), expected); } /// <summary> /// xpointer() + namespaces doesn't work w/o xmlns() /// </summary> [Test] [ExpectedException(typeof(NoSubresourcesIdentifiedException))] public void XPointerSchemeWithoutXmlnsTest() { string xptr = "xpointer(m:dsPubs/m:publishers[m:pub_id='1389']/m:pub_name)"; XmlReader reader = new XmlTextReader(Globals.GetResource(Globals.PubsNsResource)); XPointerReader xpr = new XPointerReader(reader, xptr); StringBuilder sb = new StringBuilder(); while (xpr.Read()) { sb.Append(xpr.ReadOuterXml()); } string expected = @"<pub_name xmlns=""mvp-xml"">Algodata Infosystems</pub_name><pub_name xmlns=""mvp-xml"">Algodata Infosystems</pub_name><pub_name xmlns=""mvp-xml"">Algodata Infosystems</pub_name><pub_name xmlns=""mvp-xml"">Algodata Infosystems</pub_name><pub_name xmlns=""mvp-xml"">Algodata Infosystems</pub_name>"; Assert.AreEqual(sb.ToString(), expected); } /// <summary> /// xpointer() that doesn't select a node w/o namespaces /// </summary> [Test] [ExpectedException(typeof(NoSubresourcesIdentifiedException))] public void XPointerSchemeNoSelectedNodeTest() { string xptr = "xpointer(no-such-node/foo)"; XmlReader reader = new XmlTextReader(Globals.GetResource(Globals.PubsNsResource)); XPointerReader xpr = new XPointerReader(reader, xptr); while (xpr.Read()) {} } /// <summary> /// xpointer() that returns scalar value, not a node /// </summary> [Test] [ExpectedException(typeof(NoSubresourcesIdentifiedException))] public void XPointerSchemeScalarResultTest() { string xptr = "xpointer(2+2)"; XmlReader reader = new XmlTextReader(Globals.GetResource(Globals.PubsNsResource)); XPointerReader xpr = new XPointerReader(reader, xptr); while (xpr.Read()) {} } /// <summary> /// superfluous xmlns() doesn't hurt /// </summary> [Test] public void SuperfluousXmlNsSchemeTest() { string xptr = "xmlns(m=mvp-xml)xpointer(dsPubs/publishers[pub_id='1389']/pub_name)"; XmlReader reader = new XmlTextReader(Globals.GetResource(Globals.PubsResource)); XPointerReader xpr = new XPointerReader(reader, xptr); StringBuilder sb = new StringBuilder(); while (xpr.Read()) { sb.Append(xpr.ReadOuterXml()); } string expected = @"<pub_name>Algodata Infosystems</pub_name>"; Assert.AreEqual(sb.ToString(), expected); } /// <summary> /// xpointer() + xmlns() + namespaces doesn't work /// </summary> [Test] [ExpectedException(typeof(NoSubresourcesIdentifiedException))] public void XmlnsAfterTest() { string xptr = "xpointer(m:dsPubs/m:publishers[m:pub_id='1389']/m:pub_name)xmlns(m=mvp-xml)"; XmlReader reader = new XmlTextReader(Globals.GetResource(Globals.PubsNsResource)); XPointerReader xpr = new XPointerReader(reader, xptr); while (xpr.Read()) {} } /// <summary> /// namespace re3efinition doesn't hurt /// </summary> [Test] public void NamespaceRedefinitionTest() { string xptr = "xmlns(m=mvp-xml)xmlns(m=http://foo.com)xmlns(m=mvp-xml)xpointer(m:dsPubs/m:publishers[m:pub_id='1389']/m:pub_name)"; XmlReader reader = new XmlTextReader(Globals.GetResource(Globals.PubsNsResource)); XPointerReader xpr = new XPointerReader(reader, xptr); StringBuilder sb = new StringBuilder(); while (xpr.Read()) { sb.Append(xpr.ReadOuterXml()); } string expected = @"<pub_name xmlns=""mvp-xml"">Algodata Infosystems</pub_name><pub_name xmlns=""mvp-xml"">Algodata Infosystems</pub_name><pub_name xmlns=""mvp-xml"">Algodata Infosystems</pub_name><pub_name xmlns=""mvp-xml"">Algodata Infosystems</pub_name><pub_name xmlns=""mvp-xml"">Algodata Infosystems</pub_name>"; Assert.AreEqual(sb.ToString(), expected); } /// <summary> /// Shorthand pointer works /// </summary> [Test] public void ShorthandTest() { string xptr = "o10535"; XmlReader reader = new XmlTextReader("../../northwind.xml"); XPointerReader xpr = new XPointerReader(reader, xptr); string expected = @"<Item orderID=""o10535""> <OrderDate> 6/13/95</OrderDate> <ShipAddress> Mataderos 2312</ShipAddress> </Item>"; while (xpr.Read()) { Assert.AreEqual(xpr.ReadOuterXml(), expected); return; } throw new InvalidOperationException("This means shorthand XPointer didn't work as expected."); } /// <summary> /// Shorthand pointer works via stream /// </summary> [Test] public void ShorthandViaStreamTest() { string xptr = "o10535"; FileInfo file = new FileInfo("../../northwind.xml"); using (FileStream fs = file.OpenRead()) { XPointerReader xpr = new XPointerReader( new XmlTextReader(file.FullName, fs), xptr); string expected = @"<Item orderID=""o10535""> <OrderDate> 6/13/95</OrderDate> <ShipAddress> Mataderos 2312</ShipAddress> </Item>"; while (xpr.Read()) { Assert.AreEqual(xpr.ReadOuterXml(), expected); return; } throw new InvalidOperationException("This means shorthand XPointer didn't work as expected."); } } /// <summary> /// Shorthand pointer points to nothing /// </summary> [Test] [ExpectedException(typeof(NoSubresourcesIdentifiedException))] public void ShorthandNotFoundTest() { string xptr = "no-such-id"; XmlReader reader = new XmlTextReader("../../northwind.xml"); XPointerReader xpr = new XPointerReader(reader, xptr); } /// <summary> /// element() scheme pointer works /// </summary> [Test] public void ElementSchemeTest() { string xptr = "element(o10535)"; XmlReader reader = new XmlTextReader("../../northwind.xml"); XPointerReader xpr = new XPointerReader(reader, xptr); string expected = @"<Item orderID=""o10535""> <OrderDate> 6/13/95</OrderDate> <ShipAddress> Mataderos 2312</ShipAddress> </Item>"; while (xpr.Read()) { Assert.AreEqual(xpr.ReadOuterXml(), expected); return; } throw new InvalidOperationException("This means XPointer didn't work as expected."); } /// <summary> /// element() scheme pointer works /// </summary> [Test] public void ElementSchemeTest2() { string xptr = "element(o10535/1)"; XmlReader reader = new XmlTextReader("../../northwind.xml"); XPointerReader xpr = new XPointerReader(reader, xptr); string expected = @"<OrderDate> 6/13/95</OrderDate>"; while (xpr.Read()) { Assert.AreEqual(xpr.ReadOuterXml(), expected); return; } throw new InvalidOperationException("This means XPointer didn't work as expected."); } /// <summary> /// element() scheme pointer works /// </summary> [Test] public void ElementSchemeTest3() { string xptr = "element(/1/1/2)"; XmlReader reader = new XmlTextReader("../../northwind.xml"); XPointerReader xpr = new XPointerReader(reader, xptr); string expected = @"<CompanyName> Alfreds Futterkiste</CompanyName>"; while (xpr.Read()) { Assert.AreEqual(xpr.ReadOuterXml(), expected); return; } throw new InvalidOperationException("This means XPointer didn't work as expected."); } /// <summary> /// element() scheme pointer points to nothing /// </summary> [Test] [ExpectedException(typeof(NoSubresourcesIdentifiedException))] public void ElementSchemeNotFoundTest() { string xptr = "element(no-such-id)"; XmlReader reader = new XmlTextReader("../../northwind.xml"); XPointerReader xpr = new XPointerReader(reader, xptr); } /// <summary> /// compound pointer /// </summary> [Test] public void CompoundPointerTest() { string xptr = "xmlns(p=12345)xpath1(/no/such/node) xpointer(/and/such) element(/1/1/2) element(o10535/1)"; XmlReader reader = new XmlTextReader("../../northwind.xml"); XPointerReader xpr = new XPointerReader(reader, xptr); string expected = @"<CompanyName> Alfreds Futterkiste</CompanyName>"; while (xpr.Read()) { Assert.AreEqual(xpr.ReadOuterXml(), expected); return; } throw new InvalidOperationException("This means XPointer didn't work as expected."); } /// <summary> /// Unknown scheme pointer /// </summary> [Test] public void UnknownSchemeTest() { string xptr = "dummy(foo) element(/1/1/2)"; XmlReader reader = new XmlTextReader("../../northwind.xml"); XPointerReader xpr = new XPointerReader(reader, xptr); string expected = @"<CompanyName> Alfreds Futterkiste</CompanyName>"; while (xpr.Read()) { Assert.AreEqual(xpr.ReadOuterXml(), expected); return; } throw new InvalidOperationException("This means XPointer didn't work as expected."); } /// <summary> /// Unknown scheme pointer /// </summary> [Test] public void UnknownSchemeTest2() { string xptr = "foo:dummy(bar) element(/1/1/2)"; XmlReader reader = new XmlTextReader("../../northwind.xml"); XPointerReader xpr = new XPointerReader(reader, xptr); string expected = @"<CompanyName> Alfreds Futterkiste</CompanyName>"; while (xpr.Read()) { Assert.AreEqual(xpr.ReadOuterXml(), expected); return; } throw new InvalidOperationException("This means XPointer didn't work as expected."); } /// <summary> /// Unknown scheme pointer /// </summary> [Test] public void UnknownSchemeTest3() { string xptr = "xmlns(foo=http://foo.com/schemas)foo:dummy(bar) element(/1/1/2)"; XmlReader reader = new XmlTextReader("../../northwind.xml"); XPointerReader xpr = new XPointerReader(reader, xptr); string expected = @"<CompanyName> Alfreds Futterkiste</CompanyName>"; while (xpr.Read()) { Assert.AreEqual(xpr.ReadOuterXml(), expected); return; } throw new InvalidOperationException("This means XPointer didn't work as expected."); } /// <summary> /// XSD-defined ID /// </summary> [Test] public void XSDDefnedIDTest() { string xptr = "element(id1389/1)"; XmlReader reader = new XmlTextReader("../../pubsNS.xml"); XPointerReader xpr = new XPointerReader(reader, xptr, true); string expected = @"<pub_name>Algodata Infosystems</pub_name>"; while (xpr.Read()) { Assert.AreEqual(xpr.ReadOuterXml(), expected); return; } throw new InvalidOperationException("This means XPointer didn't work as expected."); } } } --- NEW FILE: northwind.dtd --- (This appears to be a binary file; contents omitted.) --- NEW FILE: pubNS.xsd --- <?xml version="1.0"?> <xs:schema elementFormDefault="unqualified" attributeFormDefault="unqualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="dsPubs"> <xs:complexType> <xs:sequence> <xs:element ref="publishers" maxOccurs="unbounded"/> </xs:sequence> <xs:attribute name="id" type="xs:string"/> </xs:complexType> </xs:element> <xs:element name="publishers"> <xs:complexType> <xs:sequence> <xs:element name="pub_name" type="xs:string"/> <xs:element name="city" type="xs:string"/> <xs:element name="state" type="xs:string" minOccurs="0"/> <xs:element name="country" type="xs:string"/> <xs:element name="titles" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="title_id" type="xs:string"/> <xs:element name="title" type="xs:string"/> <xs:element name="type" type="xs:string"/> <xs:element name="pub_id" type="xs:unsignedShort"/> <xs:element name="price" type="xs:decimal" minOccurs="0"/> <xs:element name="advance" type="xs:unsignedShort" minOccurs="0"/> <xs:element name="royalty" type="xs:unsignedByte" minOccurs="0"/> <xs:element name="ytd_sales" type="xs:unsignedShort" minOccurs="0"/> <xs:element name="notes" type="xs:string" minOccurs="0"/> <xs:element name="pubdate" type="xs:dateTime"/> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="pub_id" type="xs:ID"/> </xs:complexType> </xs:element> </xs:schema> |