Beispiel #1
0
        void EnumConversionTest_Deserialize()
        {
            EnumConversionTestClass expectedObj = new EnumConversionTestClass(), actualObj = new EnumConversionTestClass();

            expectedObj.enumList = new List <testRegion>()
            {
                testRegion.USEast, testRegion.USCentral, testRegion.Japan
            };
            expectedObj.enumArray = new testRegion[] { testRegion.USEast, testRegion.USCentral, testRegion.Japan };
            expectedObj.enumValue = testRegion.Australia;

            string inputJson = "{\"enumList\":[" + ((int)testRegion.USEast) + "," + ((int)testRegion.USCentral) + "," + ((int)testRegion.Japan) + "],\"enumArray\":[" + ((int)testRegion.USEast) + "," + ((int)testRegion.USCentral) + "," + ((int)testRegion.Japan) + "],\"enumValue\":" + ((int)testRegion.Australia) + "}";

            JsonConvert.PopulateObject(inputJson, actualObj, Util.JsonSettings);
            UUnitAssert.ObjEquals(expectedObj, actualObj);
        }
Beispiel #2
0
        void EnumConversionTest_Deserialize()
        {
            EnumConversionTestClass expectedObj = new EnumConversionTestClass(), actualObj;

            expectedObj.enumList = new List <testRegion>()
            {
                testRegion.USEast, testRegion.USCentral, testRegion.Japan
            };
            expectedObj.enumArray    = new testRegion[] { testRegion.USEast, testRegion.USCentral, testRegion.Japan };
            expectedObj.enumValue    = testRegion.Australia;
            expectedObj.optEnumValue = null;

            string inputJson = "{\"enumList\":[" + ((int)testRegion.USEast) + "," + ((int)testRegion.USCentral) + "," + ((int)testRegion.Japan) + "],\"enumArray\":[" + ((int)testRegion.USEast) + "," + ((int)testRegion.USCentral) + "," + ((int)testRegion.Japan) + "],\"enumValue\":" + ((int)testRegion.Australia) + "}";

            actualObj = SimpleJson.DeserializeObject <EnumConversionTestClass>(inputJson, Util.ApiSerializerStrategy);
            UUnitAssert.ObjEquals(expectedObj, actualObj);
        }
Beispiel #3
0
        void EnumConversionTest()
        {
            string expectedJson, actualJson;
            EnumConversionTestClass expectedObj = new EnumConversionTestClass(), actualObj = new EnumConversionTestClass();

            expectedObj.enumList = new List <testRegion>()
            {
                testRegion.USEast, testRegion.USCentral, testRegion.Japan
            };
            expectedObj.enumArray = new testRegion[] { testRegion.USEast, testRegion.USCentral, testRegion.Japan };
            expectedObj.enumValue = testRegion.Australia;

            expectedJson = "{\"enumList\":[\"USEast\",\"USCentral\",\"Japan\"],\"enumArray\":[\"USEast\",\"USCentral\",\"Japan\"],\"enumValue\":\"Australia\"}";

            JsonConvert.PopulateObject(expectedJson, actualObj, Util.JsonSettings);
            actualJson = JsonConvert.SerializeObject(actualObj, Util.JsonFormatting, Util.JsonSettings);

            UUnitAssert.Equals(expectedJson.Replace(" ", "").Replace("\n", ""), actualJson.Replace(" ", "").Replace("\n", ""));
            UUnitAssert.ObjEquals(expectedObj, actualObj);
        }
Beispiel #4
0
        void EnumConversionTest_Serialize()
        {
            string expectedJson, actualJson;
            EnumConversionTestClass expectedObj = new EnumConversionTestClass(), actualObj;

            expectedObj.enumList = new List <testRegion>()
            {
                testRegion.USEast, testRegion.USCentral, testRegion.Japan
            };
            expectedObj.enumArray    = new testRegion[] { testRegion.USEast, testRegion.USCentral, testRegion.Japan };
            expectedObj.enumValue    = testRegion.Australia;
            expectedObj.optEnumValue = null;

            expectedJson = "{\"enumList\":[\"USEast\",\"USCentral\",\"Japan\"],\"enumArray\":[\"USEast\",\"USCentral\",\"Japan\"],\"enumValue\":\"Australia\",\"optEnumValue\":null}";

            actualObj  = SimpleJson.DeserializeObject <EnumConversionTestClass>(expectedJson, Util.ApiSerializerStrategy);
            actualJson = SimpleJson.SerializeObject(actualObj, Util.ApiSerializerStrategy);

            UUnitAssert.StringEquals(expectedJson.Replace(" ", "").Replace("\n", ""), actualJson.Replace(" ", "").Replace("\n", ""));
            UUnitAssert.ObjEquals(expectedObj, actualObj);
        }
Beispiel #5
0
        void EnumConversionTest_OptionalEnum()
        {
            EnumConversionTestClass expectedObj = new EnumConversionTestClass();

            expectedObj.enumList = new List <testRegion>()
            {
                testRegion.USEast, testRegion.USCentral, testRegion.Japan
            };
            expectedObj.enumArray    = new testRegion[] { testRegion.USEast, testRegion.USCentral, testRegion.Japan };
            expectedObj.enumValue    = testRegion.Australia;
            expectedObj.optEnumValue = null;

            var actualJson = SimpleJson.SerializeObject(expectedObj, Util.ApiSerializerStrategy);
            var actualObj  = SimpleJson.DeserializeObject <EnumConversionTestClass>(actualJson, Util.ApiSerializerStrategy);

            UUnitAssert.ObjEquals(expectedObj, actualObj);

            expectedObj.optEnumValue = testRegion.Brazil;
            actualJson = SimpleJson.SerializeObject(expectedObj, Util.ApiSerializerStrategy);
            actualObj  = SimpleJson.DeserializeObject <EnumConversionTestClass>(actualJson, Util.ApiSerializerStrategy);
            UUnitAssert.ObjEquals(expectedObj, actualObj);
        }