コード例 #1
0
ファイル: Inheritance.cs プロジェクト: Erguotou/protobuf-net
 public void InheritanceBaseType()
 {
     SomeBase sb = new SomeBase {Test = 12345};
     SomeBase clone = Serializer.DeepClone<SomeBase>(sb);
     Assert.IsInstanceOfType(typeof(SomeBase), clone, "Type");
     Assert.AreEqual(sb.Test, clone.Test, "Value");
 }
コード例 #2
0
ファイル: Inheritance.cs プロジェクト: izacus/dynabomber
        public void InheritanceCheckBytesWrongOrder()
        {
            byte[]   raw   = { 0x50, 0xB9, 0x60, 0x12, 0x05, 0x5A, 0x03, 0x61, 0x62, 0x63 };
            SomeBase clone = Program.Build <SomeBase>(raw);

            Assert.IsInstanceOfType(typeof(Sub1), clone);
            Assert.AreEqual(12345, clone.Test);
            Assert.AreEqual("abc", ((Sub1)clone).Foo);
        }
コード例 #3
0
        public void InheritanceBaseType()
        {
            SomeBase sb = new SomeBase {
                Test = 12345
            };
            SomeBase clone = Serializer.DeepClone <SomeBase>(sb);

            Assert.IsType(typeof(SomeBase), clone); //, "Type");
            Assert.Equal(sb.Test, clone.Test);      //, "Value");
        }
コード例 #4
0
        public void InheritanceSub2()
        {
            SomeBase sb = new Sub2 {
                Test = 12345, Bar = 123.45F
            };
            SomeBase clone = Serializer.DeepClone <SomeBase>(sb);

            Assert.IsType(typeof(Sub2), clone);              //, "Type");
            Assert.Equal(sb.Test, clone.Test);               //, "Value");
            Assert.Equal(((Sub2)sb).Bar, ((Sub2)clone).Bar); //, "Foo");
        }
コード例 #5
0
        public void InheritanceSub1()
        {
            SomeBase sb = new Sub1 {
                Test = 12345, Foo = "abc"
            };
            SomeBase clone = Serializer.DeepClone <SomeBase>(sb);

            Assert.IsType(typeof(Sub1), clone);              //, "Type");
            Assert.Equal(sb.Test, clone.Test);               //, "Value");
            Assert.Equal(((Sub1)sb).Foo, ((Sub1)clone).Foo); //, "Foo");
        }
コード例 #6
0
        public void InheritanceCheckBytesWrongOrder()
        {   // breaking change: not supported in v2; frankly, this is moot - the entire
            // inheritance chain is protobuf-net specific, and that always writes data in
            // the same order; the only edge case is message concatenation.
            // note sure this is a realistic concern
            byte[]   raw   = { 0x50, 0xB9, 0x60, 0x12, 0x05, 0x5A, 0x03, 0x61, 0x62, 0x63 };
            SomeBase clone = Program.Build <SomeBase>(raw);

            Assert.IsType(typeof(Sub1), clone);
            Assert.Equal(12345, clone.Test);
            Assert.Equal("abc", ((Sub1)clone).Foo);
        }
コード例 #7
0
        public void InheritanceCheckBytesCorrectOrder()
        {
            // the purpose of this test is to validate the byte stream so that when
            // we turn around the order we know what we are expecting
            SomeBase sb = new Sub1 {
                Test = 12345, Foo = "abc"
            };

            byte[] raw = { 0x12, 0x05, 0x5A, 0x03, 0x61, 0x62, 0x63, 0x50, 0xB9, 0x60 };
            // 0x12 = 10 010 = field 2, string (Sub1)
            // 0x05 = 5 bytes
            // 0x5A = 1011 010 = field 11, string (Foo)
            // 0x03 = 3 bytes
            // 0x61 0x62 0x63 = "abc"
            // 0x50 = 1010 000 = field 10, variant (Test)
            // 0xB9 0x60 = [0]1100000[1]0111001 = 12345

            Assert.True(Program.CheckBytes(sb, raw), "raw bytes");
            SomeBase clone = Program.Build <SomeBase>(raw);

            Assert.IsType(typeof(Sub1), clone);
            Assert.Equal(sb.Test, clone.Test);
            Assert.Equal(((Sub1)sb).Foo, ((Sub1)clone).Foo);
        }