Inheritance: NetworkMessage, IResponseMessage
Ejemplo n.º 1
0
        public static void Test_Construction()
        {
            //arrange
            Mock<PacketPayload> packet = new Mock<PacketPayload>(MockBehavior.Strict);

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

            //assert
            //Just that it doesn't throw.
        }
Ejemplo n.º 2
0
        public static void Test_Dispatch_Null_Parameters()
        {
            //arrange
            Mock<PacketPayload> packet = new Mock<PacketPayload>(MockBehavior.Strict);
            ResponseMessage message = new ResponseMessage(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));
        }
Ejemplo n.º 3
0
        public static void Test_Dispatch()
        {
            //arrange
            Mock<PacketPayload> packet = new Mock<PacketPayload>(MockBehavior.Strict);
            ResponseMessage message = new ResponseMessage(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 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);
		}
Ejemplo n.º 5
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.º 6
0
        public static void Test_Dispatch_Null_Receiver()
        {
            //arrange
            Mock<PacketPayload> packet = new Mock<PacketPayload>(MockBehavior.Strict);
            ResponseMessage message = new ResponseMessage(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.º 7
0
        public static void Test_Properties_After_Construction()
        {
            //arrange
            Mock<PacketPayload> packet = new Mock<PacketPayload>(MockBehavior.Strict);

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

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

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

            //assert
            //Just that it doesn't throw
            Assert.AreEqual(message.OperationTypeMappedValue, OperationType.Response);
        }
Ejemplo n.º 9
0
        public static void Test_Event_Message_Routing_Stack_Has_Pushed_Values()
        {
            //arrange
            Mock<PacketPayload> packet = new Mock<PacketPayload>(MockBehavior.Strict);
            ResponseMessage message = new ResponseMessage(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
        }