Example #1
0
        public void TestWriteObjectWithCustomSerializable()
        {
            var config = new SerializationOptions();
            var sc     = new SerializerOptions
            {
                SerializedType = typeof(CustomSerializableType),
                Creator        = () => new CustomSerializer()
            };

            config.Serializers.Add(sc);
            var serializationService =
                new SerializationServiceBuilder(new NullLoggerFactory()).SetPortableVersion(1)
                .AddPortableFactory(SerializationTestsConstants.PORTABLE_FACTORY_ID, new TestPortableFactory())
                .SetConfig(config).Build();

            var foo = new CustomSerializableType {
                Value = "foo"
            };

            var objectCarryingPortable1 = new ObjectCarryingPortable(foo);
            var data = serializationService.ToData(objectCarryingPortable1);
            var objectCarryingPortable2 = serializationService.ToObject <ObjectCarryingPortable>(data);

            Assert.AreEqual(objectCarryingPortable1, objectCarryingPortable2);
        }
        public void TestGlobalSerializer()
        {
            var config = new SerializationOptions();

            config.DefaultSerializer = new SerializerOptions
            {
                Creator = () => (ISerializer)ServiceFactory.CreateInstance(typeof(GlobalSerializer).AssemblyQualifiedName)
            };

            var ss = new SerializationServiceBuilder(new NullLoggerFactory()).SetConfig(config).Build();

            var foo = new CustomSerializableType {
                Value = "fooooo"
            };

            var d      = ss.ToData(foo);
            var newFoo = ss.ToObject <CustomSerializableType>(d);

            Assert.AreEqual(newFoo.Value, foo.Value);
        }
        public virtual void TestCustomSerialize()
        {
            var config = new SerializationOptions();

            var sc = new SerializerOptions
            {
                SerializedType = typeof(CustomSerializableType),
                Creator        = () => new CustomSerializer()
            };

            config.Serializers.Add(sc);
            var ss = new SerializationServiceBuilder(new NullLoggerFactory()).SetConfig(config).Build();

            var foo = new CustomSerializableType {
                Value = "fooooo"
            };

            var d      = ss.ToData(foo);
            var newFoo = ss.ToObject <CustomSerializableType>(d);

            Assert.AreEqual(newFoo.Value, foo.Value);
        }
 protected bool Equals(CustomSerializableType other)
 {
     return(string.Equals(Value, other.Value));
 }