Пример #1
0
        public void IntervalQueueCorrectlyDequeues()
        {
            TimeSpan windowSize = TimeSpan.FromDays(5);
            IntervalQueue<QueueItem> queue = new IntervalQueue<QueueItem>(windowSize, "EventTime");

            DateTime initialDate = DateTime.UtcNow;
            int initialValue = 0;

            queue.Enqueue(new QueueItem()
            {
                EventTime  = initialDate.AddDays(1),
                Value = initialValue++,
            });

            QueueItem expected = new QueueItem()
            {
                EventTime = initialDate.AddDays(2),
                Value = initialValue++,
            };

            queue.Enqueue(expected);

            queue.Enqueue(new QueueItem()
            {
                EventTime = initialDate.AddDays(3),
                Value = initialValue++,
            });

            QueueItem overflow;
            queue.TryDequeue(out overflow);

            QueueItem actual;
            queue.TryDequeue(out actual);

            Assert.Equal(expected, actual);
        }
Пример #2
0
        public void IntervalQueueWillRespectWindowSize()
        {
            TimeSpan windowSize = TimeSpan.FromDays(2.5);
            IntervalQueue<QueueItem> queue = new IntervalQueue<QueueItem>(windowSize, "EventTime");

            // Data Set
            DateTime initialDate = DateTime.UtcNow;
            double timeIncrement = 1;

            List<QueueItem> dataSet = new List<QueueItem>();

            for (int i = 0; i < 10; i++)
            {
                dataSet.Add(new QueueItem()
                {
                    EventTime = initialDate.AddDays((double)i * timeIncrement),
                    Value = i
                });
            }

            List<QueueItem> expected = dataSet.Skip(7).ToList();

            foreach (QueueItem item in dataSet)
            {
                queue.Enqueue(item);
            }

            List<QueueItem> actual = queue.ToList();

            Assert.Equal<QueueItem>(expected, actual);
        }