public void IListRemove() { JProperty p = new JProperty("TestProperty", null); IList l = p; l.Remove(p.Value); }
public void IListAdd() { JProperty p = new JProperty("TestProperty", null); IList l = p; l.Add(null); }
public void IListClear() { JProperty p = new JProperty("TestProperty", null); IList l = p; l.Clear(); }
public void IListCount() { JProperty p = new JProperty("TestProperty", null); IList l = p; Assert.AreEqual(1, l.Count); }
public void NullValue() { JProperty p = new JProperty("TestProperty", null); Assert.IsNotNull(p.Value); Assert.AreEqual(JTokenType.Null, p.Value.Type); Assert.AreEqual(p, p.Value.Parent); p.Value = null; Assert.IsNotNull(p.Value); Assert.AreEqual(JTokenType.Null, p.Value.Type); Assert.AreEqual(p, p.Value.Parent); }
public void ListChanged() { JProperty p = new JProperty("TestProperty", null); IBindingList l = p; ListChangedType? listChangedType = null; int? index = null; l.ListChanged += (sender, args) => { listChangedType = args.ListChangedType; index = args.NewIndex; }; p.Value = 1; Assert.AreEqual(ListChangedType.ItemChanged, listChangedType.Value); Assert.AreEqual(0, index.Value); }
/// <summary> /// Initializes a new instance of the <see cref="JProperty"/> class from another <see cref="JProperty"/> object. /// </summary> /// <param name="other">A <see cref="JProperty"/> object to copy from.</param> public JProperty(JProperty other) : base(other) { _name = other.Name; }
public void GenericListJTokenAddBadToken() { JProperty p1 = new JProperty("Test1", 1); JProperty p2 = new JProperty("Test2", "Two"); IList<JToken> l = new JObject(p1, p2); l.Add(new JValue("Bad!")); }
public void GenericListJTokenCopyTo() { JProperty p1 = new JProperty("Test1", 1); JProperty p2 = new JProperty("Test2", "Two"); IList<JToken> l = new JObject(p1, p2); JToken[] a = new JToken[l.Count]; l.CopyTo(a, 0); Assert.AreEqual(p1, a[0]); Assert.AreEqual(p2, a[1]); }
public void GenericListJTokenIndexOf() { JProperty p = new JProperty("Test", 1); IList<JToken> l = new JObject(p); Assert.AreEqual(0, l.IndexOf(p)); Assert.AreEqual(-1, l.IndexOf(new JProperty("Test", 1))); }
public void IListIsSynchronized() { JProperty p1 = new JProperty("Test1", 1); JProperty p2 = new JProperty("Test2", "Two"); IList l = new JObject(p1, p2); Assert.IsFalse(l.IsSynchronized); }
public void IListSetItemInvalid() { JProperty p1 = new JProperty("Test1", 1); JProperty p2 = new JProperty("Test2", "Two"); IList l = new JObject(p1, p2); l[0] = new JValue(true); }
public void IListIndexOf() { JProperty p = new JProperty("Test", 1); IList l = new JObject(p); Assert.AreEqual(0, l.IndexOf(p)); Assert.AreEqual(-1, l.IndexOf(new JProperty("Test", 1))); }
public void IListContains() { JProperty p = new JProperty("Test", 1); IList l = new JObject(p); Assert.IsTrue(l.Contains(p)); Assert.IsFalse(l.Contains(new JProperty("Test", 1))); }
public void ReplaceJPropertyWithJPropertyWithSameName() { JProperty p1 = new JProperty("Test1", 1); JProperty p2 = new JProperty("Test2", "Two"); JObject o = new JObject(p1, p2); IList l = o; Assert.AreEqual(p1, l[0]); Assert.AreEqual(p2, l[1]); JProperty p3 = new JProperty("Test1", "III"); p1.Replace(p3); Assert.AreEqual(null, p1.Parent); Assert.AreEqual(l, p3.Parent); Assert.AreEqual(p3, l[0]); Assert.AreEqual(p2, l[1]); Assert.AreEqual(2, l.Count); Assert.AreEqual(2, o.Properties().Count()); JProperty p4 = new JProperty("Test4", "IV"); p2.Replace(p4); Assert.AreEqual(null, p2.Parent); Assert.AreEqual(l, p4.Parent); Assert.AreEqual(p3, l[0]); Assert.AreEqual(p4, l[1]); }
public void IListSetItem() { JProperty p1 = new JProperty("Test1", 1); JProperty p2 = new JProperty("Test2", "Two"); IList l = new JObject(p1, p2); JProperty p3 = new JProperty("Test3", "III"); l[0] = p3; Assert.AreEqual(p3, l[0]); Assert.AreEqual(p2, l[1]); }
public void IListSetItemAlreadyExists() { JProperty p1 = new JProperty("Test1", 1); JProperty p2 = new JProperty("Test2", "Two"); IList l = new JObject(p1, p2); JProperty p3 = new JProperty("Test3", "III"); l[0] = p3; l[1] = p3; }
public void IListClear() { JProperty p = new JProperty("Test", 1); IList l = new JObject(p); Assert.AreEqual(1, l.Count); l.Clear(); Assert.AreEqual(0, l.Count); }
public void IListSyncRoot() { JProperty p1 = new JProperty("Test1", 1); JProperty p2 = new JProperty("Test2", "Two"); IList l = new JObject(p1, p2); Assert.IsNotNull(l.SyncRoot); }
public void IListCopyTo() { JProperty p1 = new JProperty("Test1", 1); JProperty p2 = new JProperty("Test2", "Two"); IList l = new JObject(p1, p2); object[] a = new object[l.Count]; l.CopyTo(a, 0); Assert.AreEqual(p1, a[0]); Assert.AreEqual(p2, a[1]); }
public void GenericListJTokenContains() { JProperty p = new JProperty("Test", 1); IList<JToken> l = new JObject(p); Assert.IsTrue(l.Contains(p)); Assert.IsFalse(l.Contains(new JProperty("Test", 1))); }
public void IListAddBadValue() { JProperty p1 = new JProperty("Test1", 1); JProperty p2 = new JProperty("Test2", "Two"); IList l = new JObject(p1, p2); l.Add("Bad!"); }
public void GenericListJTokenClear() { JProperty p = new JProperty("Test", 1); IList<JToken> l = new JObject(p); Assert.AreEqual(1, l.Count); l.Clear(); Assert.AreEqual(0, l.Count); }
public void IListAddPropertyWithExistingName() { JProperty p1 = new JProperty("Test1", 1); JProperty p2 = new JProperty("Test2", "Two"); IList l = new JObject(p1, p2); JProperty p3 = new JProperty("Test2", "II"); l.Add(p3); }
public void GenericListJTokenAdd() { JProperty p1 = new JProperty("Test1", 1); JProperty p2 = new JProperty("Test2", "Two"); IList<JToken> l = new JObject(p1, p2); JProperty p3 = new JProperty("Test3", "III"); l.Add(p3); Assert.AreEqual(3, l.Count); Assert.AreEqual(p3, l[2]); }
public void IListRemove() { JProperty p1 = new JProperty("Test1", 1); JProperty p2 = new JProperty("Test2", "Two"); IList l = new JObject(p1, p2); JProperty p3 = new JProperty("Test3", "III"); // won't do anything l.Remove(p3); Assert.AreEqual(2, l.Count); l.Remove(p1); Assert.AreEqual(1, l.Count); Assert.IsFalse(l.Contains(p1)); Assert.IsTrue(l.Contains(p2)); l.Remove(p2); Assert.AreEqual(0, l.Count); Assert.IsFalse(l.Contains(p2)); Assert.AreEqual(null, p2.Parent); }
/// <summary> /// Loads an <see cref="JProperty"/> from a <see cref="JsonReader"/>. /// </summary> /// <param name="reader">A <see cref="JsonReader"/> that will be read for the content of the <see cref="JProperty"/>.</param> /// <returns>A <see cref="JProperty"/> that contains the JSON that was read from the specified <see cref="JsonReader"/>.</returns> public static new JProperty Load(JsonReader reader) { if (reader.TokenType == JsonToken.None) { if (!reader.Read()) throw new Exception("Error reading JProperty from JsonReader."); } if (reader.TokenType != JsonToken.PropertyName) throw new Exception( "Error reading JProperty from JsonReader. Current JsonReader item is not a property: {0}".FormatWith( CultureInfo.InvariantCulture, reader.TokenType)); JProperty p = new JProperty((string)reader.Value); p.SetLineInfo(reader as IJsonLineInfo); p.ReadTokenFrom(reader); return p; }
public void IListRemoveAt() { JProperty p1 = new JProperty("Test1", 1); JProperty p2 = new JProperty("Test2", "Two"); IList l = new JObject(p1, p2); // won't do anything l.RemoveAt(0); l.Remove(p1); Assert.AreEqual(1, l.Count); l.Remove(p2); Assert.AreEqual(0, l.Count); }
public void Parent() { JArray v = new JArray(new JConstructor("TestConstructor"), new JValue(new DateTime(2000, 12, 20))); Assert.AreEqual(null, v.Parent); JObject o = new JObject( new JProperty("Test1", v), new JProperty("Test2", "Test2Value"), new JProperty("Test3", "Test3Value"), new JProperty("Test4", null) ); Assert.AreEqual(o.Property("Test1"), v.Parent); JProperty p = new JProperty("NewProperty", v); // existing value should still have same parent Assert.AreEqual(o.Property("Test1"), v.Parent); // new value should be cloned Assert.AreNotSame(p.Value, v); Assert.AreEqual((DateTime)((JValue)p.Value[1]).Value, (DateTime)((JValue)v[1]).Value); Assert.AreEqual(v, o["Test1"]); Assert.AreEqual(null, o.Parent); JProperty o1 = new JProperty("O1", o); Assert.AreEqual(o, o1.Value); Assert.AreNotEqual(null, o.Parent); JProperty o2 = new JProperty("O2", o); Assert.AreNotSame(o1.Value, o2.Value); Assert.AreEqual(o1.Value.Children().Count(), o2.Value.Children().Count()); Assert.AreEqual(false, JToken.DeepEquals(o1, o2)); Assert.AreEqual(true, JToken.DeepEquals(o1.Value, o2.Value)); }
public void IListInsert() { JProperty p1 = new JProperty("Test1", 1); JProperty p2 = new JProperty("Test2", "Two"); IList l = new JObject(p1, p2); JProperty p3 = new JProperty("Test3", "III"); l.Insert(1, p3); Assert.AreEqual(l, p3.Parent); Assert.AreEqual(p1, l[0]); Assert.AreEqual(p3, l[1]); Assert.AreEqual(p2, l[2]); }