Esempio n. 1
0
        public void TestSerializeComplexObjectBad()
        {
            Stranger parent = new Stranger {
                Name = "Hello", Orphan = new Orphan {
                    Name = "World"
                }
            };

            byte[] serialized = ObjectUtil.ConvertToByteArray(parent);

            Assert.Null(serialized);
        }
Esempio n. 2
0
        public void TestSerializeComplexObjectGood()
        {
            Parent parent = new Parent {
                Name = "Hello", Child = new Child {
                    Name = "World"
                }
            };

            byte[] serialized = ObjectUtil.ConvertToByteArray(parent);

            Assert.NotNull(serialized);
            Assert.IsTrue(serialized.LongLength > 0);
            Assert.AreEqual(372, serialized.LongLength);

            Parent deserialized = (Parent)ObjectUtil.ConvertToObject(serialized);

            Assert.NotNull(deserialized);
            Assert.AreEqual("Hello", deserialized.Name);
            Assert.AreEqual("World", deserialized.Child.Name);
        }
Esempio n. 3
0
        /// <summary>
        /// Encrypts the specified instance.
        /// </summary>
        /// <param name="instance">Object instance submitted for encryption.</param>
        /// <returns>The value byte[] will be returned if encryption was successful;
        /// null for otherwise.</returns>
        public static byte[] Encrypt(object instance)
        {
            if (instance == null)
            {
                Logger.Warn("Unable to encrypt NULL instance");
                return(null);
            }

            if (Logger.IsDebugEnabled)
            {
                Logger.DebugFormat("Encrypting instance: {0}", instance);
            }

            byte[] serializedInstance = ObjectUtil.ConvertToByteArray(instance);

            if (serializedInstance == null)
            {
                return(null);
            }

            return(SimpleEncryption.Encrypt(serializedInstance, PassPhrase));
        }
Esempio n. 4
0
 public void TestBoundaryConvertToByteArray()
 {
     Assert.Null(ObjectUtil.ConvertToByteArray(new NonSerializableClass()));
 }