Esempio n. 1
0
        public void TestEmptyMyListOfEntity()
        {
            var foos  = new MyList();
            var clone = Serializer.DeepClone(foos);

            Assert.IsNotNull(clone);
        }
Esempio n. 2
0
        public void TestEmtpyBasicListOfEntity()
        {
            var foos  = new List <Entity>();
            var clone = Serializer.DeepClone(foos);

            Assert.IsNotNull(clone);
        }
Esempio n. 3
0
        public void TestArrayContents()
        {
            Test3[] arr = new Test3[]
            {
                new Test3 {
                    C = new Test1 {
                        A = 123
                    }
                },
                new Test3 {
                    C = new Test1 {
                        A = 456
                    }
                },
                new Test3 {
                    C = new Test1 {
                        A = 789
                    }
                }
            };

            var clone = Serializer.DeepClone(arr);

            CheckLists(arr, clone);
        }
Esempio n. 4
0
        public void TestListContents()
        {
            List <Test3> list = new List <Test3>
            {
                new Test3 {
                    C = new Test1 {
                        A = 123
                    }
                },
                new Test3 {
                    C = new Test1 {
                        A = 456
                    }
                },
                new Test3 {
                    C = new Test1 {
                        A = 789
                    }
                }
            };

            var clone = Serializer.DeepClone(list);

            CheckLists(list, clone);
        }
Esempio n. 5
0
        public void TestEnumerableContents()
        {
            Test3Enumerable items = new Test3Enumerable
            {
                new Test3 {
                    C = new Test1 {
                        A = 123
                    }
                },
                new Test3 {
                    C = new Test1 {
                        A = 456
                    }
                },
                new Test3 {
                    C = new Test1 {
                        A = 789
                    }
                }
            };

            var clone = Serializer.DeepClone(items);

            CheckLists(items, clone);
        }
Esempio n. 6
0
        public void TestStringArray()
        {
            var foo = new List <string> {
                "abc", "def", "ghi"
            };

            var clone = Serializer.DeepClone(foo);
        }
Esempio n. 7
0
        static void VerifyNodeTree(Node node)
        {
            Node   clone = Serializer.DeepClone(node);
            string msg;
            bool   eq = AreEqual(node, clone, out msg);

            Assert.IsTrue(eq, msg);
        }
Esempio n. 8
0
 public void TestArrayBytes()
 {
     Test3[] list = new Test3[] { new Test3 {
                                      C = new Test1 {
                                          A = 150
                                      }
                                  } };
     Serializer.DeepClone(list);
     // variant?
     //Assert.IsTrue(Program.CheckBytes(list, 0x0A, 0x09, 0x1a, 0x07, 0x10, 0x01, 0x52, 0x03, 0x08, 0x96, 0x01));
 }
Esempio n. 9
0
        public void PackedNullArrayDeserializesAsNull()
        {
            var item = new EntityWithPackedInts();

            Assert.IsNull(item.ItemArray);
            var clone = Serializer.DeepClone(item);

            Assert.IsNull(clone.ItemArray);

            item.ItemArray = null;
            clone          = Serializer.DeepClone(item);
            Assert.IsNull(clone.ItemArray);
        }
Esempio n. 10
0
        public void PackedNullListDeserializesAsNull()
        {
            var item = new EntityWithPackedInts();

            Assert.IsNull(item.ListNoDefault);
            var clone = Serializer.DeepClone(item);

            Assert.IsNull(clone.ListNoDefault);

            item.ListNoDefault = null;
            clone = Serializer.DeepClone(item);
            Assert.IsNull(clone.ListNoDefault);
        }
Esempio n. 11
0
        public void TestUnpackedIntListLayout()
        {
            EntityWithUnpackedInts item = new EntityWithUnpackedInts {
                Items = { 1, 2, 3, 4, 5, 1000 }
            };

            Assert.IsTrue(Program.CheckBytes(item, 08, 01, 08, 02, 08, 03, 08, 04, 08, 05, 08, 0xE8, 07));

            var clone = Serializer.DeepClone(item);

            Assert.AreNotSame(item.Items, clone.Items);
            Assert.IsTrue(item.Items.SequenceEqual(clone.Items));
        }
Esempio n. 12
0
        public void TestEmptyArrays()
        {
            Tst t = new Tst();

            t.ValInt    = 128;
            t.Str1      = "SOme string text value ttt";
            t.ArrayData = new byte[] { };

            MemoryStream stm = new MemoryStream();

            Serializer.Serialize(stm, t);
            Console.WriteLine(stm.Length);
        }
Esempio n. 13
0
        public void TestPackedIntListLayout()
        {
            EntityWithPackedInts item = new EntityWithPackedInts
            {
                List = { 1, 2, 3, 4, 5, 1000 }
            };

            Assert.IsTrue(Program.CheckBytes(item, 0x0A, 07, 01, 02, 03, 04, 05, 0xE8, 07));

            var clone = Serializer.DeepClone(item);

            Assert.AreNotSame(item.List, clone.List);
            Assert.IsTrue(item.List.SequenceEqual(clone.List));
        }
