Exemplo n.º 1
0
        public void We_should_go_through_the_list_quickly()
        {
            DerivedObject obj = new DerivedObject("Chris", "Patterson", "Pimp");
            DerivedObject obj2 = new DerivedObject("Joe", "Blow", "Daddy");

            //IObjectFormatter fomatter = new XmlObjectFormatter();

            MemoryStream mstream = new MemoryStream();

            using(IObjectFormatter formatter = new BEncodeObjectFormatter(mstream))
            using(IObjectSerializer serializer = new BasicObjectSerializer(formatter))
            {
                serializer.Serialize(formatter, obj);
                serializer.Serialize(formatter, obj2);
            }

            Debug.WriteLine("DATA: " + Encoding.UTF8.GetString(mstream.ToArray()));

            MemoryStream mdecode = new MemoryStream(mstream.ToArray());

            using(BDecode decoder = new BDecode(mdecode))
            {
                object newObj = decoder.Read(TimeSpan.FromSeconds(200));

                Assert.That(newObj, Is.Not.Null);
                Assert.That(newObj, Is.TypeOf(typeof(DerivedObject)), "Invalid Type Received");

                object newObj2 = decoder.Read(TimeSpan.FromSeconds(200));

                Assert.That(newObj2, Is.Not.Null);
                Assert.That(newObj2, Is.TypeOf(typeof(DerivedObject)), "Invalid Type Received");

            }
        }
        public void SerializeAndDeserializeSimpleBasicObject()
        {
            BasicObject obj = BasicObject.CreateObject("Name", "Adam", "Age", 800);

            BasicObjectSerializer serializer = new BasicObjectSerializer();
            Stream stream = new MemoryStream();

            serializer.Serialize(obj, stream);
            stream.Seek(0, SeekOrigin.Begin);

            BasicObject clone = serializer.Deserialize(stream);

            Assert.IsNotNull(clone);
            Assert.AreEqual(obj, clone);
        }
        public void SerializeAndDeserializeCompositeObjectObject()
        {
            BasicObject adam = BasicObject.CreateObject("Name", "Adam", "Age", 800);
            BasicObject eve  = BasicObject.CreateObject("Name", "Eve", "Age", 700);
            BasicObject abel = BasicObject.CreateObject("Name", "Abel", "Age", 600, "Father", adam, "Mother", eve);

            BasicObjectSerializer serializer = new BasicObjectSerializer();
            Stream stream = new MemoryStream();

            serializer.Serialize(abel, stream);
            stream.Seek(0, SeekOrigin.Begin);

            BasicObject clone = serializer.Deserialize(stream);

            Assert.IsNotNull(clone);
            Assert.AreEqual(abel, clone);
        }
        public void SerializeAndDeserializeBasicObjectWithDateTime()
        {
            BasicObject obj = new BasicObject();

            obj["Name"] = "Adam";
            obj["Born"] = new DateTime(1, 1, 1);
            obj["Age"]  = 800;

            BasicObjectSerializer serializer = new BasicObjectSerializer();
            Stream stream = new MemoryStream();

            serializer.Serialize(obj, stream);
            stream.Seek(0, SeekOrigin.Begin);

            BasicObject clone = serializer.Deserialize(stream);

            Assert.IsNotNull(clone);
            Assert.AreEqual(obj, clone);
        }