public void SetValue()
    {
      object key = 0;

      JConstructor c = new JConstructor();
      c.Name = "con";
      c.Add(null);
      c[key] = new JValue(3);

      Assert.AreEqual(3, (int)c[key]);
    }
 public void CreateWithMultiValue()
 {
   JConstructor constructor = new JConstructor("Test", new List<int> { 1, 2, 3 });
   Assert.AreEqual("Test", constructor.Name);
   Assert.AreEqual(3, constructor.Children().Count());
   Assert.AreEqual(1, (int)constructor.Children().ElementAt(0));
   Assert.AreEqual(2, (int)constructor.Children().ElementAt(1));
   Assert.AreEqual(3, (int)constructor.Children().ElementAt(2));
 }
    public void JConstructorDictionary()
    {
      Dictionary<JToken, int> dic = new Dictionary<JToken, int>(JToken.EqualityComparer);
      JConstructor v11 = new JConstructor("ConstructorValue");
      JConstructor v12 = new JConstructor("ConstructorValue");

      dic[v11] = 1;
      dic[v12] += 1;
      Assert.AreEqual(2, dic[v11]);
    }
    public void Iterate()
    {
      JConstructor c = new JConstructor("MrConstructor", 1, 2, 3, 4, 5);

      int i = 1;
      foreach (JToken token in c)
      {
        Assert.AreEqual(i, (int)token);
        i++;
      }
    }
Esempio n. 5
0
    public void EvaluateIndexerOnConstructorWithError()
    {
      JConstructor c = new JConstructor("Blah");

      c.SelectToken("[1]", true);
    }
Esempio n. 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JConstructor"/> class from another <see cref="JConstructor"/> object.
 /// </summary>
 /// <param name="other">A <see cref="JConstructor"/> object to copy from.</param>
 public JConstructor(JConstructor other)
   : base(other)
 {
   _name = other.Name;
 }
Esempio n. 7
0
    /// <summary>
    /// Loads an <see cref="JConstructor"/> from a <see cref="JsonReader"/>. 
    /// </summary>
    /// <param name="reader">A <see cref="JsonReader"/> that will be read for the content of the <see cref="JConstructor"/>.</param>
    /// <returns>A <see cref="JConstructor"/> that contains the JSON that was read from the specified <see cref="JsonReader"/>.</returns>
    public static new JConstructor Load(JsonReader reader)
    {
      if (reader.TokenType == JsonToken.None)
      {
        if (!reader.Read())
          throw new Exception("Error reading JConstructor from JsonReader.");
      }

      if (reader.TokenType != JsonToken.StartConstructor)
        throw new Exception("Error reading JConstructor from JsonReader. Current JsonReader item is not a constructor: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));

      JConstructor c = new JConstructor((string)reader.Value);
      c.SetLineInfo(reader as IJsonLineInfo);

      c.ReadTokenFrom(reader);

      return c;
    }
 public void SetValueWithInvalidIndex()
 {
   JConstructor c = new JConstructor();
   c["badvalue"] = new JValue(3);
 }
 public void JConstructorStringIndex()
 {
   JConstructor c = new JConstructor("ConstructorValue");
   Assert.AreEqual(null, c["purple"]);
 }