Ejemplo n.º 1
0
        public void TestClassDefinitionConfig()
        {
            int portableVersion     = 1;
            var serializationConfig = new SerializationOptions();

            serializationConfig.AddPortableFactory(SerializationTestsConstants.PORTABLE_FACTORY_ID,
                                                   new TestPortableFactory());
            serializationConfig.PortableVersion = portableVersion;
            serializationConfig
            .ClassDefinitions.Add(
                new ClassDefinitionBuilder(SerializationTestsConstants.PORTABLE_FACTORY_ID,
                                           SerializationTestsConstants.RAW_DATA_PORTABLE, portableVersion)
                .AddLongField("l")
                .AddCharArrayField("c")
                .AddPortableField("p", CreateNamedPortableClassDefinition(portableVersion))
                .Build());
            serializationConfig
            .ClassDefinitions.Add(
                new ClassDefinitionBuilder(SerializationTestsConstants.PORTABLE_FACTORY_ID,
                                           SerializationTestsConstants.NAMED_PORTABLE, portableVersion)
                .AddStringField("name").AddIntField("myint").Build());

            var serializationService = new SerializationServiceBuilder(new NullLoggerFactory())
                                       .SetConfig(serializationConfig)
                                       .AddDataSerializableFactory(SerializationTestsConstants.DATA_SERIALIZABLE_FACTORY_ID,
                                                                   GetDataSerializableFactory())
                                       .Build();
            var p = new RawDataPortable(DateTime.Now.ToFileTime(), "test chars".ToCharArray(),
                                        new NamedPortable("named portable", 34567),
                                        9876, "Testing raw portable", new ByteArrayDataSerializable(Encoding.UTF8.GetBytes("test bytes")));

            var data = serializationService.ToData(p);

            Assert.AreEqual(p, serializationService.ToObject <RawDataPortable>(data));
        }
Ejemplo n.º 2
0
        public void TestRawDataWithoutRegistering()
        {
            var serializationService = CreateSerializationService(1, Endianness.BigEndian);
            var p = new RawDataPortable(DateTime.Now.ToFileTime(), "test chars".ToCharArray(),
                                        new NamedPortable("named portable", 34567),
                                        9876, "Testing raw portable", new ByteArrayDataSerializable(Encoding.UTF8.GetBytes("test bytes")));

            var data = serializationService.ToData(p);

            Assert.AreEqual(p, serializationService.ToObject <RawDataPortable>(data));
        }
Ejemplo n.º 3
0
        public void TestRawData()
        {
            int portableVersion      = 1;
            var serializationService = CreateSerializationService(1, Endianness.BigEndian);
            var p = new RawDataPortable(DateTime.Now.ToFileTime(), "test chars".ToCharArray(),
                                        new NamedPortable("named portable", 34567),
                                        9876, "Testing raw portable", new ByteArrayDataSerializable(Encoding.UTF8.GetBytes("test bytes")));
            var builder = new ClassDefinitionBuilder(p.FactoryId, p.ClassId, portableVersion);

            builder.AddLongField("l").AddCharArrayField("c")
            .AddPortableField("p", CreateNamedPortableClassDefinition(portableVersion));
            serializationService.GetPortableContext().RegisterClassDefinition(builder.Build());

            var data = serializationService.ToData(p);

            Assert.AreEqual(p, serializationService.ToObject <RawDataPortable>(data));
        }