Beispiel #1
0
        public void Serialize_Shoud_Serialize_Given_Object()
        {
            var serializer = new Serializer(new SerializerOptions(
                                                preserveObjectReferences: HyperionSerializerSettings.Default.PreserveObjectReferences,
                                                versionTolerance: HyperionSerializerSettings.Default.VersionTolerance,
                                                ignoreISerializable: HyperionSerializerSettings.Default.IgnoreISerializable));

            HyperionSerializer hyperionSerializer = new HyperionSerializer();

            var user = new TestUser
            {
                Age  = 31,
                Id   = Guid.NewGuid(),
                Name = "Deniz"
            };

            byte[] serializedUser = hyperionSerializer.Serialize(user);

            using (var bodyStream = new MemoryStream(serializedUser))
            {
                var deserializedUser = serializer.Deserialize(bodyStream);

                var testUser = deserializedUser as TestUser;

                Assert.True(testUser != null);

                Assert.Equal(testUser.Name, user.Name);
                Assert.Equal(testUser.Age, user.Age);
                Assert.Equal(testUser.Id, user.Id);
            }
        }
        public void Should_Serialize_Given_Object()
        {
            var serializer = new Serializer(new SerializerOptions(preserveObjectReferences: HyperionSerializerSettings.Default.PreserveObjectReferences,
                                                                  versionTolerance: HyperionSerializerSettings.Default.VersionTolerance, ignoreISerializable: true));

            var user = new TestUser {
                Age = 31, Id = Guid.NewGuid(), Name = "Deniz"
            };

            var hyperionSerializer = new HyperionSerializer(serializer);

            using (var bodyStream = new MemoryStream())
            {
                hyperionSerializer.Serialize("application/x-hyperion", user, bodyStream);

                bodyStream.Position = 0;

                object deserializedUser = serializer.Deserialize(bodyStream);

                var testUser = deserializedUser as TestUser;

                Assert.True(testUser != null);

                Assert.Equal(testUser.Name, user.Name);
                Assert.Equal(testUser.Age, user.Age);
                Assert.Equal(testUser.Id, user.Id);
            }
        }