Exemple #1
0
        public void ContentHandlerAddToTest()
        {
            var h         = new ContentHandler();
            var baseObj   = h.ObjectFrom("<a><b>test</b><c/></a>");
            var insertObj = h.ObjectFrom("<d>test2</d>");

            Assert.IsTrue(ContentHandler.AddToAt(insertObj, baseObj, "/a/c"));
            Assert.AreEqual("<a><b>test</b><c><d>test2</d></c></a>", baseObj.Serialize());
        }
Exemple #2
0
        public void ContentHandlerObjectFromInTest()
        {
            var h       = new ContentHandler();
            var baseObj = h.ObjectFrom("<a><b>test</b></a>");
            // use the deprecated one at least once to ensure it works
            var subObj = h.CreateObjectFromPropertyOf("/a", baseObj);

            Assert.AreEqual("<b>test</b>", subObj.Serialize());
            subObj = h.ObjectFromPropertyOf("/q", baseObj);
            Assert.IsTrue(string.IsNullOrEmpty(subObj.Serialize()));
            var jsonObj    = h.ObjectFrom("{ \"a\": { \"b\":\"test\" }}");
            var subJsonObj = h.ObjectFromPropertyOf("a", jsonObj);

            Assert.AreEqual("{\"b\":\"test\"}", subJsonObj.Serialize());
        }
Exemple #3
0
        public void ContentHandlerJsonObjectNullTest()
        {
            var h   = new ContentHandler();
            var obj = h.ObjectFrom("{\"a\":null}");

            Assert.AreEqual("JSON Object", obj.ToString());
            Assert.IsNull(obj.GetProperty("a"));
        }
Exemple #4
0
        public void ContentHandlerPropertyValueOfTest()
        {
            var h       = new ContentHandler();
            var baseObj = h.ObjectFrom("<a><b>test</b><c/></a>");
            var value   = ContentHandler.PropertyValueOf("/a/b", baseObj);

            Assert.AreEqual("test", value);
        }
Exemple #5
0
        public void ContentHandlerEvaluateTest()
        {
            var h       = new ContentHandler();
            var baseObj = h.ObjectFrom("<a><b/><b class='q'>test</b></a>");
            var value   = ContentHandler.EvaluateOn("/a/b[@class='q']", baseObj);

            Assert.AreEqual("test", value);
        }
Exemple #6
0
        public void ContentHandlerDeleteFromObject()
        {
            var h       = new ContentHandler();
            var baseObj = h.ObjectFrom("<a><b>test</b><c/></a>");

            ContentHandler.DeleteFrom("/a/b", baseObj);
            Assert.AreEqual("<a><c /></a>", ContentHandler.Serialize(baseObj));
        }
Exemple #7
0
        public void ContentHandlerPropertiesOfTest()
        {
            var h       = new ContentHandler();
            var baseObj = h.ObjectFrom("<a><b>test</b><c/></a>");
            var props   = ContentHandler.PropertiesOf("/a/*", baseObj).ToArray();

            Assert.AreEqual(props[0], "/a[1]/b[1]");
            Assert.AreEqual(props[1], "/a[1]/c[1]");
        }
Exemple #8
0
        public void ContentHandlerJsonObjectTest()
        {
            var h   = new ContentHandler();
            var obj = h.ObjectFrom("{ \"a\" : \"test\" }");

            Assert.AreEqual("JSON Object", obj.ToString());
            Assert.AreEqual("test", obj.GetProperty("a"));
            ContentHandler.SetPropertyValueOfTo("a", obj, "replaced");
            Assert.AreEqual("replaced", ContentHandler.PropertyValueOf("a", obj));
        }
Exemple #9
0
        public void ContentHandlerXmlObjectTest()
        {
            var h   = new ContentHandler();
            var obj = h.ObjectFrom("<a>test</a>");

            Assert.AreEqual("XML Object", obj.ToString());
            Assert.AreEqual("<a>test</a>", obj.Serialize());
            Assert.AreEqual("test", obj.GetProperty("/a"));
            ContentHandler.SetPropertyValueOfTo("/a", obj, "replaced");
            Assert.AreEqual("<a>replaced</a>", obj.Serialize());
        }
Exemple #10
0
        public void ContentHandlerPropertySetOfContainsTest()
        {
            var h       = new ContentHandler();
            var baseObj = h.ObjectFrom("<a><b>test</b><b/></a>");

            Assert.IsTrue(ContentHandler.PropertySetOfContainsValueLike("", baseObj, "test"));
            Assert.IsFalse(ContentHandler.PropertySetOfContainsValueLike("", baseObj, "q"));
            Assert.IsTrue(ContentHandler.PropertySetOfContainsValueLike("/a", baseObj, "test"));
            Assert.IsTrue(ContentHandler.PropertySetOfContainsValueLike("/a/b", baseObj, "test"));
            Assert.IsFalse(ContentHandler.PropertySetOfContainsValueLike("/a/c", baseObj, "test"));
            Assert.IsTrue(ContentHandler.PropertySetOfContainsValueLike("", baseObj, ""));
            Assert.IsFalse(ContentHandler.PropertySetOfContainsValueLike("/b", baseObj, ""));
        }