예제 #1
0
        /// <exception cref="System.IO.IOException" />
        internal static void TestDifferentClassVersionsUsingDataWriteAndRead(ISerializationService serializationService,
                                                                             ISerializationService serializationService2)
        {
            var p1   = new NamedPortable("portable-v1", 111);
            var data = serializationService.ToData(p1);
            // emulate socket write by writing data to stream
            IBufferObjectDataOutput @out = serializationService.CreateObjectDataOutput(1024);

            @out.WriteData(data);
            byte[] bytes = @out.ToByteArray();
            // emulate socket read by reading data from stream
            IBufferObjectDataInput @in = serializationService2.CreateObjectDataInput(bytes);

            data = @in.ReadData();
            // read data
            object object1 = serializationService2.ToObject <object>(data);
            // serialize new portable version
            var p2    = new NamedPortableV2("portable-v2", 123);
            var data2 = serializationService2.ToData(p2);
            // de-serialize back using old version
            object object2 = serializationService.ToObject <object>(data2);

            Assert.IsNotNull(object1, "object1 should not be null!");
            Assert.IsNotNull(object2, "object2 should not be null!");
            Assert.IsInstanceOf <NamedPortableV2>(object1, "Should be instance of NamedPortableV2: " + object1.GetType());
            Assert.IsInstanceOf <NamedPortable>(object2, "Should be instance of NamedPortable: " + object2.GetType());
        }