コード例 #1
0
ファイル: Json.cs プロジェクト: zlzforever/AutoCSer
        internal static bool TestCase()
        {
            #region 引用类型字段成员JSON序列化测试
            Data.FieldData filedData = AutoCSer.RandomObject.Creator <Data.FieldData> .Create(randomConfig);

            string jsonString = AutoCSer.Json.Serializer.Serialize(filedData);
            //AutoCSer.Log.Trace.Console(jsonString);
            Data.FieldData newFieldData = AutoCSer.Json.Parser.Parse <Data.FieldData>(jsonString);
            if (!AutoCSer.FieldEquals.Comparor <Data.FieldData> .Equals(filedData, newFieldData))
            {
                return(false);
            }
            //AutoCSer.Log.Trace.Console(AutoCSer.Json.Serializer.Serialize(newFieldData));
            #endregion

            #region 带成员位图的引用类型字段成员JSON序列化测试
            jsonSerializeConfig.MemberMap = AutoCSer.Metadata.MemberMap <Data.FieldData> .NewFull();

            jsonString   = AutoCSer.Json.Serializer.Serialize(filedData, jsonSerializeConfig);
            newFieldData = AutoCSer.Json.Parser.Parse <Data.FieldData>(jsonString);
            if (!AutoCSer.FieldEquals.Comparor <Data.FieldData> .MemberMapEquals(filedData, newFieldData, jsonSerializeConfig.MemberMap))
            {
                return(false);
            }
            #endregion

            #region 引用类型属性成员JSON序列化测试
            Data.PropertyData propertyData = AutoCSer.RandomObject.Creator <Data.PropertyData> .Create(randomConfig);

            jsonString = AutoCSer.Json.Serializer.Serialize(propertyData);
            Data.PropertyData newPropertyData = AutoCSer.Json.Parser.Parse <Data.PropertyData>(jsonString);
            if (!AutoCSer.FieldEquals.Comparor <Data.PropertyData> .Equals(propertyData, newPropertyData))
            {
                return(false);
            }
            #endregion

            #region 值类型字段成员JSON序列化测试
            Data.StructFieldData structFieldData = AutoCSer.RandomObject.Creator <Data.StructFieldData> .Create(randomConfig);

            jsonString = AutoCSer.Json.Serializer.Serialize(structFieldData);
            Data.StructFieldData newStructFieldData = AutoCSer.Json.Parser.Parse <Data.StructFieldData>(jsonString);
            if (!AutoCSer.FieldEquals.Comparor <Data.StructFieldData> .Equals(structFieldData, newStructFieldData))
            {
                return(false);
            }
            #endregion

            #region 带成员位图的值类型字段成员JSON序列化测试
            jsonSerializeConfig.MemberMap = AutoCSer.Metadata.MemberMap <Data.StructFieldData> .NewFull();

            jsonString         = AutoCSer.Json.Serializer.Serialize(structFieldData, jsonSerializeConfig);
            newStructFieldData = AutoCSer.Json.Parser.Parse <Data.StructFieldData>(jsonString);
            if (!AutoCSer.FieldEquals.Comparor <Data.StructFieldData> .MemberMapEquals(structFieldData, newStructFieldData, jsonSerializeConfig.MemberMap))
            {
                return(false);
            }
            #endregion

            #region 值类型属性成员JSON序列化测试
            Data.StructPropertyData structPropertyData = AutoCSer.RandomObject.Creator <Data.StructPropertyData> .Create(randomConfig);

            jsonString = AutoCSer.Json.Serializer.Serialize(structPropertyData);
            Data.StructPropertyData newStructPropertyData = AutoCSer.Json.Parser.Parse <Data.StructPropertyData>(jsonString);
            if (!AutoCSer.FieldEquals.Comparor <Data.StructPropertyData> .Equals(structPropertyData, newStructPropertyData))
            {
                return(false);
            }
            #endregion

            if (AutoCSer.Json.Parser.Parse <int>(jsonString = AutoCSer.Json.Serializer.Serialize <int>(1)) != 1)
            {
                return(false);
            }
            if (AutoCSer.Json.Parser.Parse <string>(jsonString = AutoCSer.Json.Serializer.Serialize <string>("1")) != "1")
            {
                return(false);
            }

            Data.Float floatData = AutoCSer.Json.Parser.Parse <Data.Float>(@"{Double4:-4.0,Double2:2.0,Double6:-6.0,Double5:5.0,Double3:-3.0}");
            if (floatData.Double2 != 2 || floatData.Double3 != -3 || floatData.Double4 != -4 || floatData.Double5 != 5 || floatData.Double6 != -6)
            {
                return(false);
            }

            floatData = new Data.Float {
                FloatPositiveInfinity = float.NaN, FloatNegativeInfinity = float.NaN, DoublePositiveInfinity = double.NaN, DoubleNegativeInfinity = double.NaN
            };
            jsonString = AutoCSer.Json.Serializer.Serialize(floatData);
            Data.Float newFloatData = AutoCSer.Json.Parser.Parse <Data.Float>(jsonString);
            if (!AutoCSer.FieldEquals.Comparor <Data.Float> .Equals(floatData, newFloatData))
            {
                return(false);
            }

            floatData  = new Data.Float();
            jsonString = AutoCSer.Json.Serializer.Serialize(floatData, new AutoCSer.Json.SerializeConfig {
                IsInfinityToNaN = false
            });
            newFloatData = AutoCSer.Json.Parser.Parse <Data.Float>(jsonString);
            if (!AutoCSer.FieldEquals.Comparor <Data.Float> .Equals(floatData, newFloatData))
            {
                return(false);
            }
            return(true);
        }
