public void ShutdownQueueAfterSomeAddsShouldResultInTheProcessOfAllAddedItemsBeforeDisposal()
        {
            var consumed = new ConcurrentBag <MyClass>();

            Action <MyClass> consumer = x => { consumed.Add(x); };

            var queue = new ProducerConsumerQueue <MyClass>(consumer, 1);
            ProducerConsumerQueueException thrownException = null;

            queue.OnException += (sender, args) =>
            {
                thrownException = args;
            };

            5.Times(n => { queue.Add(_getData(n)); });
            queue.CompleteAdding();

            queue.Completion.Wait(10.Seconds()).ShouldBeTrue();

            Action afterDisposedEnqueues = () => 3.Times(n => { queue.Add(_getData(n)); });

            afterDisposedEnqueues.ShouldNotThrow();

            Thread.Sleep(100);

            consumed.Count.ShouldBe(5);

            Thread.Sleep(1.Seconds());
            thrownException.ShouldNotBeNull();
            thrownException.Message.ShouldBe("Exception occurred when adding item.");
        }
        public void DisposedQueueShouldNotAllowAddingNewItems()
        {
            var consumed = new ConcurrentBag <MyClass>();
            Action <MyClass> consumer = x => { consumed.Add(x); };

            var queue = new ProducerConsumerQueue <MyClass>(consumer, 1);

            ProducerConsumerQueueException thrownException = null;

            queue.OnException += (sender, args) =>
            {
                thrownException = args;
            };

            const int WorkItems = 10;

            for (var i = 0; i < 10; i++)
            {
                queue.Add(_getData(i));
            }
            queue.CompleteAdding();

            queue.Completion.Wait(5.Seconds()).ShouldBeTrue();

            Thread.Sleep(50.Milliseconds());
            consumed.Count.ShouldBe(WorkItems);

            Assert.DoesNotThrow(() => queue.Add(new MyClass()));

            Thread.Sleep(1.Seconds());
            thrownException.ShouldNotBeNull();
            thrownException.Message.ShouldBe("Exception occurred when adding item.");
        }