public void SetTestObjectSubProperties() { var payload = GetTestObject(); payload = JsonPointer.Set(payload, "/Settings/Launch", false); Assert.AreEqual(false, JsonPointer.Get <bool>(payload, "/Settings/Launch")); }
public void SetAddTestObjectCollectionElement() { var payload = GetTestObject(); payload = JsonPointer.Set(payload, "/Collection/-", "last"); Assert.AreEqual("last", JsonPointer.Get <string>(payload, "/Collection/3")); }
public void CannotSetRealObjectSubPropertiesThatDoNotExist() { var payload = GetTestObject(); payload = JsonPointer.Set(payload, "/Settings/Wait", false); Assert.AreEqual(false, JsonPointer.Get <bool>(payload, "/Settings/Wait")); }
public void SetObjectSubPropertiesDoesNotExist() { var payload = GetPocoObject(); payload = JsonPointer.Set(payload, "/Settings/Wait", false); Assert.AreEqual(false, JsonPointer.Get <bool>(payload, "/Settings/Wait")); }
public void ExampleCollectionTest() { var sample = @"{ 'books': [ { 'title' : 'The Great Gatsby', 'author' : 'F. Scott Fitzgerald' }, { 'title' : 'The Grapes of Wrath', 'author' : 'John Steinbeck' } ] }"; var result = JsonPointer.Get <List <Book> >(sample, "/books"); Assert.IsTrue(result.Count == 2); sample = JsonPointer.Set(sample, "/books/-", new Book { Title = "Jayne Eyre", Author = "Charlotte Brontë" }); result = JsonPointer.Get <List <Book> >(sample, "/books"); Assert.IsTrue(result.Count == 3); }
public void ReplacePropertyUsingSet() { var obj = @"{ foo: 1, bar: { baz: 2}, qux: [3, 4, 5]}"; obj = JsonPointer.Set(obj, "/foo", 6); // sets obj.foo = 6; Assert.AreEqual(6, JsonPointer.Get <int>(obj, "/foo")); }
public void AddItemToCollectionUsingSet() { var obj = @"{ foo: 1, bar: { baz: 2}, qux: [3, 4, 5]}"; obj = JsonPointer.Set(obj, "/qux/-", 6); // sets obj.qux = [3, 4, 5, 6] Assert.AreEqual(3, JsonPointer.Get <int>(obj, "/qux/0")); Assert.AreEqual(4, JsonPointer.Get <int>(obj, "/qux/1")); Assert.AreEqual(5, JsonPointer.Get <int>(obj, "/qux/2")); Assert.AreEqual(6, JsonPointer.Get <int>(obj, "/qux/3")); }