public static void Test_Can_Serialize_Then_Deserialize_Backwards_Included_Type() { //arrange TestBaseType typeToTest = new TestChildTypeWithInclude(5068); ProtobufnetRegistry registry = new ProtobufnetRegistry(); //act registry.Register(typeof(TestBaseType)); registry.Register(typeof(TestChildTypeWithInclude2)); registry.Register(typeof(TestChildTypeWithInclude)); registry.Register(typeof(TestChildType)); //Serialize it MemoryStream ms = new MemoryStream(); ProtoBuf.Serializer.Serialize(ms, typeToTest); ms.Position = 0; //need to reset the stream TestChildTypeWithInclude deserializedType = ProtoBuf.Serializer.Deserialize <TestBaseType>(ms) as TestChildTypeWithInclude; //assert Assert.NotNull(deserializedType); Assert.AreEqual(deserializedType.GetType(), typeToTest.GetType()); Assert.AreEqual(((TestChildTypeWithInclude)typeToTest).IntField2, deserializedType.IntField2); }
public static void Test_Can_Serialize_Then_Deserialize_Backwards_Included_Type() { //arrange TestBaseType typeToTest = new TestChildTypeWithInclude(5068); ProtobufnetRegistry registry = new ProtobufnetRegistry(); //act registry.Register(typeof(TestBaseType)); registry.Register(typeof(TestChildTypeWithInclude2)); registry.Register(typeof(TestChildTypeWithInclude)); registry.Register(typeof(TestChildType)); //Serialize it MemoryStream ms = new MemoryStream(); ProtoBuf.Serializer.Serialize(ms, typeToTest); ms.Position = 0; //need to reset the stream TestChildTypeWithInclude deserializedType = ProtoBuf.Serializer.Deserialize<TestBaseType>(ms) as TestChildTypeWithInclude; //assert Assert.NotNull(deserializedType); Assert.AreEqual(deserializedType.GetType(), typeToTest.GetType()); Assert.AreEqual(((TestChildTypeWithInclude)typeToTest).IntField2, deserializedType.IntField2); }