示例#1
0
        public void DataContractObjectTest()
        {
            var dco = new DataContractObject();

            Assert.IsNull(dco.Data);
            Assert.IsNull(dco.Tag);
        }
        public void DataContractSerializeTest()
        {
            IActor             actor        = new BaseActor();
            const string       someData     = "TestData";
            DataContractObject serialObject = new DataContractObject(someData, actor.Tag);

            Assert.AreEqual("TestData", serialObject.Data);
            Assert.AreEqual(actor.Tag, serialObject.Tag);

            DataContractSerializeService service = new DataContractSerializeService();

            using (MemoryStream serializeStream = new MemoryStream())
            {
                service.Serialize(serialObject.Data, serialObject.Tag, serializeStream);
                serializeStream.Seek(0, SeekOrigin.Begin); // rewind

                using (MemoryStream deserializeStream = new MemoryStream())
                {
                    serializeStream.CopyTo(deserializeStream);
                    deserializeStream.Seek(0, SeekOrigin.Begin);
                    DataContractObject returnObject = service.Deserialize(deserializeStream) as DataContractObject;
                    Assert.IsNotNull(returnObject);
                    Assert.IsNotNull(returnObject.Data);
                    Assert.IsNotNull(returnObject.Tag);
                    Assert.AreEqual("TestData", returnObject.Data);
                    Assert.AreEqual(actor.Tag, returnObject.Tag);
                }
            }
        }
示例#3
0
        public void DataContractObjectTestWithData()
        {
            string   someData = "someData";
            ActorTag tag      = new ActorTag();
            var      dco      = new DataContractObject(someData, tag);

            Assert.AreEqual(someData, dco.Data);
            Assert.AreEqual(tag, dco.Tag);
        }