Esempio n. 1
0
 public void InheritanceSub1()
 {
     SomeBase sb = new Sub1 { Test = 12345, Foo = "abc" };
     SomeBase clone = Serializer.DeepClone<SomeBase>(sb);
     Assert.IsInstanceOfType(typeof(Sub1), clone, "Type");
     Assert.AreEqual(sb.Test, clone.Test, "Value");
     Assert.AreEqual(((Sub1)sb).Foo, ((Sub1)clone).Foo, "Foo");
 }
        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");
        }
Esempio n. 3
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.IsTrue(Program.CheckBytes(sb, raw), "raw bytes");
            SomeBase clone = Program.Build<SomeBase>(raw);
            Assert.IsInstanceOfType(typeof(Sub1), clone);
            Assert.AreEqual(sb.Test, clone.Test);
            Assert.AreEqual(((Sub1)sb).Foo, ((Sub1)clone).Foo);
        }
        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);
        }