예제 #1
0
        public void Serialize_NullObject_IntegerNull()
        {
            // arrange
            var node         = JSON.Parse(JsonObjectStringWithAllNull);
            var memoryStream = new MemoryStream();
            var binaryWriter = new BinaryWriter(memoryStream);
            var binaryReader = new BinaryReader(memoryStream);

            // act
            node.Serialize(binaryWriter);
            memoryStream.Seek(0, SeekOrigin.Begin);
            node = JSONNode.Deserialize(binaryReader);

            // assert
            Assert.IsTrue(node["integer"].IsNull);
        }
예제 #2
0
        public void Serialize_SimpleObject_NegativeExponentialSuccess()
        {
            // arrange
            var node         = JSON.Parse(JsonObjectStringWithAllTypes);
            var memoryStream = new MemoryStream();
            var binaryWriter = new BinaryWriter(memoryStream);
            var binaryReader = new BinaryReader(memoryStream);

            // act
            node.Serialize(binaryWriter);
            memoryStream.Seek(0, SeekOrigin.Begin);
            node = JSONNode.Deserialize(binaryReader);

            // assert
            Assert.AreEqual(0.0003, node["exponential"]["negative"].AsFloat, 0.000001);
        }
예제 #3
0
        public void Serialize_SimpleObject_NegativeLongSuccess()
        {
            // arrange
            var node         = JSON.Parse(JsonObjectStringWithAllTypes);
            var memoryStream = new MemoryStream();
            var binaryWriter = new BinaryWriter(memoryStream);
            var binaryReader = new BinaryReader(memoryStream);

            // act
            node.Serialize(binaryWriter);
            memoryStream.Seek(0, SeekOrigin.Begin);
            node = JSONNode.Deserialize(binaryReader);

            // assert
            Assert.AreEqual(-1234567890000, node["long"]["negative"].AsLong);
        }
예제 #4
0
        public void Serialize_SimpleObject_DoubleNegativeSuccess()
        {
            // arrange
            var node         = JSON.Parse(JsonObjectStringWithAllTypes);
            var memoryStream = new MemoryStream();
            var binaryWriter = new BinaryWriter(memoryStream);
            var binaryReader = new BinaryReader(memoryStream);

            // act
            node.Serialize(binaryWriter);
            memoryStream.Seek(0, SeekOrigin.Begin);
            node = JSONNode.Deserialize(binaryReader);

            // assert
            Assert.AreEqual(-3.14159265359, node["double"]["negative"].AsDouble, 0.000000000001);
        }
예제 #5
0
        public void Serialize_SimpleObject_SpecialStringSuccess()
        {
            // arrange
            var node         = JSON.Parse(JsonObjectStringWithAllTypes);
            var memoryStream = new MemoryStream();
            var binaryWriter = new BinaryWriter(memoryStream);
            var binaryReader = new BinaryReader(memoryStream);

            // act
            node.Serialize(binaryWriter);
            memoryStream.Seek(0, SeekOrigin.Begin);
            node = JSONNode.Deserialize(binaryReader);

            // assert
            Assert.AreEqual(@":,[]{}""\\t\n\r\bA\f\m/", node["string"]["special"].Value);
        }
예제 #6
0
        public void Serialize_SimpleObject_ExplicitPositiveIntegerSuccess()
        {
            // arrange
            var node         = JSON.Parse(JsonObjectStringWithAllTypes);
            var memoryStream = new MemoryStream();
            var binaryWriter = new BinaryWriter(memoryStream);
            var binaryReader = new BinaryReader(memoryStream);

            // act
            node.Serialize(binaryWriter);
            memoryStream.Seek(0, SeekOrigin.Begin);
            node = JSONNode.Deserialize(binaryReader);

            // assert
            Assert.AreEqual(1, node["integer"]["explicitPositive"].AsInt);
        }
예제 #7
0
        public void Serialize_SimpleObject_PopulatedArrayObjectAtFive()
        {
            // arrange
            var node         = JSON.Parse(JsonObjectStringWithAllTypes);
            var memoryStream = new MemoryStream();
            var binaryWriter = new BinaryWriter(memoryStream);
            var binaryReader = new BinaryReader(memoryStream);

            // act
            node.Serialize(binaryWriter);
            memoryStream.Seek(0, SeekOrigin.Begin);
            node = JSONNode.Deserialize(binaryReader);

            // assert
            Assert.IsNotNull(node["array"]["populated"].AsArray[5].AsObject);
        }
예제 #8
0
        public void Serialize_SimpleObject_PopulatedArrayStringAtThree()
        {
            // arrange
            var node         = JSON.Parse(JsonObjectStringWithAllTypes);
            var memoryStream = new MemoryStream();
            var binaryWriter = new BinaryWriter(memoryStream);
            var binaryReader = new BinaryReader(memoryStream);

            // act
            node.Serialize(binaryWriter);
            memoryStream.Seek(0, SeekOrigin.Begin);
            node = JSONNode.Deserialize(binaryReader);

            // assert
            Assert.AreEqual("string", node["array"]["populated"].AsArray[3].Value);
        }
예제 #9
0
        public void Serialize_SimpleObject_EmptyArrayCountZero()
        {
            // arrange
            var node         = JSON.Parse(JsonObjectStringWithAllTypes);
            var memoryStream = new MemoryStream();
            var binaryWriter = new BinaryWriter(memoryStream);
            var binaryReader = new BinaryReader(memoryStream);

            // act
            node.Serialize(binaryWriter);
            memoryStream.Seek(0, SeekOrigin.Begin);
            node = JSONNode.Deserialize(binaryReader);

            // assert
            Assert.AreEqual(0, node["array"]["empty"].AsArray.Count);
        }
예제 #10
0
        public void Serialize_SimpleObject_NullSuccess()
        {
            // arrange
            var node         = JSON.Parse(JsonObjectStringWithAllTypes);
            var memoryStream = new MemoryStream();
            var binaryWriter = new BinaryWriter(memoryStream);
            var binaryReader = new BinaryReader(memoryStream);

            // act
            node.Serialize(binaryWriter);
            memoryStream.Seek(0, SeekOrigin.Begin);
            node = JSONNode.Deserialize(binaryReader);

            // assert
            Assert.IsTrue(node["null"].IsNull);
        }
예제 #11
0
        public void Serialize_SimpleObject_FalseBoolSuccess()
        {
            // arrange
            var node         = JSON.Parse(JsonObjectStringWithAllTypes);
            var memoryStream = new MemoryStream();
            var binaryWriter = new BinaryWriter(memoryStream);
            var binaryReader = new BinaryReader(memoryStream);

            // act
            node.Serialize(binaryWriter);
            memoryStream.Seek(0, SeekOrigin.Begin);
            node = JSONNode.Deserialize(binaryReader);

            // assert
            Assert.AreEqual(false, node["boolean"]["negative"].AsBool);
        }
예제 #12
0
        public void Serialize_NullObject_StringNull()
        {
            // arrange
            var node         = JSON.Parse(JsonObjectStringWithAllNull);
            var memoryStream = new MemoryStream();
            var binaryWriter = new BinaryWriter(memoryStream);
            var binaryReader = new BinaryReader(memoryStream);

            // act
            node.Serialize(binaryWriter);
            memoryStream.Seek(0, SeekOrigin.Begin);
            node = JSONNode.Deserialize(binaryReader);


            // assert
            Assert.AreEqual("null", node["string"].Value);
        }