Esempio n. 14
0
        public void TestEnumerableBytes()
        {
            Test3Enumerable list = new Test3Enumerable {
                new Test3 {
                    C = new Test1 {
                        A = 150
                    }
                }
            };

            Serializer.DeepClone(list);
            // Actual: 0A 05 1A 03 08 96 01 why, variant??
            //Assert.IsTrue(Program.CheckBytes(list, 0x0A, 0x09, 0x1a, 0x07, 0x10, 0x01, 0x52, 0x03, 0x08, 0x96, 0x01));
        }
Esempio n. 15
0
        public void TestListBytes()
        {
            List <Test3> list = new List <Test3> {
                new Test3 {
                    C = new Test1 {
                        A = 150
                    }
                }
            };

            Serializer.DeepClone(list);
            // Actual 0A 05 1A 03 08 96 01 - don't know why, variant?
            //Assert.IsTrue(Program.CheckBytes(list, 0x0A, 0x09, 0x1a, 0x07, 0x10, 0x01, 0x52, 0x03, 0x08, 0x96, 0x01));
        }
Esempio n. 16
0
        public void TestPackedIntArrayLayout()
        {
            EntityWithPackedInts item = new EntityWithPackedInts
            {
                ItemArray = new int[] { 1, 2, 3, 4, 5, 1000 }
            };

            item.ClearList();
            Assert.IsTrue(Program.CheckBytes(item, 0x1A, 07, 01, 02, 03, 04, 05, 0xE8, 07));

            var clone = Serializer.DeepClone(item);

            Assert.AreNotSame(item.ItemArray, clone.ItemArray);
            Assert.IsTrue(item.ItemArray.SequenceEqual(clone.ItemArray));
        }
Esempio n. 17
0
        public void JaggedByteArray()
        {
            var data = new[] {
                new byte[] { 0, 1, 2, 3, 4 },
                new byte[] { 5, 6, 7 },
                new byte[] { 8, 9, 10 }
            };
            var clone = Serializer.DeepClone(data);

            Assert.AreNotSame(data, clone);
            Assert.AreEqual(3, clone.Length);
            Assert.IsTrue(data[0].SequenceEqual(clone[0]));
            Assert.IsTrue(data[1].SequenceEqual(clone[1]));
            Assert.IsTrue(data[2].SequenceEqual(clone[2]));
        }
Esempio n. 18
0
        public void TestPrimativeArray()
        {
            var  schema = RuntimeTypeModel.Default.GetDebugSchema(typeof(Prim));
            Prim p      = new Prim {
                Values = new[] { "abc", "def", "ghi", "jkl" }
            },
                 clone = Serializer.DeepClone(p);

            string[] oldArr = p.Values, newArr = clone.Values;
            Assert.AreEqual(oldArr.Length, newArr.Length);
            for (int i = 0; i < oldArr.Length; i++)
            {
                Assert.AreEqual(oldArr[i], newArr[i], "Item " + i.ToString());
            }
        }
Esempio n. 19
0
        public void CheckWrappedLinkedListCanRoundtrip()
        {
            var wrapper = new WithLinkedList();

            wrapper.Items.AddLast(new BasicItem {
                Value = "abc"
            });
            wrapper.Items.AddLast(new BasicItem {
                Value = "def"
            });
            var clone = Serializer.DeepClone(wrapper);

            Assert.AreEqual(2, clone.Items.Count);
            Assert.AreEqual("abc", clone.Items.First.Value.Value);
            Assert.AreEqual("def", clone.Items.Last.Value.Value);
        }
Esempio n. 20
0
        public void TestUnpackedIntCustomLayout()
        {
            EntityWithUnpackedInts item = new EntityWithUnpackedInts
            {
                Custom = new CustomEnumerable {
                    1, 2, 3, 4, 5, 1000
                }
            };

            Assert.IsTrue(Program.CheckBytes(item, 0x20, 01, 0x20, 02, 0x20, 03, 0x20, 04, 0x20, 05, 0x20, 0xE8, 07));

            var clone = Serializer.DeepClone(item);

            Assert.AreNotSame(item.Custom, clone.Custom);
            Assert.IsTrue(item.Custom.SequenceEqual(clone.Custom));
        }
Esempio n. 21
0
        public void CheckNakedLinkedListCanRoundtrip()
        {
            var list = new LinkedList <BasicItem>();

            list.AddLast(new BasicItem {
                Value = "abc"
            });
            list.AddLast(new BasicItem {
                Value = "def"
            });
            var clone = Serializer.DeepClone(list);

            Assert.AreEqual(2, clone.Count);
            Assert.AreEqual("abc", clone.First.Value.Value);
            Assert.AreEqual("def", clone.Last.Value.Value);
        }
