Ejemplo n.º 1
0
        public void TestMockPacketDispatcherDifferentOriginFailed()
        {
            bool dispatched = false;
            bool failed = false;

            MockPacketDispatcher dispatcher = new MockPacketDispatcher() {
                MissingDispatchHandler = (identifer, request, response) => { failed = true; }
            };

            dispatcher.Append(new Dictionary<IPacketDispatch, Action<IPacketWrapper, IPacketWrapper>>() {
                {
                    new PacketDispatch() {
                        Name = "TestMockPacketDispatcherDifferentOriginFailed", Origin = PacketOrigin.Client
                    }, (request, response) => {
                        dispatched = true;
                    }
                }
            });

            dispatcher.Dispatch(new MockPacket() {
                Packet = {
                    Origin = PacketOrigin.Server,
                    RequestId = 2,
                    Type = PacketType.Request,
                },
                Text = "TestMockPacketDispatcherDifferentOriginFailed",
            });

            Assert.IsFalse(dispatched);
            Assert.IsTrue(failed);
        }
Ejemplo n.º 2
0
        public void TestMockPacketDispatcherSuccess()
        {
            bool dispatched = false;

            MockPacketDispatcher dispatcher = new MockPacketDispatcher();

            dispatcher.Append(new Dictionary<IPacketDispatch, Action<IPacketWrapper, IPacketWrapper>>() {
                {
                    new PacketDispatch() {
                        Name = "TestMockPacketDispatcherSuccess", Origin = PacketOrigin.Client
                    }, (request, response) => {
                        dispatched = true;
                    }
                }
            });

            dispatcher.Dispatch(new MockPacket() {
                Packet = {
                    Origin = PacketOrigin.Client,
                    RequestId = 2,
                    Type = PacketType.Request,
                },
                Text = "TestMockPacketDispatcherSuccess",
            });

            Assert.IsTrue(dispatched);
        }
Ejemplo n.º 3
0
        public void TestMockPacketDispatcherReplacedDispatcherSuccess()
        {
            int handler = 0;

            MockPacketDispatcher dispatcher = new MockPacketDispatcher();

            dispatcher.Append(new Dictionary<IPacketDispatch, Action<IPacketWrapper, IPacketWrapper>>() {
                {
                    new PacketDispatch() {
                        Name = "TestMockPacketDispatcherReplacedDispatcherSuccess", Origin = PacketOrigin.Client
                    }, (request, response) => {
                        handler = 1;
                    }
                }
            });

            dispatcher.Append(new Dictionary<IPacketDispatch, Action<IPacketWrapper, IPacketWrapper>>() {
                {
                    new PacketDispatch() {
                        Name = "TestMockPacketDispatcherReplacedDispatcherSuccess", Origin = PacketOrigin.Client
                    }, (request, response) => {
                        handler = 2;
                    }
                }
            });

            dispatcher.Dispatch(new MockPacket() {
                Packet = {
                    Origin = PacketOrigin.Client,
                    RequestId = 2,
                    Type = PacketType.Request,
                },
                Text = "TestMockPacketDispatcherReplacedDispatcherSuccess"
            });

            Assert.AreEqual(2, handler);
        }