Beispiel #1
0
        public void SerializeDeserialize_Recursive()
        {
            T1 t1 = new T1();

            t1.x = 1;
            t1.y = 2;

            object aSerializedT1 = TestedSerializer.Serialize <T1>(t1);

            T2 t2 = new T2();

            t2.a = "hello";
            t2.o = aSerializedT1;

            object aSerializedT2 = TestedSerializer.Serialize <T2>(t2);


            T2 aDeserializedT2 = TestedSerializer.Deserialize <T2>(aSerializedT2);

            Assert.AreEqual(t2.a, aDeserializedT2.a);

            T1 aDeserializedT1 = TestedSerializer.Deserialize <T1>(aSerializedT1);

            Assert.AreEqual(t1.x, aDeserializedT1.x);
            Assert.AreEqual(t1.y, aDeserializedT1.y);
        }
Beispiel #2
0
        public void SerializeDeserialize()
        {
            string aData             = "hello world";
            object aSerializedData   = TestedSerializer.Serialize <string>(aData);
            string aDeserializedData = TestedSerializer.Deserialize <string>(aSerializedData);

            Assert.AreEqual(aData, aDeserializedData);
        }
Beispiel #3
0
        public void SerializeDeserialize_10MB()
        {
            // 10MB
            string aData             = RandomDataGenerator.GetString(10000000);
            object aSerializedData   = TestedSerializer.Serialize <string>(aData);
            string aDeserializedData = TestedSerializer.Deserialize <string>(aSerializedData);

            Assert.AreEqual(aData, aDeserializedData);
        }
Beispiel #4
0
        public void SerializeDeserialize_NULL()
        {
            T1 t1 = null;

            object aSerializedT1   = TestedSerializer.Serialize <T1>(t1);
            T1     aDeserializedT1 = TestedSerializer.Deserialize <T1>(aSerializedT1);

            Assert.AreEqual(null, aDeserializedT1);
        }
Beispiel #5
0
        public void SerializeDeserialize_EmptyByteArray()
        {
            byte[] aBytes = { };

            object aSerialized = TestedSerializer.Serialize <byte[]>(aBytes);

            byte[] aDeserialized = TestedSerializer.Deserialize <byte[]>(aSerialized);

            Assert.AreEqual(0, aDeserialized.Length);
        }
Beispiel #6
0
        //[Test]
        public void SerializeDeserialize_10MB_500x()
        {
            // 10MB
            string aData = RandomDataGenerator.GetString(10000000);

            for (int i = 0; i < 500; ++i)
            {
                object aSerializedData   = TestedSerializer.Serialize <string>(aData);
                string aDeserializedData = TestedSerializer.Deserialize <string>(aSerializedData);
                Assert.AreEqual(aData, aDeserializedData, "Iteration " + i.ToString() + " failed.");
            }
        }
Beispiel #7
0
        public void IncorrectPassword()
        {
            string aData = "Hello world.";

            // Serialize.
            object aSerializedData = TestedSerializer.Serialize <string>(aData);

            // Serializer with incorrect password.
            ISerializer anIncorrectSerializer = new AesSerializer("mytestpassword1");

            // Try to deserialize.
            Assert.Throws <CryptographicException>(() => anIncorrectSerializer.Deserialize <string>(aSerializedData));
        }
        public void SerializeDeserialize_10MB_GoodComprimation()
        {
            StringBuilder aStringBuilder = new StringBuilder();

            for (int i = 0; i < 10000000; ++i)
            {
                aStringBuilder.Append('a');
            }

            string aData = aStringBuilder.ToString();

            object aSerializedData = TestedSerializer.Serialize <string>(aData);

            EneterTrace.Info("Size of compressed data: " + ((byte[])aSerializedData).Length.ToString());

            string aDeserializedData = TestedSerializer.Deserialize <string>(aSerializedData);

            Assert.AreEqual(aData, aDeserializedData);
        }