Beispiel #1
0
        public void BinarySerializer_Deserialize_GivenNullInput_ShouldReturnNull()
        {
            var binarySerializer = new BinarySerializer();
            var result = binarySerializer.Deserialize(null);

            Assert.IsNull(result);
        }
        public void BinarySerializer_Deserialize_GivenValidReferenceType_ShouldReturnReferenceType()
        {
            var binarySerializer = new BinarySerializer();
            var input = "test";
            var serialized = binarySerializer.Serialize(input);

            var deserialized = binarySerializer.Deserialize<string>(serialized);

            Assert.IsNotNull(deserialized);
            Assert.AreEqual("test", deserialized);
        }
        public void BinarySerializer_Deserialize_GivenValidValueType_ShouldReturnValueType()
        {
            var binarySerializer = new BinarySerializer();
            var input = 123;
            var serialized = binarySerializer.Serialize(input);

            var deserialized = binarySerializer.Deserialize<int>(serialized);

            Assert.IsNotNull(deserialized);
            Assert.AreEqual(123, deserialized);
        }
Beispiel #4
0
        public void BinarySerializer_Deserialize_GivenValidReferenceTypeAsBytesInput_ShouldReturnReferenceType()
        {
            var binarySerializer = new BinarySerializer();
            // string value of "test" as bytes
            var serializedString = new byte[] { 0, 1, 0, 0, 0, 255, 255, 255, 255, 1, 0, 0, 0, 0, 0, 0, 0, 6, 1, 0, 0, 0, 4, 116, 101, 115, 116, 11 };

            var resultObject = binarySerializer.Deserialize(serializedString);

            Assert.IsNotNull(resultObject);

            var deserializedString = resultObject as string;

            Assert.IsNotNull(deserializedString);
            Assert.AreEqual("test", deserializedString);
        }
Beispiel #5
0
        public void BinarySerializer_Deserialize_GivenValidValueTypeAsBytesInput_ShouldReturnValueType()
        {
            var binarySerializer = new BinarySerializer();
            // int value of 123 as bytes
            var serializedInt = new byte[]
            { 0, 1, 0, 0, 0, 255, 255, 255, 255, 1, 0, 0, 0, 0, 0, 0, 0, 4, 1, 0, 0, 0, 12, 83, 121, 115, 116, 101,
                109, 46, 73, 110, 116, 51, 50, 1, 0, 0, 0, 7, 109, 95, 118, 97, 108, 117, 101, 0, 8, 123, 0, 0, 0, 11 };

            var resultObject = binarySerializer.Deserialize(serializedInt);

            Assert.IsNotNull(resultObject);

            var deserializedInt = (int)resultObject;

            Assert.AreEqual(123, deserializedInt);
        }
Beispiel #6
0
        public void BinarySerializer_Serialize_Deserialize_ShouldReturnOriginalResult()
        {
            var binarySerializer = new BinarySerializer();
            var input = "test";
            var serializedResult = binarySerializer.Serialize(input);

            Assert.IsNotNull(serializedResult);

            var deserializedResult = binarySerializer.Deserialize(serializedResult);

            Assert.IsNotNull(deserializedResult);

            var resultString = deserializedResult as string;

            Assert.IsNotNull(resultString);
            Assert.AreEqual("test", resultString);
        }