public void WithResultWorks()
        {
            // --- Arrange
            var processor = new QueuedTaskProcessor <ResultTaskWithCompletedResetEvent, string, int>(s_Context)
            {
                DoNotPeekWhenCheckingTasks = false,
                MaxDequeuCountBeforeDrop   = 5,
                MaxMessagesReadFromQueue   = 25,
                PeekPolicy = s_PeekPolicy,
                VisibilityTimeoutInSeconds = 30,
                RequestQueueKey            = REQUEST_QUEUE,
                ResponseQueueKey           = RESPONSE_QUEUE,
                TaskSleepInMilliseconds    = 20
            };
            var queue         = ResourceConnectionFactory.CreateResourceConnection <INamedQueue>(REQUEST_QUEUE);
            var responseQueue = ResourceConnectionFactory.CreateResourceConnection <INamedQueue>(RESPONSE_QUEUE);

            queue.Clear();
            //responseQueue.Clear();
            queue.PutMessage("testmessage1", 70);
            queue.PutMessage("testmsg2", 70);
            ResultTaskWithCompletedResetEvent.DisposeTimes = 0;
            ResultTaskWithCompletedResetEvent.RunTimes     = 0;
            ResultTaskWithCompletedResetEvent.SetupTimes   = 0;
            s_TasksCompletedAutoResetEvent = new AutoResetEvent(false);
            bool completedSuccessfully;

            using (s_TasksCompletedAutoResetEvent)
            {
                // --- Act
                processor.Start();
                //wait for both tasks to complete (Sets, if the 2. message's dispose is finished)
                completedSuccessfully = s_TasksCompletedAutoResetEvent.WaitOne(10000);
                processor.Stop();
            }
            // --- Assert

            ResultTaskWithCompletedResetEvent.SetupTimes.ShouldEqual(2);
            ResultTaskWithCompletedResetEvent.RunTimes.ShouldEqual(2);
            ResultTaskWithCompletedResetEvent.DisposeTimes.ShouldEqual(2);
            completedSuccessfully.ShouldBeTrue("Tasks did not complete in 10 seconds");
            ResultTaskWithCompletedResetEvent.ResultDict.ContainsValue("testmessage1").ShouldBeTrue();
            ResultTaskWithCompletedResetEvent.ResultDict.ContainsValue("testmsg2").ShouldBeTrue();
            var messages = responseQueue.GetMessages(2, 40);

            foreach (var message in messages)
            {
                ResultTaskWithCompletedResetEvent.ResultDict[Convert.ToInt32(message.MessageText)]
                .Length.ShouldEqual(Convert.ToInt32(message.MessageText));
            }
            processor.Dispose();
        }
        public void StopWorks()
        {
            // --- Arrange
            var processor = new QueuedTaskProcessor <TaskWithSetupEvent, string>(s_Context)
            {
                DoNotPeekWhenCheckingTasks = false,
                MaxDequeuCountBeforeDrop   = 10,
                MaxMessagesReadFromQueue   = 25,
                PeekPolicy = s_PeekPolicy,
                VisibilityTimeoutInSeconds = 30,
                RequestQueueKey            = "requestQueue",
                TaskSleepInMilliseconds    = 20
            };

            var queue = ResourceConnectionFactory.CreateResourceConnection <INamedQueue>(REQUEST_QUEUE);

            queue.Clear();
            queue.PutMessage("testmessage1", 70);
            queue.PutMessage("testmsg2", 70);
            TaskWithSetupEvent.DisposeTimes = 0;
            TaskWithSetupEvent.RunTimes     = 0;
            TaskWithSetupEvent.SetupTimes   = 0;
            s_TaskSetupAutoResetEvent       = new AutoResetEvent(false);
            bool completedSuccessfully;

            using (s_TaskSetupAutoResetEvent)
            {
                // --- Act
                processor.Start();
                //wait for the first task to finish setup
                completedSuccessfully = s_TaskSetupAutoResetEvent.WaitOne(10000);
                processor.Stop();
            }
            // --- Assert
            completedSuccessfully.ShouldBeTrue("Tasks did not complete in 10 seconds");
            TaskWithSetupEvent.SetupTimes.ShouldEqual(1, "Setup");
            TaskWithSetupEvent.RunTimes.ShouldEqual(0, "Run");
            TaskWithSetupEvent.DisposeTimes.ShouldEqual(1, "Dispose");
            processor.Dispose();
        }