public void Test_Can_Serialize_Payloads_With_Collections() { ProtobufnetSerializerStrategy serializer = new ProtobufnetSerializerStrategy(); ProtobufnetDeserializerStrategy deserializer = new ProtobufnetDeserializerStrategy(); ProtobufnetRegistry registry = new ProtobufnetRegistry(); registry.Register(typeof(NetworkMessage)); registry.Register(typeof(ResponseMessage)); registry.Register(typeof(GameServerListResponsePayload)); GameServerListResponsePayload payload = new GameServerListResponsePayload(GameServerListResponseCode.Success, new List <SimpleGameServerDetailsModel>(8) { new SimpleGameServerDetailsModel("Hello", IPAddress.Any, 5, ServerRegion.EU) }); ResponseMessage rMessage = new ResponseMessage(payload); rMessage.Payload.Serialize(serializer); ResponseMessage rMessageDeserializer = deserializer.Deserialize <NetworkMessage>(serializer.Serialize(rMessage as NetworkMessage)) as ResponseMessage; rMessageDeserializer.Payload.Deserialize(deserializer); GameServerListResponsePayload dPayload = rMessageDeserializer.Payload.Data as GameServerListResponsePayload; Assert.AreEqual(1, dPayload.GameServerDetails.Count()); Assert.AreEqual("Hello", dPayload.GameServerDetails.FirstOrDefault().Name); }
public void Test_Can_Serialize_Collections_With_Multiple_Inheritance_Type() { ProtobufnetSerializerStrategy serializer = new ProtobufnetSerializerStrategy(); ProtobufnetDeserializerStrategy deserializer = new ProtobufnetDeserializerStrategy(); ProtobufnetRegistry registry = new ProtobufnetRegistry(); registry.Register(typeof(TestClassBase)); registry.Register(typeof(TestClassChild1)); registry.Register(typeof(TestClassChild2)); TestClassBase testObject = new TestClassChild2() { i = 5, j = 6, k = new int[] { 1, 2, 3, 4 } }; TestClassChild2 child = deserializer.Deserialize <TestClassBase>(serializer.Serialize(testObject)) as TestClassChild2; Assert.AreEqual(5, child.i); Assert.AreEqual(6, child.j); Assert.AreEqual(4, child.k.Count()); for (int i = 0; i < child.k.Count(); i++) { Assert.AreEqual(i + 1, child.k[i]); } }
public static void Test_Serialized_Stack_Results_In_Same_Order() { ProtobufnetRegistry registry = new ProtobufnetRegistry(); registry.Register(typeof(NetworkMessage)); registry.Register(typeof(RequestMessage)); registry.Register(typeof(EventMessage)); registry.Register(typeof(ResponseMessage)); RequestMessage message = new RequestMessage(new StatusChangePayload(Common.NetStatus.Connected)); message.Push(1); message.Push(2); message.Push(3); message.Push(4); ProtobufnetSerializerStrategy serializer = new ProtobufnetSerializerStrategy(); Assert.NotNull((new ProtobufnetDeserializerStrategy()).Deserialize<RequestMessage>(serializer.Serialize(message as NetworkMessage))); RequestMessage deserializedMessage = (new ProtobufnetDeserializerStrategy()).Deserialize<RequestMessage>(serializer.Serialize(message as NetworkMessage)); //check that the stack is in the same order Assert.AreEqual(message.Pop(), deserializedMessage.Pop()); Assert.AreEqual(message.Pop(), deserializedMessage.Pop()); Assert.AreEqual(message.Pop(), deserializedMessage.Pop()); Assert.AreEqual(message.Pop(), deserializedMessage.Pop()); }
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_Serialized_Stack_Results_In_Same_Order() { ProtobufnetRegistry registry = new ProtobufnetRegistry(); registry.Register(typeof(NetworkMessage)); registry.Register(typeof(RequestMessage)); registry.Register(typeof(EventMessage)); registry.Register(typeof(ResponseMessage)); RequestMessage message = new RequestMessage(new StatusChangePayload(Common.NetStatus.Connected)); message.Push(1); message.Push(2); message.Push(3); message.Push(4); ProtobufnetSerializerStrategy serializer = new ProtobufnetSerializerStrategy(); Assert.NotNull((new ProtobufnetDeserializerStrategy()).Deserialize <RequestMessage>(serializer.Serialize(message as NetworkMessage))); RequestMessage deserializedMessage = (new ProtobufnetDeserializerStrategy()).Deserialize <RequestMessage>(serializer.Serialize(message as NetworkMessage)); //check that the stack is in the same order Assert.AreEqual(message.Pop(), deserializedMessage.Pop()); Assert.AreEqual(message.Pop(), deserializedMessage.Pop()); Assert.AreEqual(message.Pop(), deserializedMessage.Pop()); Assert.AreEqual(message.Pop(), deserializedMessage.Pop()); }
public static void Test_Can_Register_Type_Will_Not_Fail_If_Try_To_Reregister() { //arrange ProtobufnetRegistry registry = new ProtobufnetRegistry(); //assert Assert.IsTrue(registry.Register(typeof(TestEmptyClass))); Assert.IsTrue(registry.Register(typeof(TestEmptyClass))); }
public static void Test_Can_Register_Type_Will_Not_Fail_If_Try_To_Reregister() { //arrange ProtobufnetRegistry registry = new ProtobufnetRegistry(); //assert Assert.IsTrue(registry.Register(typeof(TestEmptyClass))); Assert.IsTrue(registry.Register(typeof(TestEmptyClass))); }
public static void Test_Can_Register_Marked_Types() { //arrange ProtobufnetRegistry registry = new ProtobufnetRegistry(); //assert Assert.IsTrue(registry.Register(typeof(TestEmptyClass))); Assert.IsTrue(registry.Register(typeof(TestWithMember))); Assert.IsTrue(registry.Register(typeof(TestWithNestedSerializableType))); }
public static void Test_Can_Register_Marked_Types() { //arrange ProtobufnetRegistry registry = new ProtobufnetRegistry(); //assert Assert.IsTrue(registry.Register(typeof(TestEmptyClass))); Assert.IsTrue(registry.Register(typeof(TestWithMember))); Assert.IsTrue(registry.Register(typeof(TestWithNestedSerializableType))); }
public static void Test_Probuf_Serializes_Message_And_Serializes_Message_With_Payload() { ProtobufnetRegistry registry = new ProtobufnetRegistry(); registry.Register(typeof(NetworkMessage)); registry.Register(typeof(RequestMessage)); registry.Register(typeof(RequestMessage)); registry.Register(typeof(EventMessage)); registry.Register(typeof(ResponseMessage)); registry.Register(typeof(StatusMessage)); registry.Register(typeof(NetSendable <>)); registry.Register(typeof(NetSendable <PacketPayload>)); registry.Register(typeof(TestPayload)); RequestMessage message = new RequestMessage(new TestPayload()); message.Payload.Serialize(new ProtobufnetSerializerStrategy()); message.Payload.Deserialize(new ProtobufnetDeserializerStrategy()); Assert.NotNull(message.Payload.Data); message.Payload.Serialize(new ProtobufnetSerializerStrategy()); message.Push(1); message.Pop(); ProtobufnetSerializerStrategy serializer = new ProtobufnetSerializerStrategy(); Assert.NotNull((new ProtobufnetDeserializerStrategy()).Deserialize <NetworkMessage>(serializer.Serialize(message as NetworkMessage)).Payload); }
public static void Test_Probuf_Serializes_Message_And_Serializes_Message_With_Payload() { ProtobufnetRegistry registry = new ProtobufnetRegistry(); registry.Register(typeof(NetworkMessage)); registry.Register(typeof(RequestMessage)); registry.Register(typeof(RequestMessage)); registry.Register(typeof(EventMessage)); registry.Register(typeof(ResponseMessage)); registry.Register(typeof(StatusMessage)); registry.Register(typeof(NetSendable<>)); registry.Register(typeof(NetSendable<PacketPayload>)); registry.Register(typeof(TestPayload)); RequestMessage message = new RequestMessage(new TestPayload()); message.Payload.Serialize(new ProtobufnetSerializerStrategy()); message.Payload.Deserialize(new ProtobufnetDeserializerStrategy()); Assert.NotNull(message.Payload.Data); message.Payload.Serialize(new ProtobufnetSerializerStrategy()); message.Push(1); message.Pop(); ProtobufnetSerializerStrategy serializer = new ProtobufnetSerializerStrategy(); Assert.NotNull((new ProtobufnetDeserializerStrategy()).Deserialize<NetworkMessage>(serializer.Serialize(message as NetworkMessage)).Payload); }
public static void Test_Can_Serialize_MessageType() { ProtobufnetRegistry registry = new ProtobufnetRegistry(); registry.Register(typeof(NetworkMessage)); registry.Register(typeof(RequestMessage)); RequestMessage message = new RequestMessage(Mock.Of <PacketPayload>()); ProtobufnetSerializerStrategy serializer = new ProtobufnetSerializerStrategy(); Assert.NotNull(serializer.Serialize(message)); }
public static void Test_Can_Serialize_MessageType() { ProtobufnetRegistry registry = new ProtobufnetRegistry(); registry.Register(typeof(NetworkMessage)); registry.Register(typeof(RequestMessage)); RequestMessage message = new RequestMessage(Mock.Of<PacketPayload>()); ProtobufnetSerializerStrategy serializer = new ProtobufnetSerializerStrategy(); Assert.NotNull(serializer.Serialize(message)); }
public static void Test_Can_Deserialize_MessageType() { ProtobufnetRegistry registry = new ProtobufnetRegistry(); registry.Register(typeof(NetworkMessage)); registry.Register(typeof(RequestMessage)); registry.Register(typeof(EventMessage)); registry.Register(typeof(ResponseMessage)); RequestMessage message = new RequestMessage(new StatusChangePayload(Common.NetStatus.Connected)); ProtobufnetSerializerStrategy serializer = new ProtobufnetSerializerStrategy(); Assert.NotNull((new ProtobufnetDeserializerStrategy()).Deserialize <RequestMessage>(serializer.Serialize(message as NetworkMessage))); }
public static void Test_Can_Serialize_Then_Deserialize_Registered_Type() { //arrange TestWithNestedSerializableType typeToTest = new TestWithNestedSerializableType(); typeToTest.IntField = 5; typeToTest.SomeClassField = new TestWithNestedSerializableType.SomeClass() { SomeField = 8 }; ProtobufnetRegistry registry = new ProtobufnetRegistry(); typeToTest.ShouldntSerialize = 50643; //act registry.Register(typeof(TestWithNestedSerializableType)); //Serialize it MemoryStream ms = new MemoryStream(); ProtoBuf.Serializer.Serialize(ms, typeToTest); ms.Position = 0; //need to reset the stream TestWithNestedSerializableType deserializedType = ProtoBuf.Serializer.Deserialize <TestWithNestedSerializableType>(ms); //assert Assert.NotNull(deserializedType); Assert.AreEqual(typeToTest.IntField, deserializedType.IntField); Assert.NotNull(deserializedType.SomeClassField); Assert.AreEqual(typeToTest.SomeClassField.SomeField, deserializedType.SomeClassField.SomeField); Assert.AreNotEqual(typeToTest.ShouldntSerialize, deserializedType.ShouldntSerialize); }
public static void Test_Can_Register_Type_With_Includes() { //arrange ProtobufnetRegistry registry = new ProtobufnetRegistry(); Assert.IsTrue(registry.Register(typeof(TestBaseType))); }
public static void Test_Can_Deserialize_MessageType() { ProtobufnetRegistry registry = new ProtobufnetRegistry(); registry.Register(typeof(NetworkMessage)); registry.Register(typeof(RequestMessage)); registry.Register(typeof(EventMessage)); registry.Register(typeof(ResponseMessage)); RequestMessage message = new RequestMessage(new StatusChangePayload(Common.NetStatus.Connected)); ProtobufnetSerializerStrategy serializer = new ProtobufnetSerializerStrategy(); Assert.NotNull((new ProtobufnetDeserializerStrategy()).Deserialize<RequestMessage>(serializer.Serialize(message as NetworkMessage))); }
public static void Test_Register_Throws_On_Null_Type() { //arrange ProtobufnetRegistry registry = new ProtobufnetRegistry(); //assert Assert.Throws<ArgumentNullException>(() => registry.Register(null)); }
public static void Test_Doesnt_Fail_On_Circular_Graph() { //arrange ProtobufnetRegistry registry = new ProtobufnetRegistry(); //assert Assert.DoesNotThrow(() => registry.Register(typeof(TestCircularGraph))); }
public static void Test_Expected_Preregistered_Types_Indicate_They_Arent_Registered_And_Return_False(Type t) { //arrange ProtobufnetRegistry registry = new ProtobufnetRegistry(); //assert Assert.False(registry.Register(t)); }
public static void Test_Doesnt_Fail_On_Circular_Graph() { //arrange ProtobufnetRegistry registry = new ProtobufnetRegistry(); //assert Assert.DoesNotThrow(() => registry.Register(typeof(TestCircularGraph))); }
public static void Test_Register_Throws_On_Null_Type() { //arrange ProtobufnetRegistry registry = new ProtobufnetRegistry(); //assert Assert.Throws <ArgumentNullException>(() => registry.Register(null)); }
public static void Test_Expected_Preregistered_Types_Indicate_They_Arent_Registered_And_Return_False(Type t) { //arrange ProtobufnetRegistry registry = new ProtobufnetRegistry(); //assert Assert.False(registry.Register(t)); }
public static void Test_Serialized_Stack_Empty_Results_In_Not_Throw() { ProtobufnetRegistry registry = new ProtobufnetRegistry(); registry.Register(typeof(NetworkMessage)); registry.Register(typeof(RequestMessage)); registry.Register(typeof(EventMessage)); registry.Register(typeof(ResponseMessage)); RequestMessage message = new RequestMessage(new StatusChangePayload(Common.NetStatus.Connected)); message.Push(1); message.Pop(); ProtobufnetSerializerStrategy serializer = new ProtobufnetSerializerStrategy(); Assert.DoesNotThrow(() => (new ProtobufnetDeserializerStrategy()).Deserialize<RequestMessage>(serializer.Serialize(message as NetworkMessage))); }
public static void Test_Can_Register_Backwards_Include_Type() { //arrange ProtobufnetRegistry registry = new ProtobufnetRegistry(); //TestChildTypeWithInclude value = new TestChildTypeWithInclude() { IntField = 5 }; //assert Assert.IsTrue(registry.Register(typeof(TestChildTypeWithInclude))); }
public static void Test_Serialized_Stack_Empty_Results_In_Not_Throw() { ProtobufnetRegistry registry = new ProtobufnetRegistry(); registry.Register(typeof(NetworkMessage)); registry.Register(typeof(RequestMessage)); registry.Register(typeof(EventMessage)); registry.Register(typeof(ResponseMessage)); RequestMessage message = new RequestMessage(new StatusChangePayload(Common.NetStatus.Connected)); message.Push(1); message.Pop(); ProtobufnetSerializerStrategy serializer = new ProtobufnetSerializerStrategy(); Assert.DoesNotThrow(() => (new ProtobufnetDeserializerStrategy()).Deserialize <RequestMessage>(serializer.Serialize(message as NetworkMessage))); }
public static void Test_Protobufnet_Can_Serialize_NetSendablePackPayload() { ProtobufnetRegistry registry = new ProtobufnetRegistry(); registry.Register(typeof(TestSerialization)); TestSerialization netsendable = new TestSerialization(new TestPayload()); ProtobufnetSerializerStrategy serializer = new ProtobufnetSerializerStrategy(); Assert.NotNull((new ProtobufnetDeserializerStrategy()).Deserialize<TestSerialization>(serializer.Serialize(netsendable))); }
public static void Test_Protobufnet_Can_Serialize_NetSendablePackPayload() { ProtobufnetRegistry registry = new ProtobufnetRegistry(); registry.Register(typeof(TestSerialization)); TestSerialization netsendable = new TestSerialization(new TestPayload()); ProtobufnetSerializerStrategy serializer = new ProtobufnetSerializerStrategy(); Assert.NotNull((new ProtobufnetDeserializerStrategy()).Deserialize <TestSerialization>(serializer.Serialize(netsendable))); }
public void Test_Can_Serialize_Collections_With_Multiple_Inheritance_Type() { ProtobufnetSerializerStrategy serializer = new ProtobufnetSerializerStrategy(); ProtobufnetDeserializerStrategy deserializer = new ProtobufnetDeserializerStrategy(); ProtobufnetRegistry registry = new ProtobufnetRegistry(); registry.Register(typeof(TestClassBase)); registry.Register(typeof(TestClassChild1)); registry.Register(typeof(TestClassChild2)); TestClassBase testObject = new TestClassChild2() { i = 5, j = 6, k = new int[] { 1, 2, 3, 4 } }; TestClassChild2 child = deserializer.Deserialize<TestClassBase>(serializer.Serialize(testObject)) as TestClassChild2; Assert.AreEqual(5, child.i); Assert.AreEqual(6, child.j); Assert.AreEqual(4, child.k.Count()); for (int i = 0; i < child.k.Count(); i++) Assert.AreEqual(i + 1, child.k[i]); }
public void Test_Can_Serialize_Payloads_With_Collections() { ProtobufnetSerializerStrategy serializer = new ProtobufnetSerializerStrategy(); ProtobufnetDeserializerStrategy deserializer = new ProtobufnetDeserializerStrategy(); ProtobufnetRegistry registry = new ProtobufnetRegistry(); registry.Register(typeof(NetworkMessage)); registry.Register(typeof(ResponseMessage)); registry.Register(typeof(GameServerListResponsePayload)); GameServerListResponsePayload payload = new GameServerListResponsePayload(GameServerListResponseCode.Success, new List<SimpleGameServerDetailsModel>(8) { new SimpleGameServerDetailsModel("Hello", IPAddress.Any, 5, ServerRegion.EU) }); ResponseMessage rMessage = new ResponseMessage(payload); rMessage.Payload.Serialize(serializer); ResponseMessage rMessageDeserializer = deserializer.Deserialize<NetworkMessage>(serializer.Serialize(rMessage as NetworkMessage)) as ResponseMessage; rMessageDeserializer.Payload.Deserialize(deserializer); GameServerListResponsePayload dPayload = rMessageDeserializer.Payload.Data as GameServerListResponsePayload; Assert.AreEqual(1, dPayload.GameServerDetails.Count()); Assert.AreEqual("Hello", dPayload.GameServerDetails.FirstOrDefault().Name); }
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_Registered_Type() { //arrange TestWithNestedSerializableType typeToTest = new TestWithNestedSerializableType(); typeToTest.IntField = 5; typeToTest.SomeClassField = new TestWithNestedSerializableType.SomeClass() { SomeField = 8 }; ProtobufnetRegistry registry = new ProtobufnetRegistry(); typeToTest.ShouldntSerialize = 50643; //act registry.Register(typeof(TestWithNestedSerializableType)); //Serialize it MemoryStream ms = new MemoryStream(); ProtoBuf.Serializer.Serialize(ms, typeToTest); ms.Position = 0; //need to reset the stream TestWithNestedSerializableType deserializedType = ProtoBuf.Serializer.Deserialize<TestWithNestedSerializableType>(ms); //assert Assert.NotNull(deserializedType); Assert.AreEqual(typeToTest.IntField, deserializedType.IntField); Assert.NotNull(deserializedType.SomeClassField); Assert.AreEqual(typeToTest.SomeClassField.SomeField, deserializedType.SomeClassField.SomeField); Assert.AreNotEqual(typeToTest.ShouldntSerialize, deserializedType.ShouldntSerialize); }
public static void Test_Can_Register_Type_With_Includes() { //arrange ProtobufnetRegistry registry = new ProtobufnetRegistry(); Assert.IsTrue(registry.Register(typeof(TestBaseType))); }
public static void Test_Can_Register_Backwards_Include_Type() { //arrange ProtobufnetRegistry registry = new ProtobufnetRegistry(); //TestChildTypeWithInclude value = new TestChildTypeWithInclude() { IntField = 5 }; //assert Assert.IsTrue(registry.Register(typeof(TestChildTypeWithInclude))); }