public void TestGetRequestPacketDoesNotExists() { PacketQueue queue = new PacketQueue(); IPacketWrapper packetRequest = new MockPacket() { Packet = { Origin = PacketOrigin.Client, Type = PacketType.Request, RequestId = 1 } }; IPacketWrapper packetResponse = new MockPacket() { Packet = { Origin = PacketOrigin.Client, Type = PacketType.Response, RequestId = 2 } }; queue.PacketSend(packetRequest); Assert.AreEqual(1, queue.OutgoingPackets.Count); IPacketWrapper fetchedRequestPacket = queue.GetRequestPacket(packetResponse); Assert.IsNull(fetchedRequestPacket); }
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); }
public void TestRestartConnectionOnQueueFailureTruey() { PacketQueue queue = new PacketQueue(); IPacketWrapper packet = new MockPacket() { Packet = { Origin = PacketOrigin.Client, Type = PacketType.Request, RequestId = 1, Stamp = DateTime.Now.AddMinutes(-5) } }; IPacketWrapper poppedPacket = queue.PacketSend(packet); Assert.AreEqual(packet, poppedPacket); Assert.AreEqual(1, queue.OutgoingPackets.Count); Assert.IsTrue(queue.RestartConnectionOnQueueFailure()); }
public void TestRestartConnectionOnQueueFailureFalsey() { PacketQueue queue = new PacketQueue(); IPacketWrapper packet = new MockPacket() { Packet = { Origin = PacketOrigin.Client, Type = PacketType.Request, RequestId = 1 } }; IPacketWrapper poppedPacket = queue.PacketSend(packet); Assert.AreEqual(packet, poppedPacket); Assert.AreEqual(1, queue.OutgoingPackets.Count); Assert.IsFalse(queue.RestartConnectionOnQueueFailure()); }
public void TestPacketSendQueued() { PacketQueue queue = new PacketQueue(); IPacketWrapper firstPacket = new MockPacket() { Packet = { Origin = PacketOrigin.Client, Type = PacketType.Request, RequestId = 1 } }; IPacketWrapper poppedPacket = queue.PacketSend(firstPacket); // Client would send to the server. Assert.AreEqual(firstPacket, poppedPacket); Assert.AreEqual(1, queue.OutgoingPackets.Count); IPacketWrapper secondPacket = new MockPacket() { Packet = { Origin = PacketOrigin.Client, Type = PacketType.Request, RequestId = 1 } }; poppedPacket = queue.PacketSend(secondPacket); // Popped packet is null, client would essentially ignore it until later. Assert.IsNull(poppedPacket); Assert.AreEqual(1, queue.OutgoingPackets.Count); Assert.AreEqual(1, queue.QueuedPackets.Count); }
public void TestPacketSendImmediate() { PacketQueue queue = new PacketQueue(); IPacketWrapper packet = new MockPacket() { Packet = { Origin = PacketOrigin.Client, Type = PacketType.Request, RequestId = 1 } }; IPacketWrapper poppedPacket = queue.PacketSend(packet); // Client would send to the server. Assert.AreEqual(packet, poppedPacket); Assert.AreEqual(1, queue.OutgoingPackets.Count); Assert.AreEqual(0, queue.QueuedPackets.Count); }
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); }