public void XmlObjectPlainXmlTest() { var xmlObj = new XmlObject(PlainXml, null, null); Assert.AreEqual("https://localhost/Model.svc/Categories(41)", xmlObj.Evaluate("/feed/entry[1]/id")); Assert.AreEqual("41", xmlObj.Evaluate("/feed/entry[1]/content/properties/Id")); }
public void XmlObjectAtomTest() { var xmlObj = new XmlObject(AtomXml, "atom", "m:type"); Assert.AreEqual( "https://localhost/Model.svc/Categories(41)", xmlObj.Evaluate("/atom:feed/atom:entry[1]/atom:id")); Assert.AreEqual("41", xmlObj.Evaluate("/atom:feed/atom:entry[1]/atom:content/m:properties/d:Id")); }
public void XmlObjectTrimTest() { const string source = "<text> aa </text>"; const string locator = "/text"; var noTrim = new XmlObject(source, "q", null); Assert.AreEqual(" aa ", noTrim.GetProperty(locator)); Assert.AreEqual(" aa ", noTrim.Evaluate(locator)); var trim = new XmlObject(source, "q", null, true); Assert.AreEqual("aa", trim.GetProperty(locator)); Assert.AreEqual("aa", trim.Evaluate(locator)); }
public void XmlObjectAddXmlTest() { var xmlObj = new XmlObject(AtomXml, "atom", "m:type"); var objToAdd = new XmlObject( "<?xml version=\"1.0\"?><contributor><name>Lara</name></contributor>", null, null); xmlObj.AddAt(objToAdd, "/atom:feed/atom:entry[2]/atom:content/m:properties"); Assert.AreEqual( "Lara", xmlObj.Evaluate("/atom:feed/atom:entry[2]/atom:content/m:properties/contributor/name")); }
public void XmlObjectEvaluateTest() { const string items = "<item id=\"myId\">3349</item>\r\n<item id=\"otherId\">2268</item>\r\n<item id=\"bool\">false</item>"; const string source = "<data>" + items + "</data>"; var xmlObject = new XmlObject(source, null, null); var evaluation = xmlObject.Evaluate("/data"); // Apply CompareOptions.IgnoreSymbols enum here to support asserting on multiple platforms. e.g. New line symbol "\n\r" for Windows, and "\n" for Linux/Mac Assert.AreEqual( 0, string.Compare(items, evaluation, CultureInfo.CurrentCulture, CompareOptions.IgnoreSymbols)); Assert.AreEqual( 0, string.Compare("3349", xmlObject.Evaluate("/data/item[@id='myId']"), CultureInfo.CurrentCulture, CompareOptions.IgnoreSymbols)); Assert.AreEqual( 0, string.Compare("2268", xmlObject.Evaluate("/data/item[@id='otherId']"), CultureInfo.CurrentCulture, CompareOptions.IgnoreSymbols)); Assert.AreEqual("True", xmlObject.Evaluate("5 > 2")); Assert.AreEqual("abc", xmlObject.Evaluate("'abc'")); Assert.AreEqual(null, xmlObject.Evaluate("/data/nonexistingitem")); }