Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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));
        }
Ejemplo n.º 4
0
 public void TestBoundaryConvertToByteArray()
 {
     Assert.Null(ObjectUtil.ConvertToByteArray(new NonSerializableClass()));
 }