示例#1
0
        public void V_Path_Test()
        {
            var b = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
            var j = WFJson.Parse(b);

            Assert.AreEqual <int>(j.V <int>("b[1].b1"), 3);
        }
示例#2
0
        public void Constructor_New_Test()
        {
            WFJson j = null;

            j = new WFJson();
            Assert.AreEqual(j.ToString(), "{}", "create a empty JsonObject fail");
        }
示例#3
0
        public void Add_String_Test()
        {
            var j = WFJson.Parse("[]");

            j.Add("a");
            Assert.AreEqual(j.ToString(), "[\"a\"]");
        }
示例#4
0
        public void Add_Object_Test()
        {
            var j = WFJson.Parse("[]");

            j.Add(obj);
            Assert.AreEqual(j.ToString(), "[" + new WFJson(obj) + "]");
        }
示例#5
0
        public void Add_Bool_Test()
        {
            var j = WFJson.Parse("[]");

            j.Add(true);
            Assert.AreEqual(j.ToString(), "[true]");
        }
示例#6
0
        public void Constructor_JObject_Test()
        {
            var jobj = new JObject(new JProperty("a", 1));
            var j    = new WFJson(jobj);

            Assert.AreEqual(j.ToString(), "{\"a\":1}", "create a JosnObject with JObject fail");
        }
示例#7
0
        public void Add_Int_Test()
        {
            var j = WFJson.Parse("[]");

            j.Add(1);
            Assert.AreEqual(j.ToString(), "[1]");
        }
示例#8
0
        public void Constructor_JArray_Test()
        {
            var jArr = new JArray(1, 2);
            var j    = new WFJson(jArr);

            Assert.AreEqual(j.ToString(), "[1,2]");
        }
示例#9
0
        public void Indexer_String_Get_Test()
        {
            var b = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
            var j = WFJson.Parse(b);

            Assert.AreEqual <int>(j["a"].V <int>(), 123);
        }
示例#10
0
        public void Constructor_String_Test()
        {
            string str = "123";
            var    j   = new WFJson(str);

            Assert.AreEqual(j.V <string>(), str);
        }
示例#11
0
        public void Contains_Int_Test()
        {
            var j = WFJson.Parse("[1,2,3]");

            Assert.IsTrue(j.Contains(1));
            Assert.IsFalse(j.Contains(5));
        }
示例#12
0
        public void Parse_Test()
        {
            var b = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
            var j = WFJson.Parse(b);

            Assert.IsInstanceOfType(j, typeof(WFJson));
        }
示例#13
0
        public void Add_DateTime_Test()
        {
            var      j  = WFJson.Parse("[]");
            DateTime dt = DateTime.Now;

            j.Add(dt);
            Assert.AreEqual(j[0].V <DateTime>(), dt);
        }
示例#14
0
        public void StandardTest()
        {
            var rtv = InvokeWF("standard", new { a = 2, b = 3 });
            var j   = WFJson.Parse(rtv);

            //c=(a+b)*100
            Assert.AreEqual(j.V <int>("c"), 500);
        }
示例#15
0
        public void IndexOf_Int_Test()
        {
            var j = WFJson.Parse("[]");

            Assert.AreEqual(j.IndexOf(1), -1);
            j.Add(1);
            Assert.AreEqual(j.IndexOf(1), 0);
        }
示例#16
0
        public void Add_WFJson_Test()
        {
            var j = WFJson.Parse("[]");
            var a = new WFJson("sd");

            j.Add(a);
            Assert.AreEqual(j[0].ToString(), a.ToString());
        }
示例#17
0
        public void IndexOf_WFJson_Test()
        {
            var j = WFJson.Parse("[]");
            var a = new WFJson(1);

            Assert.AreEqual <int>(j.IndexOf(a), -1);
            j.Add(a);
            Assert.AreEqual <int>(j.IndexOf(a), 0);
        }
示例#18
0
        public void Contains_WFJson_Test()
        {
            var j = WFJson.Parse("[]");
            var a = new WFJson(1);

            Assert.IsFalse(j.Contains(a));
            j.Add(a);
            Assert.IsTrue(j.Contains(a));
        }
示例#19
0
        public void Constructor_Class_Test()
        {
            MyClass my = new MyClass()
            {
                Name = "Name", Age = 23
            };
            var j   = new WFJson(my);
            var rtv = j.V <MyClass>();

            Assert.IsInstanceOfType(rtv, typeof(MyClass));
            Assert.AreEqual(rtv.Name, my.Name);
            Assert.AreEqual(rtv.Age, my.Age);
        }
示例#20
0
        public void Indexer_Int_Set_Test()
        {
            var j = new WFJson
            {
                ["a.b[0].c"] = 2
            };

            Assert.IsNotNull(j[0]);          //a
            Assert.IsNotNull(j[0][0]);       //a.b
            Assert.IsNotNull(j[0][0][0]);    //a.b[0]
            Assert.IsNotNull(j[0][0][0][0]); //a.b[0].c
            Assert.AreEqual(j[0][0][0][0].V <int>(), 2);
        }
示例#21
0
        public void Indexer_String_Set_Test()
        {
            var j = new WFJson
            {
                ["a.b[0].c"] = "a"
            };

            Assert.IsNotNull(j["a"]);
            Assert.IsNotNull(j["a.b"]);
            Assert.IsNotNull(j["a.b[0]"]);
            Assert.IsNotNull(j["a.b[0].c"]);
            Assert.AreEqual(j["a.b[0].c"].V <string>(), "a");
        }
示例#22
0
        public void GetEnumeratorTest()
        {
            var j = new WFJson(obj);

            foreach (var item in j)
            {
                Assert.IsNotNull(item);
            }
            foreach (var item in j["b"])
            {
                Assert.IsNotNull(item);
            }
        }
示例#23
0
        public void Indexer_String_Get_Object_Test()
        {
            MyClass my = new MyClass()
            {
                Name = "Name", Age = 23
            };
            var j = WFJson.Parse("{a:null}");

            j["a"] = new WFJson(my);
            var rtv = j["a"].V <MyClass>();

            Assert.IsInstanceOfType(rtv, typeof(MyClass));
            Assert.AreEqual(rtv.Name, my.Name);
            Assert.AreEqual(rtv.Age, my.Age);
        }