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); 
    }
示例#7
0
 /// <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]);
    }
示例#10
0
    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)));
    }
示例#11
0
    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);
    }
示例#12
0
    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);
    }
示例#13
0
    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)));
    }
示例#14
0
    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)));
    }
示例#15
0
    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]);
    }
示例#16
0
    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]);
    }
示例#17
0
    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;
    }
示例#18
0
    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);
    }
示例#19
0
    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);
    }
示例#20
0
    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]);
    }
示例#21
0
    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)));
    }
示例#22
0
    public void IListAddBadValue()
    {
      JProperty p1 = new JProperty("Test1", 1);
      JProperty p2 = new JProperty("Test2", "Two");
      IList l = new JObject(p1, p2);

      l.Add("Bad!");
    }
示例#23
0
    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);
    }
示例#24
0
    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);
    }
示例#25
0
    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]);
    }
示例#26
0
    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);
    }
示例#27
0
    /// <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;
    }
示例#28
0
    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);
    }
示例#29
0
    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));
    }
示例#30
0
    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]);
    }