コード例 #2
0
        internal static bool TestCase()
        {
            Data.Float floatData = new Data.Float();
            string     xmlString = AutoCSer.Xml.Serializer.Serialize(floatData);

            Data.Float newFloatData = AutoCSer.Xml.Parser.Parse <Data.Float>(xmlString);
            if (!AutoCSer.FieldEquals.Comparor <Data.Float> .Equals(floatData, newFloatData))
            {
                return(false);
            }

            #region 引用类型字段成员XML序列化测试
            Data.FieldData filedData = AutoCSer.RandomObject.Creator <Data.FieldData> .Create(randomConfig);

            xmlString = AutoCSer.Xml.Serializer.Serialize(filedData);
            //AutoCSer.Log.Trace.Console(xmlString);
            Data.FieldData newFieldData = AutoCSer.Xml.Parser.Parse <Data.FieldData>(xmlString);
            if (!AutoCSer.FieldEquals.Comparor <Data.FieldData> .Equals(filedData, newFieldData))
            {
                return(false);
            }
            //AutoCSer.Log.Trace.Console(AutoCSer.Xml.Serializer.Serialize(newFieldData));
            #endregion

            #region 带成员位图的引用类型字段成员XML序列化测试
            xmlSerializeConfig.MemberMap = AutoCSer.Metadata.MemberMap <Data.FieldData> .NewFull();

            xmlString    = AutoCSer.Xml.Serializer.Serialize(filedData, xmlSerializeConfig);
            newFieldData = AutoCSer.Xml.Parser.Parse <Data.FieldData>(xmlString);
            if (!AutoCSer.FieldEquals.Comparor <Data.FieldData> .MemberMapEquals(filedData, newFieldData, xmlSerializeConfig.MemberMap))
            {
                return(false);
            }
            #endregion

            #region 引用类型属性成员XML序列化测试
            Data.PropertyData propertyData = AutoCSer.RandomObject.Creator <Data.PropertyData> .Create(randomConfig);

            xmlString = AutoCSer.Xml.Serializer.Serialize(propertyData);
            Data.PropertyData newPropertyData = AutoCSer.Xml.Parser.Parse <Data.PropertyData>(xmlString);
            if (!AutoCSer.FieldEquals.Comparor <Data.PropertyData> .Equals(propertyData, newPropertyData))
            {
                return(false);
            }
            #endregion

            #region 值类型字段成员XML序列化测试
            Data.StructFieldData structFieldData = AutoCSer.RandomObject.Creator <Data.StructFieldData> .Create(randomConfig);

            xmlString = AutoCSer.Xml.Serializer.Serialize(structFieldData);
            Data.StructFieldData newStructFieldData = AutoCSer.Xml.Parser.Parse <Data.StructFieldData>(xmlString);
            if (!AutoCSer.FieldEquals.Comparor <Data.StructFieldData> .Equals(structFieldData, newStructFieldData))
            {
                return(false);
            }
            #endregion

            #region 带成员位图的值类型字段成员XML序列化测试
            xmlSerializeConfig.MemberMap = AutoCSer.Metadata.MemberMap <Data.StructFieldData> .NewFull();

            xmlString          = AutoCSer.Xml.Serializer.Serialize(structFieldData, xmlSerializeConfig);
            newStructFieldData = AutoCSer.Xml.Parser.Parse <Data.StructFieldData>(xmlString);
            if (!AutoCSer.FieldEquals.Comparor <Data.StructFieldData> .MemberMapEquals(structFieldData, newStructFieldData, xmlSerializeConfig.MemberMap))
            {
                return(false);
            }
            #endregion

            #region 值类型属性成员XML序列化测试
            Data.StructPropertyData structPropertyData = AutoCSer.RandomObject.Creator <Data.StructPropertyData> .Create(randomConfig);

            xmlString = AutoCSer.Xml.Serializer.Serialize(structPropertyData);
            Data.StructPropertyData newStructPropertyData = AutoCSer.Xml.Parser.Parse <Data.StructPropertyData>(xmlString);
            if (!AutoCSer.FieldEquals.Comparor <Data.StructPropertyData> .Equals(structPropertyData, newStructPropertyData))
            {
                return(false);
            }
            #endregion

            if (AutoCSer.Xml.Parser.Parse <int>(xmlString = AutoCSer.Xml.Serializer.Serialize <int>(1)) != 1)
            {
                return(false);
            }
            if (AutoCSer.Xml.Parser.Parse <string>(xmlString = AutoCSer.Xml.Serializer.Serialize <string>("1")) != "1")
            {
                return(false);
            }

            return(true);
        }