Esempio n. 1
0
        public void ObjectTest()
        {
            MPJson obj = MPJson.Object(
                MPJson.Property("a", 1),
                MPJson.Property("b", 2),
                MPJson.Property("c", 3)
                );

            Assert.Equal(JsonType.Object, obj.Type);
            Assert.True(obj.HasValue);
            Assert.False(obj.IsUndefined);
            Assert.Equal(1.0, obj["a"]);
            Assert.Equal(2.0, obj["b"]);
            Assert.Equal(3.0, obj["c"]);
            Assert.Equal(JsonType.Undefined, obj[0].Type);
            Assert.Equal(JsonType.Undefined, obj["d"].Type);
            Assert.Equal("{ \"a\":1, \"b\":2, \"c\":3 }", obj.ToString());
            Assert.Equal(3, obj.Keys.Count());
        }
Esempio n. 2
0
        public void ArrayTest()
        {
            object[] array = new object[] { 1.0, 2.0, 3.0 };
            MPJson   json1 = MPJson.From(array);
            MPJson   json2 = MPJson.From(array.Clone());
            MPJson   ja    = MPJson.Array(1.0, 2.0, 3.0);

            Assert.Equal(JsonType.Array, json1.Type);
            Assert.Equal(JsonType.Array, json2.Type);
            Assert.Equal(JsonType.Array, ja.Type);
            Assert.True(json1.HasValue);
            Assert.False(json1.IsUndefined);
            Assert.Equal(json1, json2);
            Assert.Equal(json1, ja);
            Assert.Equal(1.0, ja[0]);
            Assert.Equal(2.0, ja[1]);
            Assert.Equal(3.0, ja[2]);
            Assert.Equal(JsonType.Undefined, json1["x"].Type);
            Assert.Equal("[ 1, 2, 3 ]", ja.ToString());
            Assert.Equal(3, ja.Count());
            Assert.Empty(ja.Keys);
        }