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)); }
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)); }
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)); }
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); }
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); }
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)); }
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)); }
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)); }
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)); }
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()); }
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]); }
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]); }