Exemplo n.º 1
0
        public void TestJsonLong()
        {
            var expectedObjects = new JsonNumTestContainer[] {
                // URGENT TODO: This test fails for long.MaxValue - Write custom serializers for ulongs that can handle larger values
                new JsonNumTestContainer {
                    IntValue = int.MaxValue, UintValue = uint.MaxValue, LongValue = long.MaxValue, UlongValue = long.MaxValue, FloatValue = float.MaxValue, DoubleValue = double.MaxValue
                },
                new JsonNumTestContainer {
                    IntValue = int.MinValue, UintValue = uint.MinValue, LongValue = long.MinValue, UlongValue = ulong.MinValue, FloatValue = float.MinValue, DoubleValue = double.MinValue
                },
                new JsonNumTestContainer {
                    IntValue = 0, UintValue = 0, LongValue = 0, UlongValue = 0, FloatValue = 0, DoubleValue = 0
                },
            };

            for (int i = 0; i < expectedObjects.Length; i++)
            {
                // Convert the object to json and back, and verify that everything is the same
                var actualJson   = JsonConvert.SerializeObject(expectedObjects[i], Util.JsonFormatting, Util.JsonSettings).Replace(" ", "").Replace("\n", "").Replace("\r", "").Replace("\t", "");
                var actualObject = JsonConvert.DeserializeObject <JsonNumTestContainer>(actualJson, Util.JsonSettings);

                UUnitAssert.IntEquals(expectedObjects[i].IntValue, actualObject.IntValue);
                UUnitAssert.UintEquals(expectedObjects[i].UintValue, actualObject.UintValue);
                UUnitAssert.LongEquals(expectedObjects[i].LongValue, actualObject.LongValue);
                UUnitAssert.ULongEquals(expectedObjects[i].UlongValue, actualObject.UlongValue);
                UUnitAssert.FloatEquals(expectedObjects[i].FloatValue, actualObject.FloatValue, 0.001f);
                UUnitAssert.DoubleEquals(expectedObjects[i].DoubleValue, actualObject.DoubleValue, 0.001);
            }
        }
Exemplo n.º 2
0
        public void TestJsonLong()
        {
            var expectedObjects = new JsonNumTestContainer[] {
                // URGENT TODO: This test fails for long.MaxValue - Write custom serializers for ulongs that can handle larger values
                new JsonNumTestContainer { IntValue = int.MaxValue, UintValue = uint.MaxValue, LongValue = long.MaxValue, UlongValue = long.MaxValue, FloatValue = float.MaxValue, DoubleValue = double.MaxValue },
                new JsonNumTestContainer { IntValue = int.MinValue, UintValue = uint.MinValue, LongValue = long.MinValue, UlongValue = ulong.MinValue, FloatValue = float.MinValue, DoubleValue = double.MinValue },
                new JsonNumTestContainer { IntValue = 0, UintValue = 0, LongValue = 0, UlongValue = 0, FloatValue = 0, DoubleValue = 0 },
            };

            for (int i = 0; i < expectedObjects.Length; i++)
            {
                // Convert the object to json and back, and verify that everything is the same
                var actualJson = JsonConvert.SerializeObject(expectedObjects[i], Util.JsonFormatting, Util.JsonSettings).Replace(" ", "").Replace("\n", "").Replace("\r", "").Replace("\t", "");
                var actualObject = JsonConvert.DeserializeObject<JsonNumTestContainer>(actualJson, Util.JsonSettings);

                UUnitAssert.IntEquals(expectedObjects[i].IntValue, actualObject.IntValue);
                UUnitAssert.UintEquals(expectedObjects[i].UintValue, actualObject.UintValue);
                UUnitAssert.LongEquals(expectedObjects[i].LongValue, actualObject.LongValue);
                UUnitAssert.ULongEquals(expectedObjects[i].UlongValue, actualObject.UlongValue);
                UUnitAssert.FloatEquals(expectedObjects[i].FloatValue, actualObject.FloatValue, 0.001f);
                UUnitAssert.DoubleEquals(expectedObjects[i].DoubleValue, actualObject.DoubleValue, 0.001);
            }
        }