Inheritance: NetworkMessage, IRequestMessage, IRoutableMessage
		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_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());
		}
Ejemplo n.º 3
0
        public static void Test_Construction()
        {
            //arrange
            Mock<PacketPayload> packet = new Mock<PacketPayload>(MockBehavior.Strict);

            //act
            RequestMessage message = new RequestMessage(packet.Object);

            //assert
            //Just that it doesn't throw
        }
		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));
		}
Ejemplo n.º 5
0
        public static void Test_Dispatch_Null_Parameters()
        {
            //arrange
            Mock<PacketPayload> packet = new Mock<PacketPayload>(MockBehavior.Strict);
            RequestMessage message = new RequestMessage(packet.Object);
            Mock<INetworkMessageReceiver> receiever = new Mock<INetworkMessageReceiver>(MockBehavior.Strict);

            //Sets up the method that should be called so it doesn't throw.
            //Also rigs it up so that the two mocks above should be the values provided.
            receiever.Setup((actual) => actual.OnNetworkMessageReceive(message, null));

            //assert
            //Exception should be thrown for null.
            Assert.Throws<ArgumentNullException>(() => message.Dispatch(receiever.Object, null));
        }
		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)));
		}
Ejemplo n.º 7
0
        public static void Test_Dispatch()
        {
            //arrange
            Mock<PacketPayload> packet = new Mock<PacketPayload>(MockBehavior.Strict);
            RequestMessage message = new RequestMessage(packet.Object);
            Mock<IMessageParameters> parameters = new Mock<IMessageParameters>(MockBehavior.Strict);
            Mock<INetworkMessageReceiver> receiever = new Mock<INetworkMessageReceiver>(MockBehavior.Strict);

            //Sets up the method that should be called so it doesn't throw.
            //Also rigs it up so that the two mocks above should be the values provided.
            receiever.Setup((actual) => actual.OnNetworkMessageReceive(message, parameters.Object));

            //act
            message.Dispatch(receiever.Object, parameters.Object);

            //asset
            receiever.Verify((actual) => actual.OnNetworkMessageReceive(message, parameters.Object));
        }
		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)));
		}
Ejemplo n.º 9
0
        public static void Test_Event_Message_Routing_Stack_Can_Export_To_Other_Message()
        {
            //arrange
            Mock<PacketPayload> packet = new Mock<PacketPayload>(MockBehavior.Strict);
            RequestMessage message = new RequestMessage(packet.Object);

            //act
            message.Push(5);
            message.Push(4);
            message.Push(3);

            ResponseMessage rMessage = new ResponseMessage(packet.Object);

            //export routing stack
            message.ExportRoutingDataTo(rMessage);

            List<IRoutableMessage> Messages = new List<IRoutableMessage>() { rMessage, message };

            foreach (IRoutableMessage m in Messages)
            {
                Assert.NotNull(m.Peek());
                Assert.True(m.isMessageRoutable);

                Assert.AreEqual(3, m.Pop());
                Assert.AreEqual(4, m.Pop());
                Assert.AreEqual(5, m.Pop());

                Assert.IsNull(m.Peek());
                Assert.IsFalse(m.isMessageRoutable);
            }
        }
Ejemplo n.º 10
0
        public static void Test_Dispatch_Null_Receiver()
        {
            //arrange
            Mock<PacketPayload> packet = new Mock<PacketPayload>(MockBehavior.Strict);
            RequestMessage message = new RequestMessage(packet.Object);
            Mock<IMessageParameters> parameters = new Mock<IMessageParameters>(MockBehavior.Strict);

            //assert
            //Exception should be thrown for null.
            Assert.Throws<ArgumentNullException>(() => message.Dispatch(null, parameters.Object));
        }
Ejemplo n.º 11
0
        public static void Test_Properties_After_Construction()
        {
            //arrange
            Mock<PacketPayload> packet = new Mock<PacketPayload>(MockBehavior.Strict);

            //act
            RequestMessage message = new RequestMessage(packet.Object);

            //assert
            Assert.AreSame(packet.Object, message.Payload.Data);
        }
Ejemplo n.º 12
0
        public static void Test_OperationType_Returning_Correctly()
        {
            //arrange
            Mock<PacketPayload> packet = new Mock<PacketPayload>(MockBehavior.Strict);

            //act
            RequestMessage message = new RequestMessage(packet.Object);

            //assert
            //Just that it doesn't throw
            Assert.AreEqual(message.OperationTypeMappedValue, OperationType.Request);
        }
Ejemplo n.º 13
0
        public static void Test_Event_Message_Routing_Stack_Has_Pushed_Values()
        {
            //arrange
            Mock<PacketPayload> packet = new Mock<PacketPayload>(MockBehavior.Strict);
            RequestMessage message = new RequestMessage(packet.Object);

            //act
            message.Push(5);
            message.Push(4);
            message.Push(3);

            //assert
            Assert.NotNull(message.Peek());
            Assert.True(message.isMessageRoutable);

            Assert.AreEqual(3, message.Pop());
            Assert.AreEqual(4, message.Pop());
            Assert.AreEqual(5, message.Pop());

            Assert.IsNull(message.Peek());
            Assert.IsFalse(message.isMessageRoutable); //shouldn't be able to rout
        }
Ejemplo n.º 14
0
        public static void Test_Event_Message_Routing_Stack_Empty_On_Initial_Creation()
        {
            //arrange
            Mock<PacketPayload> packet = new Mock<PacketPayload>(MockBehavior.Strict);
            RequestMessage message = new RequestMessage(packet.Object);

            //assert
            Assert.IsNull(message.Peek());
            Assert.IsFalse(message.isMessageRoutable); //shouldn't be able to rout
        }