예제 #1
0
        public void TestReturnElement()
        {
            //Arrange
            IXPathProcessor processor = XPathProcessorFactory.Get(XPathEngine.xpath1);

            //Act
            var result = processor.Process(DataProvider.GetInventorySample(), "//book[@id='myfave']/author");

            //Assert
            Assert.IsNotNull(result);
        }
예제 #2
0
        public void TestReturnString()
        {
            //Arrange
            IXPathProcessor processor = XPathProcessorFactory.Get(XPathEngine.xpath1);
            var             query     = "concat(//book[1]/author/first-name, ' ', //book[1]/author/last-name)";

            //Act
            var result = processor.Process(DataProvider.GetInventorySample(), query);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("Joe Bob", result);
        }
예제 #3
0
        public void TestReturnBoolean()
        {
            //Arrange
            IXPathProcessor processor = XPathProcessorFactory.Get(XPathEngine.xpath1);
            var             query     = "//book[1]/price > 10";

            //Act
            var result = processor.Process(DataProvider.GetInventorySample(), query);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("True", result);
        }
예제 #4
0
        public JsonResult ExecuteXPath(XPathDemo demo)
        {
            string          result = "", error = "";
            IXPathProcessor processor = XPathProcessorFactory.Get(demo.Engine);

            try
            {
                result = processor.Process(demo.Xml, demo.XPath);
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(Json(new { data = result, error }));
        }
예제 #5
0
        public void TestReturnMixed()
        {
            //Arrange
            IXPathProcessor processor = XPathProcessorFactory.Get(XPathEngine.xpath1);

            /*
             * Test mixed of element, attribute & text node
             */
            var query = "//book[@id='myfave']/author/first-name";

            query += " | //book[@id='myfave']/@id";
            query += " | //book[@id='myfave']/author/last-name/text()";

            //Act
            var result = processor.Process(DataProvider.GetInventorySample(), query);

            //Assert
            Assert.IsNotNull(result);
        }