Пример #1
0
        public void TwoPopsWaitWhenItemsWillBeAvailable()
        {
            using (RichQueue <int> richQueue = new RichQueue <int>())
            {
                AutoResetEvent resetEvent = new AutoResetEvent(false);

                var task1 = Task.Run(() =>
                {
                    resetEvent.Set();
                    return(richQueue.Pop());
                });

                // Wait when Pop task begin
                resetEvent.WaitOne();

                var task2 = Task.Run(() =>
                {
                    resetEvent.Set();
                    return(richQueue.Pop());
                });

                // Wait when Pop task begin
                resetEvent.WaitOne();

                richQueue.Push(5);
                richQueue.Push(7);

                Assert.AreEqual(5, task1.Result);
                Assert.AreEqual(7, task2.Result);
            }
        }
Пример #2
0
        public void PushIncreasesCount()
        {
            using (RichQueue <int> richQueue = new RichQueue <int>())
            {
                richQueue.Push(5);
                richQueue.Push(7);

                Assert.AreEqual(2, richQueue.Count);
            }
        }
Пример #3
0
        public void PopTwiseReturnsTwoPushedItem()
        {
            using (RichQueue <int> richQueue = new RichQueue <int>())
            {
                richQueue.Push(5);
                richQueue.Push(7);

                var actualValue1 = richQueue.Pop();
                var actualValue2 = richQueue.Pop();

                Assert.AreEqual(5, actualValue1);
                Assert.AreEqual(7, actualValue2);
            }
        }
Пример #4
0
        public void PushThrowsOnDisposedObject()
        {
            RichQueue <int> richQueue = new RichQueue <int>();

            richQueue.Dispose();

            Assert.Catch <ObjectDisposedException>(() => richQueue.Push(5));
        }
Пример #5
0
        public void PopReturnsPushedItem()
        {
            using (RichQueue <int> richQueue = new RichQueue <int>())
            {
                richQueue.Push(5);
                var actualValue = richQueue.Pop();

                Assert.AreEqual(5, actualValue);
            }
        }
Пример #6
0
        public void PopDecreasesCount()
        {
            using (RichQueue <int> richQueue = new RichQueue <int>())
            {
                richQueue.Push(5);
                var countBeforePop = richQueue.Count;

                richQueue.Pop();

                Assert.AreEqual(countBeforePop - 1, richQueue.Count);
            }
        }
Пример #7
0
        public void CountThrowsOnDisposedObject()
        {
            RichQueue <int> richQueue = new RichQueue <int>();

            richQueue.Push(5);
            richQueue.Dispose();

            Assert.Catch <ObjectDisposedException>(() =>
            {
                var count = richQueue.Count;
            });
        }
Пример #8
0
        public void PopWaitsWhenItemWillBeAvailable()
        {
            using (RichQueue <int> richQueue = new RichQueue <int>())
            {
                ManualResetEvent resetEvent = new ManualResetEvent(false);
                var task = Task.Run(() =>
                {
                    resetEvent.Set();

                    return(richQueue.Pop());
                });

                // Wait when Pop task begin
                resetEvent.WaitOne();
                richQueue.Push(5);

                Assert.AreEqual(5, task.Result);
            }
        }