public void SetValueWithInvalidIndex()
 {
     AssertException.Throws<ArgumentException>(() =>
     {
         JConstructor c = new JConstructor();
         c["badvalue"] = new JValue(3);
     }, @"Set JConstructor values with invalid key value: ""badvalue"". Argument position index expected.");
 }
 public void CreateWithMultiValue()
 {
     JConstructor constructor = new JConstructor("Test", new List<int> { 1, 2, 3 });
     Assert.Equal("Test", constructor.Name);
     Assert.Equal(3, constructor.Children().Count());
     Assert.Equal(1, (int)constructor.Children().ElementAt(0));
     Assert.Equal(2, (int)constructor.Children().ElementAt(1));
     Assert.Equal(3, (int)constructor.Children().ElementAt(2));
 }
        public void SetValue()
        {
            object key = 0;

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

            Assert.Equal(3, (int)c[key]);
        }
        public void Iterate()
        {
            JConstructor c = new JConstructor("MrConstructor", 1, 2, 3, 4, 5);

            int i = 1;
            foreach (JToken token in c)
            {
                Assert.Equal(i, (int)token);
                i++;
            }
        }
예제 #5
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;
 }
예제 #6
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 new static JConstructor Load(JsonReader reader)
        {
            if (reader.TokenType == JsonToken.None)
            {
                if (!reader.Read())
                    throw JsonReaderException.Create(reader, "Error reading JConstructor from JsonReader.");
            }

            while (reader.TokenType == JsonToken.Comment)
            {
                reader.Read();
            }

            if (reader.TokenType != JsonToken.StartConstructor)
                throw JsonReaderException.Create(reader, "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 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.Equal(2, dic[v11]);
        }
예제 #8
0
 public void JConstructorStringIndex()
 {
     AssertException.Throws<ArgumentException>(() =>
     {
         JConstructor c = new JConstructor("ConstructorValue");
         Assert.Equal(null, c["purple"]);
     }, @"Accessed JConstructor values with invalid key value: ""purple"". Argument position index expected.");
 }
        public void EvaluateConstructorOutOfBoundsIndxer()
        {
            JConstructor c = new JConstructor("Blah");

            Assert.Null(c.SelectToken("[1]"));
        }
예제 #10
0
        public void EvaluateConstructorOutOfBoundsIndxerWithError()
        {
            JConstructor c = new JConstructor("Blah");

            AssertException.Throws<JsonException>(() => { c.SelectToken("[1]", true); }, @"Index 1 outside the bounds of JConstructor.");
        }
예제 #11
0
        public void MergeNull()
        {
            JConstructor c = new JConstructor();
            c.Merge(null);
            Assert.Equal(null, c.Name);
            Assert.Equal(0, c.Count);

            JObject o = new JObject();
            o.Merge(null);
            Assert.Equal(0, o.Count);

            JArray a = new JArray();
            a.Merge(null);
            Assert.Equal(0, a.Count);

            JProperty p = new JProperty("name1");
            p.Merge(null);
            Assert.Equal("name1", p.Name);
            Assert.Equal(0, p.Count);
        }
예제 #12
0
        public void MergeJConstructor()
        {
            JConstructor c1 = new JConstructor("c1", new[] { 1, 2 });
            JConstructor c2 = new JConstructor("c2", new[] { 3, 4 });

            c1.Merge(c2);
            Assert.Equal("c2", c1.Name);
            Assert.Equal(new[] { 1, 2, 3, 4 }, c1.Select(i => (int)i));

            JConstructor c3 = new JConstructor();
            c1.Merge(c3);
            Assert.Equal("c2", c1.Name);

            JConstructor c4 = new JConstructor("c4", new[] { 5, 6 });
            c1.Merge(c4, new JsonMergeSettings
            {
                MergeArrayHandling = MergeArrayHandling.Replace
            });
            Assert.Equal("c4", c1.Name);
            Assert.Equal(new[] { 5, 6 }, c1.Select(i => (int)i));
        }