コード例 #1
0
        public void ObjectGraphMsg_Basic()
        {
            ObjectGraphMsg msg;

            msg = new ObjectGraphMsg();
            Assert.IsNull(msg.Graph);
            Assert.AreEqual(Compress.Best, msg.Compress);

            msg = new ObjectGraphMsg(10);
            Assert.AreEqual(10, msg.Graph);
            Assert.AreEqual(Compress.Best, msg.Compress);

            msg = new ObjectGraphMsg("hello world", Compress.Always);
            Assert.AreEqual("hello world", msg.Graph);
            Assert.AreEqual(Compress.Always, msg.Compress);
        }
コード例 #2
0
        public void ObjectGraphMsg_Serialize()
        {
            ObjectGraphMsg       msgOut, msgIn;
            EnhancedMemoryStream ms = new EnhancedMemoryStream();

            Msg.ClearTypes();
            Msg.LoadTypes(Assembly.GetExecutingAssembly());

            msgOut = new ObjectGraphMsg("hello world", Compress.Always);

            Msg.Save(ms, msgOut);
            ms.Seek(0, SeekOrigin.Begin);
            msgIn = (ObjectGraphMsg)Msg.Load(ms);

            Assert.AreEqual("hello world", msgIn.Graph);

            //-----------------------------------

            ms.SetLength(0);

            msgOut = new ObjectGraphMsg(new string[] { "a", "b", "c" }, Compress.Always);

            Msg.Save(ms, msgOut);
            ms.Seek(0, SeekOrigin.Begin);
            msgIn = (ObjectGraphMsg)Msg.Load(ms);

            CollectionAssert.AreEqual(new string[] { "a", "b", "c" }, (string[])msgIn.Graph);

            //-----------------------------------

            ms.SetLength(0);

            msgOut = new ObjectGraphMsg(null, Compress.Always);

            Msg.Save(ms, msgOut);
            ms.Seek(0, SeekOrigin.Begin);
            msgIn = (ObjectGraphMsg)Msg.Load(ms);

            Assert.IsNull(msgIn.Graph);
        }