Example #1
0
        public void TestPacketReceivedRemovedAndPopped()
        {
            PacketQueue queue = new PacketQueue();

            IPacketWrapper firstPacketRequest = new MockPacket() {
                Packet = {
                    Origin = PacketOrigin.Client,
                    Type = PacketType.Request,
                    RequestId = 1
                }
            };

            IPacketWrapper secondPacketRequest = new MockPacket() {
                Packet = {
                    Origin = PacketOrigin.Client,
                    Type = PacketType.Request,
                    RequestId = 2
                }
            };

            IPacketWrapper firstPacketResponse = new MockPacket() {
                Packet = {
                    Origin = PacketOrigin.Client,
                    Type = PacketType.Response,
                    RequestId = 1
                }
            };

            queue.PacketSend(firstPacketRequest);
            queue.PacketSend(secondPacketRequest);
            Assert.AreEqual(1, queue.OutgoingPackets.Count);
            Assert.AreEqual(1, queue.QueuedPackets.Count);

            IPacketWrapper poppedPacket = queue.PacketReceived(firstPacketResponse);
            Assert.AreEqual(secondPacketRequest, poppedPacket);

            queue.PacketSend(poppedPacket);

            Assert.AreEqual(1, queue.OutgoingPackets.Count);
            Assert.AreEqual(0, queue.QueuedPackets.Count);
        }
Example #2
0
        public void TestPacketReceivedRemoveFromOutgoing()
        {
            PacketQueue queue = new PacketQueue();

            IPacketWrapper sentPacket = new MockPacket() {
                Packet = {
                    Origin = PacketOrigin.Client,
                    Type = PacketType.Request,
                    RequestId = 1
                }
            };

            IPacketWrapper recievedPacket = new MockPacket() {
                Packet = {
                    Origin = PacketOrigin.Client,
                    Type = PacketType.Response,
                    RequestId = 1
                }
            };

            IPacketWrapper poppedPacket = queue.PacketSend(sentPacket);

            // Client would send to the server.

            Assert.AreEqual(sentPacket, poppedPacket);
            Assert.AreEqual(1, queue.OutgoingPackets.Count);
            Assert.AreEqual(0, queue.QueuedPackets.Count);

            poppedPacket = queue.PacketReceived(recievedPacket);

            Assert.IsNull(poppedPacket);
            Assert.AreEqual(0, queue.OutgoingPackets.Count);
            Assert.AreEqual(0, queue.QueuedPackets.Count);
        }