예제 #1
0
        public void TestMockPacketDispatcherMissingDispatchNameFailed()
        {
            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 = "TestMockPacketDispatcherMissingDispatchNameFailed", Origin = PacketOrigin.Client
                    }, (request, response) => {
                        dispatched = true;
                    }
                }
            });

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

            Assert.IsFalse(dispatched);
            Assert.IsTrue(failed);
        }
예제 #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);
        }
예제 #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);
        }