Esempio n. 1
0
        public static void TestUseCase()
        {
            var list = new List <int> {
                7
            };
            var z = Bridge.JSON.Serialize(list); // this is ok

            Assert.AreEqual("[7]", z, "List<int>");

            var b = new Bridge501B()
            {
                1, 2
            };
            var y = Bridge.JSON.Serialize(b); // wrong, missing items

            Assert.AreEqual("[1,2]", y, "Bridge501B");

            var a = new Bridge501A()
            {
                7
            };                              // sine items is defined as member, push fails
            var x = Bridge.JSON.Serialize(a);

            Assert.AreEqual("[7]", x, "Bridge501A");

            var c = JSON.Deserialize <Bridge501A>(x);

            Assert.AreEqual("12", c.Items, "Bridge501A Parse c.Items");
            Assert.AreEqual(7, c[0], "Bridge501A Parse c[0]");
        }
Esempio n. 2
0
        public static void TestJsonArrayParse()
        {
            var o = JSON.Deserialize <int[]>("[1]");

            Assert.True(o != null);
            Assert.AreEqual(1, o.Length);
            Assert.AreEqual(1, o[0]);
        }
Esempio n. 3
0
        public static void TestRelated()
        {
            var i = Bridge.JSON.Deserialize <int>("25");

            Assert.AreEqual(25, i, "Bridge544 int");

            var dbl = Bridge.JSON.Deserialize <double>("26.1");

            Assert.AreEqual(26.1d, dbl, "Bridge544 double");

            var d = Bridge.JSON.Deserialize <decimal>("27.2");

            DecimalHelper.AssertIsDecimalAndEqualTo(d, 27.2, "Bridge544 decimal");

            var s = JSON.Deserialize <string>("\"Some string\"");

            Assert.AreEqual("Some string", s, "Bridge544 string");
        }
Esempio n. 4
0
        public static void TestJSONParseAsArray()
        {
            var serialized = Bridge.JSON.Serialize(new[] { new Foo()
                                                           {
                                                               Value = 101
                                                           } });

            Assert.NotNull(serialized, " serialized should not be null");

            var result = JSON.Deserialize <Foo[]>(serialized);

            Assert.NotNull(result, " result should not be null");
            Assert.AreEqual("Bridge.ClientTest.Batch3.BridgeIssues.Bridge1438+Foo[]", result.GetType().FullName, "Check result type name");
            Assert.AreEqual(1, result.Length, "Check result length");
            Assert.NotNull(result[0], " result[0] should not be null");
            Assert.AreEqual("Bridge.ClientTest.Batch3.BridgeIssues.Bridge1438+Foo", result[0].GetType().FullName, "Check result[0] type name");
            Assert.AreEqual(101, result[0].Value, "result[0].Value = 101");
        }