示例#1
0
        public void SerializePackedDeserializeUnpacked()
        {
            EntityWithPackedInts item = new EntityWithPackedInts
            {
                List = { 1, 2, 3, 4, 5, 1000 }
            };
            EntityWithUnpackedInts clone = Serializer.ChangeType <EntityWithPackedInts, EntityWithUnpackedInts>(item);

            Assert.NotSame(item.List, clone.Items);
            Assert.True(item.List.SequenceEqual(clone.Items));
        }
示例#2
0
        public void SerializeUnpackedSerializePacked()
        {
            EntityWithUnpackedInts item = new EntityWithUnpackedInts
            {
                Items = { 1, 2, 3, 4, 5, 1000 }
            };
            EntityWithPackedInts clone = Serializer.ChangeType <EntityWithUnpackedInts, EntityWithPackedInts>(item);

            Assert.AreNotSame(item.Items, clone.List);
            Assert.IsTrue(item.Items.SequenceEqual(clone.List));
        }
示例#3
0
        public void SerializeUnpackedSerializePacked()
        {
            EntityWithUnpackedInts item = new EntityWithUnpackedInts
            {
                Items = { 1, 2, 3, 4, 5, 1000 }
            };
            var tm = TypeModel.Create(false, ProtoCompatibilitySettingsValue.FullCompatibility);
            EntityWithPackedInts clone = tm.ChangeType <EntityWithUnpackedInts, EntityWithPackedInts>(item);

            Assert.AreNotSame(item.Items, clone.List);
            Assert.IsTrue(item.Items.SequenceEqual(clone.List));
        }
示例#4
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);
        }
示例#5
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);
        }
示例#6
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));
        }
示例#7
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));
        }
示例#8
0
        public void TestPackedIntCustomLayout()
        {
            EntityWithPackedInts item = new EntityWithPackedInts
            {
                Custom = new CustomEnumerable {
                    1, 2, 3, 4, 5, 1000
                }
            };

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

            var clone = Serializer.DeepClone(item);

            Assert.AreNotSame(item.Custom, clone.Custom);
            Assert.IsTrue(item.Custom.SequenceEqual(clone.Custom));
        }
示例#9
0
        public void TestPackedIntCustomLayout()
        {
            EntityWithPackedInts item = new EntityWithPackedInts
            {
                Custom = new CustomEnumerable {
                    1, 2, 3, 4, 5, 1000
                }
            };

            item.ClearList();
            RuntimeTypeModel.Default.Add <CustomEnumerable>();
            Program.CheckBytes(item, "22-07-01-02-03-04-05-E8-07");

            var clone = Serializer.DeepClone(item);

            Assert.NotSame(item.Custom, clone.Custom);
            Assert.True(item.Custom.SequenceEqual(clone.Custom));
        }
示例#10
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());
        }
示例#11
0
        public void PackedEmptyListDeserializesAsEmpty()
        {
            var item = new EntityWithPackedInts();

            Assert.IsNull(item.ListNoDefault);
            var 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]);
        }
示例#12
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]);
        }