Esempio n. 1
0
        public void TestString()
        {
            var t1 = new TypedValues <string>()
            {
                IgnoredValue = "100", DirectValue = "200", PropertyValue = "300"
            };

            var wr = new JsonWriter(indented: false);

            new JsonSerializer().Serialize(t1, wr);
            string json = wr.ToString();

            Assert.AreEqual(@"{""a"":""200"",""b"":""300""}", json);

            var t2 = new JsonDeserializer().Deserialize <TypedValues <string> >(json);

            Assert.AreEqual(null, t2.IgnoredValue);
            Assert.AreEqual("200", t2.DirectValue);
            Assert.AreEqual("300", t2.PropertyValue);
        }
Esempio n. 2
0
        public void TestInteger()
        {
            var t1 = new TypedValues <int>()
            {
                IgnoredValue = 100, DirectValue = 200, PropertyValue = 300
            };

            var wr = new JsonWriter(indented: false);

            new JsonSerializer().Serialize(t1, wr);
            string json = wr.ToString();

            Assert.AreEqual(@"{""a"":200,""b"":300}", json);

            var t2 = new JsonDeserializer().Deserialize <TypedValues <int> >(json);

            Assert.AreEqual(0, t2.IgnoredValue);
            Assert.AreEqual(200, t2.DirectValue);
            Assert.AreEqual(300, t2.PropertyValue);
        }
Esempio n. 3
0
        public void TestSimple()
        {
            var t1 = new TypedValues()
            {
                IgnoredValue = 100, DirectValue = 200, PropertyValue = 300, TestValue = int.MinValue
            };

            var wr = new JsonWriter(indented: false);

            new JsonSerializer().Serialize(t1, wr);
            string json = wr.ToString();

            Assert.AreEqual(@"{""a"":200,""b"":300,""c"":-2147483648}", json);

            var t2 = new JsonDeserializer().Deserialize <TypedValues>(json);

            Assert.AreEqual(0, t2.IgnoredValue);
            Assert.AreEqual(200, t2.DirectValue);
            Assert.AreEqual(300, t2.PropertyValue);
            Assert.AreEqual(int.MinValue, t2.TestValue);
        }