public void SetAddTestObjectCollectionElement() { var payload = GetTestObject(); payload = JsonPointer.Set(payload, "/Collection/-", "last"); Assert.AreEqual("last", JsonPointer.Get <string>(payload, "/Collection/3")); }
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 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 SetTestObjectSubProperties() { var payload = GetTestObject(); payload = JsonPointer.Set(payload, "/Settings/Launch", false); Assert.AreEqual(false, JsonPointer.Get <bool>(payload, "/Settings/Launch")); }
public void Issue1() { var input = "[{\"Id\":\"b4120a48-d5b0-476f-a653-083f3725dfce\"}]"; var result = JsonPointer.Get <List <Foo> >(input, "/"); Assert.IsNotNull(result); Assert.AreEqual(1, result.Count); }
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")); }
public void Example() { var obj = @"{ foo: 1, bar: { baz: 2}, qux: [3, 4, 5]}"; Assert.AreEqual(1, JsonPointer.Get <int>(obj, "/foo")); Assert.AreEqual(2, JsonPointer.Get <int>(obj, "/bar/baz")); Assert.AreEqual(2, JsonPointer.Get <int>(obj, "/bar/baz")); 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")); }
public void Example2Test() { var sample = @"{ 'books': [ { 'title' : 'The Great Gatsby', 'author' : 'F. Scott Fitzgerald' }, { 'title' : 'The Grapes of Wrath', 'author' : 'John Steinbeck' } ] }"; var result = JsonPointer.Get <string>(sample, "/books/1/author"); // returns "John Steinbeck" Assert.AreEqual("John Steinbeck", result); }
public void PointToTokenWithEmbeddedTilde() { var sample = GetJsonObject(); Assert.AreEqual(8, JsonPointer.Get <int>(sample, "/m~0n")); }
public void PointToTokenWithEscapedSpace() { var sample = GetJsonObject(); Assert.AreEqual(7, JsonPointer.Get <int>(sample, "/%20")); }
public void PointToTokenWithEscapedQuote() { var sample = GetJsonObject(); Assert.AreEqual(6, JsonPointer.Get <int>(sample, "/k%22l")); }
public void PointToTokenWithEscapedBackSlash() { var sample = GetJsonObject(); Assert.AreEqual(5, JsonPointer.Get <int>(sample, "/i%5Cj")); }
public void MissingPropertyThrowsArgumentException() { var obj = @"{ foo: 1, bar: { baz: 2}, qux: [3, 4, 5]}"; JsonPointer.Get <int>(obj, "/quo"); // throws ArgumentException }
public void PointToRoot() { var sample = GetJsonObject(); Assert.IsTrue(JToken.DeepEquals(sample, JsonPointer.Get <JObject>(sample, ""))); }
public void GetStringFromArrayIndexedProperty() { var sample = GetJsonString(); Assert.AreEqual("John Steinbeck", JsonPointer.Get <string>(sample, "/books/1/author")); }
public void PointToTokenWithEncodedPercent() { var sample = GetJsonObject(); Assert.AreEqual(2, JsonPointer.Get <int>(sample, "/c%25d")); }
public void CanHandleTestObjectSubProperties() { var payload = GetTestObject(); Assert.AreEqual(true, JsonPointer.Get <bool>(payload, "/Settings/Launch")); }
public void PointToArrayElementThatDoesNotExistThrowsException() { var sample = GetJsonObject(); JsonPointer.Get <string>(sample, "/foo/10"); }
public void PointToArrayElement() { var sample = GetJsonObject(); Assert.AreEqual(sample["foo"][0], JsonPointer.Get <string>(sample, "/foo/0")); }
public void PointToArray() { var sample = GetJsonObject(); CollectionAssert.AreEqual(sample["foo"].ToObject <List <string> >(), JsonPointer.Get <List <string> >(sample, "/foo")); }
public void PointToTokenTwoLevelsDeep() { var sample = GetJsonObject(); Assert.AreEqual("a3", JsonPointer.Get <string>(sample, "/tee/black")); }
public void PointToTokenWithEncodedCaret() { var sample = GetJsonObject(); Assert.AreEqual(3, JsonPointer.Get <int>(sample, "/e%5Ef")); }
public void PointToTokenThreeLevelsDeep() { var sample = GetJsonObject(); Assert.AreEqual("blue", JsonPointer.Get <string>(sample, "/tee/pink/1")); }
public void PointToTokenWithEscapedPipe() { var sample = GetJsonObject(); Assert.AreEqual(4, JsonPointer.Get <int>(sample, "/g%7Ch")); }
public void PointToElementThatDoesNotExistThrowsException() { var sample = GetJsonObject(); JsonPointer.Get <string>(sample, "/tee/nope"); }
public void CanHandleTestObjectCollections() { var payload = GetTestObject(); Assert.AreEqual("second", JsonPointer.Get <string>(payload, "/Collection/1")); }
public void CanHandleObjectProperties() { var payload = GetPocoObject(); Assert.AreEqual(false, JsonPointer.Get <bool>(payload, "/Enabled")); }
public void PointToTokenWithEmbeddedSlash() { var sample = GetJsonObject(); Assert.AreEqual(1, JsonPointer.Get <int>(sample, "/a~1b")); }