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); }
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)); }
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"); }