Serialize() public method

지정된 객체를 Serialize를 수행한다.
의 형식이 byte[] 가 아닌 경우
public Serialize ( object graph ) : byte[]
graph object 직렬화할 객체
return byte[]
        public void Serialize_By_SymmetricEncryptor() {
            var user = UserInfo.GetSample();

            foreach(var encryptor in symmetricEncryptors) {
                var serializer = new EncryptSerializer<UserInfo>(new BinarySerializer<UserInfo>(), encryptor);

                var data = serializer.Serialize(user);
                var user2 = serializer.Deserialize(data);

                Assert.AreEqual(user.FirstName, user2.FirstName);
                Assert.AreEqual(user.FavoriteMovies.Count, user.FavoriteMovies.Count);
            }
        }
Example #2
0
        public void XmlSerialize_With_Compress_Encryption([Values(typeof(SharpBZip2Compressor),
                                                              typeof(GZipCompressor),
                                                              typeof(DeflateCompressor),
                                                              typeof(SevenZipCompressor))] Type compressorType,
                                                          [Values(typeof(AriaSymmetricEncryptor),
                                                              typeof(RC2SymmetricEncryptor),
                                                              typeof(TripleDESSymmetricEncryptor))] Type encryptorType) {
            var xmlSerializer = XmlSerializer<List<User>>.Instance;
            var compressor = (ICompressor)ActivatorTool.CreateInstance(compressorType);
            var encryptor = (ISymmetricEncryptor)ActivatorTool.CreateInstance(encryptorType);

            var serializer = new EncryptSerializer<List<User>>(new CompressSerializer<List<User>>(xmlSerializer, compressor), encryptor);

            var users = GetSampleUsers(10);

            var usersData = serializer.Serialize(users);
            var deserializedUsers = serializer.Deserialize(usersData);

            CollectionAssert.AreEqual(users, deserializedUsers);
        }