public void RootInFilterWithInitializers() { JObject rootObject = new JObject { { "referenceDate", DateTime.MinValue }, { "dateObjectsArray", new[] { new JObject { { "date", DateTime.MinValue } }, new JObject { { "date", DateTime.MaxValue } }, new JObject { { "date", DateTime.Now } }, new JObject { { "date", DateTime.MinValue } }, } } }; var result = rootObject.SelectTokens("$.dateObjectsArray[?(@.date == $.referenceDate)]").ToList(); Assert.AreEqual(2, result.Count); }
public void EvaluateSinglePropertyReturningArray() { var o = new JObject() { ["Blah"] = new[] { 1, 2, 3 } }; var t = o.SelectTokens("Blah").First(); Assert.IsNotNull(t); Assert.IsInstanceOf <IEnumerable>(t); t = o.SelectTokens("Blah[2]").First(); Assert.IsInstanceOf <int>(t); Assert.AreEqual(3, t); }
public void EvaluateMissingPropertyIndexWithError() { var o = new JObject { ["Blah"] = 1 }; Assert.Throws <Exception>(() => { o.SelectTokens("['Missing','Missing2']", true).First(); }, "Property 'Missing' does not exist on JObject."); }
public void EvaluateSliceOnObjectWithError() { var o = new JObject { ["Blah"] = 1 }; Assert.Throws <Exception>(() => { o.SelectTokens("[:]", true).First(); }, @"Array slice is not valid on JObject."); }
public void EvaluateWildcardIndexOnObjectWithError() { var o = new JObject { ["Blah"] = 1 }; Assert.Throws <Exception>(() => { o.SelectTokens("[*]", true).First(); }, @"Index * not valid on JObject."); }
public void EvaluatePropertyWithoutError() { var o = new JObject() { ["Blah"] = 1 }; Assert.AreEqual(1, o.SelectTokens("Blah", true).First()); }
public void EvaluateIndexerOnObjectWithError() { var o = new JObject() { ["Blah"] = 1 }; Assert.Throws <ArgumentOutOfRangeException>(() => { o.SelectTokens("[1]", true).First(); }, @"Index 1 not valid on JObject."); }
public void EvaluateIndexerOnObject() { var o = new JObject() { ["Blah"] = 1 }; CollectionAssert.IsEmpty(o.SelectTokens("[1]")); }
public void EvaluateMissingProperty() { var o = new JObject() { ["Blah"] = 1 }; CollectionAssert.IsEmpty(o.SelectTokens("Missing[1]")); }
public void QuoteName() { var o = new JObject() { ["Blah"] = 1 }; var t = o.SelectTokens("['Blah']").First(); Assert.IsNotNull(t); Assert.IsInstanceOf <int>(t); Assert.AreEqual(1, t); }
public void EvaluateWildcardProperty() { var o = new JObject() { ["Blah"] = 1, ["Blah2"] = 2 }; var t = o.SelectTokens("$.*").ToList(); Assert.IsNotNull(t); Assert.AreEqual(2, t.Count); Assert.AreEqual(1, t[0]); Assert.AreEqual(2, t[1]); }