Пример #1
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));
        }
Пример #2
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());
        }
Пример #3
0
        public void ContentHandlerLoadObjectFromSaveObjectToTest()
        {
            const string jsonTest = "{ \"Id\": 0, \"Name\": \"Joe\", \"IsShared\": true }";
            var          file     = Path.GetTempFileName();

            File.WriteAllText(file, jsonTest);
            var h       = new ContentHandler();
            var baseObj = h.LoadObjectFrom(file);

            Assert.AreEqual("0", ContentHandler.PropertyValueOf("Id", baseObj), "Id matches");
            Assert.AreEqual("Joe", ContentHandler.PropertyValueOf("Name", baseObj), "Name matches");
            Assert.AreEqual("True", ContentHandler.PropertyValueOf("IsShared", baseObj), "IsShared matches");
            Assert.IsTrue(ContentHandler.SetPropertyValueOfTo("Name", baseObj, "Jane"), "Change name");
            var fileOut = ContentHandler.SaveObjectTo(baseObj, "");
            var h2      = new ContentHandler();

            _ = h2.LoadObjectFrom(fileOut);
            Assert.AreEqual("0", ContentHandler.PropertyValueOf("Id", baseObj), "Unchanged Id matches");
            Assert.AreEqual("Jane", ContentHandler.PropertyValueOf("Name", baseObj), "Changed name matches");
            Assert.AreEqual("True", ContentHandler.PropertyValueOf("IsShared", baseObj), "Unchanged IsShared matches");
        }