public void QueueIsNotBrokenByExceptions()
        {
            // Arrange
            var workerThreads = 2;
            var worker = new BackgroundWorkerQueue(workerThreads);

            var exceptionThrowingWork = new ExceptionThrowingWork();
            var work = new StandardWork();

            // Act
            worker.Enqueue(exceptionThrowingWork);
            worker.Enqueue(work);

            // wait for a bit
            Thread.Sleep(1000);

            // Assert
            CollectionAssert.AreEquivalent(new List<StandardWork>() { work }, PROCESSED_WORK);
        }
        public void ClearErrors()
        {
            // ARRANGE
            var workerThreads = 1;

            var worker = new BackgroundWorkerQueue(workerThreads);

            var exceptionThrowingWork = new ExceptionThrowingWork();

            worker.Enqueue(exceptionThrowingWork);

            // wait for a bit
            Thread.Sleep(500);

            var status = worker.Status();

            // PRECONDITIONS ASSERT
            CollectionAssert.IsNotEmpty(status.Failed);

            // ACT
            worker.ClearErrors();

            // ASSERT
            var actual = worker.Status().Failed;

            CollectionAssert.IsEmpty(actual);
        }
        public void ReaddSpecificErrors()
        {
            // ARRANGE
            var workerThreads = 1;

            var worker = new BackgroundWorkerQueue(workerThreads);

            var exceptionThrowingWork = new ExceptionThrowingWork();

            var longRunningWorkProcessing = new LongRunningWork();
            var longRunningWorkInBacklog = new LongRunningWork();

            worker.Enqueue(exceptionThrowingWork);
            worker.Enqueue(longRunningWorkProcessing);
            worker.Enqueue(longRunningWorkInBacklog);

            // wait for a bit
            Thread.Sleep(500);

            var status = worker.Status();

            // PRECONDITIONS ASSERT
            CollectionAssert.IsNotEmpty(status.Failed);

            // ACT
            worker.ReAddFailed(new List<IWork>() { exceptionThrowingWork });

            // ASSERT
            var actual = worker.Status();

            CollectionAssert.IsEmpty(actual.Failed);
            CollectionAssert.Contains(actual.Processing, longRunningWorkProcessing);
            CollectionAssert.Contains(actual.Backlog, longRunningWorkInBacklog);
            CollectionAssert.Contains(actual.Backlog, exceptionThrowingWork);
        }
        public void Status()
        {
            // Arrange
            var workerThreads = 2;

            var worker = new BackgroundWorkerQueue(workerThreads);

            var exceptionThrowingWork1 = new ExceptionThrowingWork();
            var exceptionThrowingWork2 = new ExceptionThrowingWork();
            var longRunningWork1 = new LongRunningWork();
            var longRunningWork2 = new LongRunningWork();
            var work1 = new StandardWork();
            var work2 = new StandardWork();

            // Act
            worker.Enqueue(exceptionThrowingWork1);
            worker.Enqueue(exceptionThrowingWork2);
            worker.Enqueue(longRunningWork1);
            worker.Enqueue(longRunningWork2);
            worker.Enqueue(work1);
            worker.Enqueue(work2);

            // wait for a bit
            Thread.Sleep(1000);

            var actual = worker.Status();

            // Assert

            //backlog
            CollectionAssert.AreEquivalent(new List<IWork>() { work1, work2 }, actual.Backlog);

            //failed
            CollectionAssert.AreEquivalent(
                new List<IWork>() { exceptionThrowingWork1, exceptionThrowingWork2 }, actual.Failed);

            //processing
            CollectionAssert.AreEquivalent(new List<IWork>() { longRunningWork1, longRunningWork2 }, actual.Processing);
        }