System.Collections.Tests.Helpers.PerformActionOnAllQueueWrappers C# (CSharp) Method

PerformActionOnAllQueueWrappers() public static method

public static PerformActionOnAllQueueWrappers ( Queue queue, Action action ) : void
queue Queue
action Action
return void
        public static void PerformActionOnAllQueueWrappers(Queue queue, Action<Queue> action)
        {
            // Synchronized returns a slightly different version of Queue
            Queue[] queueTypes =
            {
                (Queue)queue.Clone(),
                Queue.Synchronized(queue)
            };

            foreach (Queue queueType in queueTypes)
            {
                action(queueType);
            }
        }

Usage Example

Beispiel #1
0
        public static void Clone_DequeueThenEnqueue()
        {
            var queue1 = new Queue(100);

            Helpers.PerformActionOnAllQueueWrappers(queue1, queue2 =>
            {
                // Insert 50 items in the Queue
                for (int i = 0; i < 50; i++)
                {
                    queue2.Enqueue(i);
                }

                // Insert and Remove 75 items in the Queue. This should wrap the queue
                // where there is 25 at the end of the array and 25 at the beginning
                for (int i = 0; i < 75; i++)
                {
                    queue2.Enqueue(i + 50);
                    queue2.Dequeue();
                }

                Queue queClone = (Queue)queue2.Clone();

                Assert.Equal(50, queClone.Count);
                Assert.Equal(75, queClone.Dequeue());

                // Add an item to the Queue
                queClone.Enqueue(100);
                Assert.Equal(50, queClone.Count);
                Assert.Equal(76, queClone.Dequeue());
            });
        }
All Usage Examples Of System.Collections.Tests.Helpers::PerformActionOnAllQueueWrappers