public void CanDump() { queue.Push(new BaseMessage(new StringValue("content1"), 1, 10)); queue.Push(new BaseMessage(new StringValue("content2"), 2, 10)); queue.Push(new BaseMessage(new StringValue("content3"), 3, 11)); queue.Push(new BaseMessage(new StringValue("content4"), 4, 12)); queue.Push(new BaseMessage(new StringValue("content5"), 5, 13)); GenericMessageQueue <BaseMessage, FakeCurrentTimeProvider> newQueue = new GenericMessageQueue <BaseMessage, FakeCurrentTimeProvider>(); newQueue.LoadDump(queue.Dump()); newQueue.TimeProvider.SetTime(11); // time now is 13, there should be 4 messages Assert.AreEqual(5, newQueue.Count()); Assert.AreEqual(3, newQueue.ReceivedCount()); BaseMessage received = newQueue.Pop(); Assert.AreEqual(1, received.SentAt); Assert.AreEqual(10, received.ReceivedAt); Assert.AreEqual(new StringValue("content1"), received.Content); Assert.AreEqual(new StringValue("content2"), newQueue.Pop().Content); Assert.AreEqual(new StringValue("content3"), newQueue.Pop().Content); }
public void CanDump() { queue.Push(new BaseMessage(new StringValue("content1"), 1, 10)); queue.Push(new BaseMessage(new StringValue("content2"), 2, 10)); queue.Push(new BaseMessage(new StringValue("content3"), 3, 11)); queue.Push(new BaseMessage(new StringValue("content4"), 4, 12)); queue.Push(new BaseMessage(new StringValue("content5"), 5, 13)); GenericMessageQueue<BaseMessage> newQueue = new GenericMessageQueue<BaseMessage>(timeProvider); newQueue.LoadDump(queue.Dump()); timeProvider.FakeTime = 11; // time now is 13, there should be 4 messages Assert.AreEqual(5, newQueue.Count()); Assert.AreEqual(3, newQueue.ReceivedCount()); BaseMessage received = newQueue.Pop(); Assert.AreEqual(1, received.SentAt); Assert.AreEqual(10, received.ReceivedAt); Assert.AreEqual(new StringValue("content1"), received.Content); Assert.AreEqual(new StringValue("content2"), newQueue.Pop().Content); Assert.AreEqual(new StringValue("content3"), newQueue.Pop().Content); }
public void CanHandleNoMessages() { Assert.AreEqual(0, queue.Count()); Assert.AreEqual(0, queue.ReceivedCount()); Assert.Throws <KOSCommunicationException>(delegate { queue.Pop(); }); Assert.Throws <KOSCommunicationException>(delegate { queue.Peek(); }); }