public void TestPofSerialization()
        {
            ISerializer serializer = new SimplePofContext();

            IDictionary original = InstantiateDictionary();

            original.Add("A", "A");
            original.Add("B", "B");
            original.Add("C", "C");

            var stream = new BinaryMemoryStream();

            serializer.Serialize(new DataWriter(stream), original);
            Binary     bin    = stream.ToBinary();
            IPofReader reader = new PofStreamReader(bin.GetReader(), (IPofContext)serializer);
            Object     copy   = reader.ReadDictionary(-1, InstantiateDictionary());

            Assert.AreEqual(original, copy);
            Assert.AreEqual(original.GetHashCode(), copy.GetHashCode());

            original.Add(null, null);
            stream = new BinaryMemoryStream();
            serializer.Serialize(new DataWriter(stream), original);
            bin    = stream.ToBinary();
            reader = new PofStreamReader(bin.GetReader(), (IPofContext)serializer);
            copy   = reader.ReadDictionary(-1, InstantiateDictionary());

            Assert.AreEqual(original, copy);
            Assert.AreEqual(original.GetHashCode(), copy.GetHashCode());
            Assert.AreEqual(original.ToString(), copy.ToString());
        }
        /// <summary>
        /// Creates a POF context with neccessary test type registrations.
        /// </summary>
        /// <param name="isRefEnabled">
        /// Flag to indicate if object identity/reference is enabled.
        /// </param>
        /// <returns>
        /// A configured test POF context.
        /// </returns>
        public static IPofContext GetPofContext(bool isRefEnabled)
        {
            if (isRefEnabled)
            {
                return(new ConfigurablePofContext("config/reference-pof-config.xml"));
            }
            SimplePofContext ctx = new SimplePofContext();

            ctx.RegisterUserType(3010, typeof(Address), new PortableObjectSerializer(3010));
            ctx.RegisterUserType(101, typeof(PortablePerson), new PortableObjectSerializer(101));
            ctx.RegisterUserType(3011, typeof(BooleanHolder), new PortableObjectSerializer(3011));
            ctx.RegisterUserType(3012, typeof(TestValue), new PortableObjectSerializer(3012));
            return(ctx);
        }
Ejemplo n.º 3
0
        public void UUIDSerializationTest()
        {
            IPAddress        addr = NetworkUtils.GetLocalHostAddress();
            UUID             uuid = new UUID(DateTimeUtils.GetSafeTimeMillis(), addr, 8080, 1);
            SimplePofContext ctx  = new SimplePofContext();

            ctx.RegisterUserType(20, typeof(UUID), new PortableObjectSerializer(20));
            Stream stream = new MemoryStream();

            ctx.Serialize(new DataWriter(stream), uuid);
            stream.Position = 0;
            UUID result = (UUID)ctx.Deserialize(new DataReader(stream));

            Assert.AreEqual(uuid.ToString(), result.ToString());
        }