Ejemplo n.º 1
0
        public static JSONTestObj PrepareData()
        {
            JSONTestObj result = new JSONTestObj();

            result.ID       = UuidHelper.NewUuidString();
            result.Age      = 41;
            result.Birthday = new DateTime(1972, 4, 26, 12, 40, 0, DateTimeKind.Local);

            return(result);
        }
Ejemplo n.º 2
0
		public static JSONTestObj PrepareData()
		{
			JSONTestObj result = new JSONTestObj();

			result.ID = UuidHelper.NewUuidString();
			result.Age = 41;
			result.Birthday = new DateTime(1972, 4, 26, 12, 40, 0, DateTimeKind.Local);

			return result;
		}
Ejemplo n.º 3
0
        public void SimpleObjectJSONTest()
        {
            JSONTestObj data = JSONTestObj.PrepareData();

            string json = JSONSerializerExecute.Serialize(data);

            Console.WriteLine(json);

            JSONTestObj deserializedData = JSONSerializerExecute.Deserialize <JSONTestObj>(json);

            AssertObjects(data, deserializedData);
        }
Ejemplo n.º 4
0
        public void DictObjectJSONTest()
        {
            Dictionary <string, object> source = new Dictionary <string, object>();

            JSONTestObj data = JSONTestObj.PrepareData();

            source.Add("Data", data);

            string json = JSONSerializerExecute.SerializeWithType(source);

            Console.WriteLine(json);

            Dictionary <string, object> deserializedData = JSONSerializerExecute.Deserialize <Dictionary <string, object> >(json);

            AssertObjects((JSONTestObj)source["Data"], (JSONTestObj)deserializedData["Data"]);
        }
Ejemplo n.º 5
0
        public void ListObjectJSONTest()
        {
            JSONTestObj data = JSONTestObj.PrepareData();

            List <JSONTestObj> source = new List <JSONTestObj>();

            source.Add(data);

            string json = JSONSerializerExecute.Serialize(source);

            Console.WriteLine(json);

            List <JSONTestObj> deserializedData = JSONSerializerExecute.Deserialize <List <JSONTestObj> >(json);

            AssertObjects(data, deserializedData[0]);
        }
Ejemplo n.º 6
0
        //[TestMethod]
        //[Description("集合对象的JSON序列化测试")]
        //public void VocherObjectJSONTest()
        //{
        //    VocherEntity source = VocherEntity.PrepareData();

        //    string json = JSONSerializerExecute.SerializeWithType(source);

        //    Console.WriteLine(json);

        //    VocherEntity deserialized = JSONSerializerExecute.Deserialize<VocherEntity>(json);

        //    Assert.AreEqual(source.Items.Count, deserialized.Items.Count);
        //}

        private static void AssertObjects(JSONTestObj source, JSONTestObj dest)
        {
            Assert.AreEqual(source.ID, dest.ID);
            Assert.AreEqual(source.Age, dest.Age);
            Assert.AreEqual(source.Birthday, dest.Birthday);
        }
Ejemplo n.º 7
0
        //[TestMethod]
        //[Description("集合对象的JSON序列化测试")]
        //public void VocherObjectJSONTest()
        //{
        //    VocherEntity source = VocherEntity.PrepareData();

        //    string json = JSONSerializerExecute.SerializeWithType(source);

        //    Console.WriteLine(json);

        //    VocherEntity deserialized = JSONSerializerExecute.Deserialize<VocherEntity>(json);

        //    Assert.AreEqual(source.Items.Count, deserialized.Items.Count);
        //}

        private static void AssertObjects(JSONTestObj source, JSONTestObj dest)
        {
            Assert.AreEqual(source.ID, dest.ID);
            Assert.AreEqual(source.Age, dest.Age);
            Assert.AreEqual(source.Birthday, dest.Birthday);
        }