Esempio n. 22
0
        public void ListOfByteArray()
        {
            var data = new List <byte[]> {
                new byte[] { 0, 1, 2, 3, 4 },
                new byte[] { 5, 6, 7 },
                new byte[] { 8, 9, 10 },
                new byte[] {}
            };
            var clone = Serializer.DeepClone(data);

            Assert.AreNotSame(data, clone);
            Assert.AreEqual(4, clone.Count);
            Assert.IsTrue(data[0].SequenceEqual(clone[0]));
            Assert.IsTrue(data[1].SequenceEqual(clone[1]));
            Assert.IsTrue(data[2].SequenceEqual(clone[2]));
            Assert.IsTrue(data[3].SequenceEqual(clone[3]));
        }
Esempio n. 23
0
        public void PackedEmptyCustomDeserializesAsEmpty()
        {
            var item = new EntityWithPackedInts();

            Assert.IsNull(item.Custom);
            var clone = Serializer.DeepClone(item);

            Assert.IsNull(clone.Custom);

            item.Custom = new CustomEnumerable();
            clone       = Serializer.DeepClone(item);
            Assert.IsNotNull(clone.Custom);
            Assert.AreEqual(0, clone.Custom.Count());

            item.Custom.Add(123);
            clone = Serializer.DeepClone(item);
            Assert.IsNotNull(clone.Custom);
            Assert.AreEqual(123, item.Custom.Single());
        }
Esempio n. 24
0
        public void PackedEmptyListDeserializesAsEmpty()
        {
            var item = new EntityWithPackedInts();

            Assert.IsNull(item.ListNoDefault);
            EntityWithPackedInts clone;// = Serializer.DeepClone(item);

            //Assert.IsNull(clone.ListNoDefault);

            item.ListNoDefault = new List <int>();
            clone = Serializer.DeepClone(item);
            Assert.IsNotNull(clone.ListNoDefault);
            Assert.AreEqual(0, clone.ListNoDefault.Count);

            item.ListNoDefault.Add(123);
            clone = Serializer.DeepClone(item);
            Assert.IsNotNull(clone.ListNoDefault);
            Assert.AreEqual(1, clone.ListNoDefault.Count);
            Assert.AreEqual(123, clone.ListNoDefault[0]);
        }
Esempio n. 25
0
        public void TestNonEmptyMyListOfEntity()
        {
            var foos = new MyList()
            {
                new Entity {
                    Foo = "abc"
                },
                new Entity {
                    Foo = "def"
                },
            };
            var clone = Serializer.DeepClone(foos);

            Assert.IsNotNull(clone);
            Assert.AreNotSame(foos, clone);
            Assert.AreEqual(foos.GetType(), clone.GetType());
            Assert.AreEqual(2, clone.Count);
            Assert.AreEqual(foos[0].Foo, clone[0].Foo);
            Assert.AreEqual(foos[1].Foo, clone[1].Foo);
        }
Esempio n. 26
0
        public void TestCompositeDictionary()
        {
            DictionaryTestEntity obj = new DictionaryTestEntity
            {
                Foo   = "bar",
                Stuff =
                {
                    { "abc", CompositeType.Create(123)            },
                    { "def", CompositeType.Create(DateTime.Today) },
                    { "ghi", CompositeType.Create("hello world")  },
                }
            }, clone = Serializer.DeepClone(obj);

            Assert.IsNotNull(clone);
            Assert.AreNotSame(clone, obj);
            Assert.AreEqual("bar", clone.Foo);
            Assert.AreEqual(3, clone.Stuff.Count);
            Assert.AreEqual(123, clone.Stuff["abc"].Value);
            Assert.AreEqual(DateTime.Today, clone.Stuff["def"].Value);
            Assert.AreEqual("hello world", clone.Stuff["ghi"].Value);
        }
Esempio n. 27
0
        public void PackedEmptyArrayDeserializesAsEmpty()
        {
            var item = new EntityWithPackedInts();

            Assert.IsNull(item.ItemArray);
            var clone = Serializer.DeepClone(item);

            Assert.IsNull(clone.ItemArray);

            item.ItemArray = new int[0];
            clone          = Serializer.DeepClone(item);
            Assert.IsNotNull(clone.ItemArray);
            Assert.AreEqual(0, clone.ItemArray.Length);

            item.ItemArray = new int[1] {
                123
            };
            clone = Serializer.DeepClone(item);
            Assert.IsNotNull(clone.ItemArray);
            Assert.AreEqual(1, clone.ItemArray.Length);
            Assert.AreEqual(123, clone.ItemArray[0]);
        }
Esempio n. 28
0
 public void TestPackedCustomOfSubMessage()
 {
     Serializer.DeepClone(new CustomOfSubMessage());
 }
Esempio n. 29
0
 public void TestPackedListDateTime()
 {
     Serializer.DeepClone(new ListOfDateTime());
 }
Esempio n. 30
0
 public void TestPackedArrayString()
 {
     Serializer.DeepClone(new ArrayOfString());
 }