Push() public method

Pushes a new routing key into the message. This key indicates where a message to this message should be routed back to.
public Push ( int routingKey ) : void
routingKey int Unique routing key.
return void
		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_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_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_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);
            }
        }
        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
        }