void FillPortableFactories
     (XmlNode node, SerializationConfig serializationConfig)
 {
     foreach (XmlNode child in node.ChildNodes)
     {
         string name = CleanNodeName(child);
         if ("portable-factory".Equals(name))
         {
             string  value         = GetTextContent(child);
             XmlNode factoryIdNode = child.Attributes.GetNamedItem("factory-id");
             if (factoryIdNode == null)
             {
                 throw new ArgumentException("'factory-id' attribute of 'portable-factory' is required!");
             }
             int factoryId = Convert.ToInt32(GetTextContent(factoryIdNode));
             serializationConfig.AddPortableFactoryClass(factoryId, value);
         }
     }
 }
        public virtual void TestInputOutputWithPortableReader(ByteOrder byteOrder)
        {
            var portable = KitchenSinkPortable.Generate();

            var config = new SerializationConfig();
            config.AddPortableFactoryClass(KitchenSinkPortableFactory.FactoryId, typeof (KitchenSinkPortableFactory));

            var ss = new SerializationServiceBuilder().SetConfig(config).
                SetUseNativeByteOrder(false).SetByteOrder(byteOrder).Build();

            var data = ss.ToData(portable);
            var reader = ss.CreatePortableReader(data);

            var actual = new KitchenSinkPortable();
            actual.ReadPortable(reader);

            Assert.AreEqual(portable, actual);

            ss.Destroy();
        }
        public virtual void TestDataInputOutputWithPortable(ByteOrder byteOrder)
        {
            var portable = KitchenSinkPortable.Generate();

            var config = new SerializationConfig();
            config.AddPortableFactoryClass(KitchenSinkPortableFactory.FactoryId, typeof (KitchenSinkPortableFactory));

            var ss = new SerializationServiceBuilder().SetConfig(config).
                SetUseNativeByteOrder(false).SetByteOrder(byteOrder).Build();

            IObjectDataOutput output = ss.CreateObjectDataOutput(1024);
            output.WriteObject(portable);
            var data = output.ToByteArray();

            IObjectDataInput input = ss.CreateObjectDataInput(data);
            var readObject = input.ReadObject<IPortable>();

            Assert.AreEqual(portable, readObject);

            ss.Destroy();
        }
 protected internal virtual void FillPortableFactories(XmlNode node, SerializationConfig serializationConfig)
 {
     foreach (XmlNode child in node.ChildNodes)
     {
         string name = CleanNodeName(child);
         if ("portable-factory".Equals(name))
         {
             string value = GetTextContent(child);
             XmlNode factoryIdNode = child.Attributes.GetNamedItem("factory-id");
             if (factoryIdNode == null)
             {
                 throw new ArgumentException("'factory-id' attribute of 'portable-factory' is required!");
             }
             int factoryId = Convert.ToInt32(GetTextContent(factoryIdNode));
             serializationConfig.AddPortableFactoryClass(factoryId, value);
         }
     }
 }
        public void TestAddPortableFactoryClassWithNoEmptyConstructor()
        {
            var config = new SerializationConfig();
            config.AddPortableFactoryClass(1, typeof(PortableFactory));

            var service = new SerializationServiceBuilder().SetConfig(config).Build();
        }
        public void TestAddPortableFactoryClassWithDuplicateId()
        {
            var config = new SerializationConfig();
            config.AddPortableFactory(1, new KitchenSinkPortableFactory());
            config.AddPortableFactoryClass(1, typeof(KitchenSinkPortableFactory));

            var service = new SerializationServiceBuilder().SetConfig(config).Build();
        }
        public void TestAddPortableFactoryClassWhichDoesNotImplementPortableFactory()
        {
            var config = new SerializationConfig();
            config.AddPortableFactoryClass(1, typeof(SerializableFactory));

            var service = new SerializationServiceBuilder().SetConfig(config).Build();
        }
        public void TestAddPortableFactoryClass()
        {
            var service1 = new SerializationServiceBuilder().Build();
            var data = service1.ToData(new KitchenSinkPortable());

            var config = new SerializationConfig();
            config.AddPortableFactoryClass(1, typeof(KitchenSinkPortableFactory));

            var service = new SerializationServiceBuilder().SetConfig(config).Build();

            var obj = service.ToObject<object>(data);
            Assert.IsInstanceOf<KitchenSinkPortable>(obj);
        }