示例#1
0
        public void TestInherit()
        {
            var ser = new Regulus.Serialization.Dynamic.Serializer();


            var test = new TestGrandson();

            test.Data = 100;
            var testChild = test as TestChild;

            testChild.Data = 1;
            var testParent = test as TestParent;

            testParent.Data = 33;

            var buf       = ser.ObjectToBuffer(test);
            var val       = (TestGrandson)ser.BufferToObject(buf);
            var valParent = val as TestParent;
            var child     = val as TestChild;


            Assert.AreEqual(100, val.Data);
            Assert.AreEqual(1, child.Data);
            Assert.AreEqual(33, valParent.Data);
        }
示例#2
0
        public void TestSerializerNull()
        {
            var ser = new Regulus.Serialization.Dynamic.Serializer();

            var buf = ser.ObjectToBuffer(null);
            var val = ser.BufferToObject(buf);

            Assert.AreEqual(null, val);
        }
示例#3
0
        public void TestSerializerString()
        {
            var ser = new Regulus.Serialization.Dynamic.Serializer();

            var buf = ser.ObjectToBuffer("12345");
            var val = (string)ser.BufferToObject(buf);

            Assert.AreEqual("12345", val);
        }
示例#4
0
        public void TestSerializerInt()
        {
            var ser = new Regulus.Serialization.Dynamic.Serializer();

            var buf = ser.ObjectToBuffer(12345);
            var val = (int)ser.BufferToObject(buf);

            Assert.AreEqual(12345, val);
        }
示例#5
0
        public void TestSerializerStringArray()
        {
            var ser = new Regulus.Serialization.Dynamic.Serializer();

            var buf = ser.ObjectToBuffer(new[] { "1", "2", "3", "4", "5" });
            var val = (string[])ser.BufferToObject(buf);

            Assert.AreEqual("1", val[0]);
            Assert.AreEqual("2", val[1]);
            Assert.AreEqual("3", val[2]);
            Assert.AreEqual("4", val[3]);
            Assert.AreEqual("5", val[4]);
        }
示例#6
0
        public void TestSerializerArray()
        {
            var ser = new Regulus.Serialization.Dynamic.Serializer();

            var buf = ser.ObjectToBuffer(new[] { 1, 2, 3, 4, 5 });
            var val = (int[])ser.BufferToObject(buf);

            Assert.AreEqual(1, val[0]);
            Assert.AreEqual(2, val[1]);
            Assert.AreEqual(3, val[2]);
            Assert.AreEqual(4, val[3]);
            Assert.AreEqual(5, val[4]);
        }
示例#7
0
        public void TestClassPolytype1()
        {
            var g = new TestGrandson();

            g.Data = 100;
            var test = new TestPoly();

            test.Parent = g;



            var serializer =
                new Regulus.Serialization.Dynamic.Serializer(new CustomFinder((name) => Type.GetType(name)));
            var buf      = serializer.ObjectToBuffer(test);
            var val      = (TestPoly)serializer.BufferToObject(buf);
            var valChild = val.Parent as TestGrandson;

            Assert.AreEqual(100, valChild.Data);
        }
示例#8
0
        public void TestArray1()
        {
            var test = new TestGrandson();

            test.Data = 100;
            var testChild = test as TestChild;

            testChild.Data = 1;
            var testParent = test as TestParent;

            testParent.Data = 33;

            var serializer =
                new Regulus.Serialization.Dynamic.Serializer(new CustomFinder((name) => Type.GetType(name)));
            var buf = serializer.ObjectToBuffer(new TestParent[] { test, testChild, testParent });
            var val = (TestParent[])serializer.BufferToObject(buf);

            Assert.AreEqual(100, (val[0] as TestGrandson).Data);
            Assert.AreEqual(1, (val[1] as TestChild).Data);
            Assert.AreEqual(33, (val[2] as TestParent).Data);
        }