Exemple #1
0
        public void TestNullValue_When_ValueType()
        {
            var ss = new SerializationServiceBuilder()
                     .Build();

            var output = ss.CreateObjectDataOutput(1024);

            ss.WriteObject(output, null);

            var input = ss.CreateObjectDataInput(output.ToByteArray());

            ss.ReadObject <int>(input);
        }
        public void TestNullValue_When_ReferenceType()
        {
            var ss = new SerializationServiceBuilder(new NullLoggerFactory())
                     .Build();

            var output = ss.CreateObjectDataOutput(1024);

            ss.WriteObject(output, null);

            var input = ss.CreateObjectDataInput(output.ToByteArray());

            Assert.IsNull(ss.ReadObject <object>(input));
        }
        public void TestNullValue_When_ValueType()
        {
            Assert.Throws <SerializationException>(() =>
            {
                var ss = new SerializationServiceBuilder(new NullLoggerFactory())
                         .Build();

                var output = ss.CreateObjectDataOutput(1024);
                ss.WriteObject(output, null);

                var input = ss.CreateObjectDataInput(output.ToByteArray());
                ss.ReadObject <int>(input);
            });
        }
Exemple #4
0
        public void TestNullValue_When_NullableType()
        {
            var ss = new SerializationServiceBuilder()
                     .Build();

            var output = ss.CreateObjectDataOutput(1024);

            ss.WriteObject(output, 1);
            ss.WriteObject(output, null);

            var input = ss.CreateObjectDataInput(output.ToByteArray());

            Assert.AreEqual(1, ss.ReadObject <int?>(input));
            Assert.IsNull(ss.ReadObject <int?>(input));
        }
        public virtual void TestReadWrite(ByteOrder byteOrder)
        {
            var obj = KitchenSinkDataSerializable.Generate();

            obj.Serializable = KitchenSinkDataSerializable.Generate();

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

            IObjectDataOutput output = ss.CreateObjectDataOutput(1024);

            output.WriteObject(obj);

            IObjectDataInput input = ss.CreateObjectDataInput(output.ToByteArray());
            var readObj            = input.ReadObject <object>();

            Assert.AreEqual(obj, readObj);

            ss.Destroy();
        }
Exemple #6
0
        public virtual void TestDataInputOutputWithPortable(Endianness endianness)
        {
            var portable = KitchenSinkPortable.Generate();

            var config = new SerializationOptions();

            config.AddPortableFactory(KitchenSinkPortableFactory.FactoryId, typeof(KitchenSinkPortableFactory));

            using var ss = new SerializationServiceBuilder(new NullLoggerFactory()).SetConfig(config)
                           .SetEndianness(endianness).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);
        }
Exemple #7
0
        public virtual void TestReadWrite(Endianness endianness)
        {
            var obj = KitchenSinkDataSerializable.Generate();

            obj.Serializable = KitchenSinkDataSerializable.Generate();

            using var ss = new SerializationServiceBuilder(new NullLoggerFactory())
                           .AddDataSerializableFactory(1, new ArrayDataSerializableFactory(new Func <IIdentifiedDataSerializable>[]
            {
                () => new KitchenSinkDataSerializable(),
            }))
                           .SetEndianness(endianness).Build();

            IObjectDataOutput output = ss.CreateObjectDataOutput(1024);

            output.WriteObject(obj);

            IObjectDataInput input = ss.CreateObjectDataInput(output.ToByteArray());
            var readObj            = input.ReadObject <object>();

            Assert.AreEqual(obj, readObj);
        }
Exemple #8
0
        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();
        }