コード例 #1
0
        public void TheLastDispatchedTaskIsNotExecutedMoreThanOnce()
        {
            var pollingRootDispatcher = new PollingDispatcher();
            var balkingDispatcher = new BalkingDispatcher(pollingRootDispatcher);

            balkingDispatcher.Dispatch(() => this.processedValues.Add(1));
            balkingDispatcher.Dispatch(() => this.processedValues.Add(2));

            pollingRootDispatcher.ExecuteNextTask();
            pollingRootDispatcher.ExecuteNextTask();

            Check.That(this.processedValues).HasSize(1).And.ContainsExactly(2);
        }
コード例 #2
0
 public void DispatchedTasksAreExecutedOnlyWhenCallingExecuteNextTask()
 {
     var pollingDispatcher = new PollingDispatcher();
     pollingDispatcher.Dispatch(() => this.processedValues.Add(1));
     Check.That(this.processedValues).HasSize(0);
     
     pollingDispatcher.ExecuteNextTask();
     Check.That(this.processedValues).HasSize(1).And.ContainsExactly(1);
 }
コード例 #3
0
        public void DispatchedTasksAreExecutedOnlyWhenCallingExecuteNextTask()
        {
            var pollingDispatcher = new PollingDispatcher();

            pollingDispatcher.Dispatch(() => this.processedValues.Add(1));
            Check.That(this.processedValues).HasSize(0);

            pollingDispatcher.ExecuteNextTask();
            Check.That(this.processedValues).HasSize(1).And.ContainsExactly(1);
        }
コード例 #4
0
        public void TasksDispatchedWhileBusyAreDiscarded()
        {
            var pollingRootDispatcher = new PollingDispatcher();
            var balkingDispatcher     = new BalkingDispatcher(pollingRootDispatcher);

            balkingDispatcher.Dispatch(() => this.processedValues.Add(1));
            balkingDispatcher.Dispatch(() => this.processedValues.Add(2));

            balkingDispatcher.Dispatch(() => this.processedValues.Add(3));
            pollingRootDispatcher.ExecuteNextTask();

            // Should have executed only the latest task before the ExecuteNextTask
            Check.That(this.processedValues).HasSize(1).And.ContainsExactly(3);

            balkingDispatcher.Dispatch(() => this.processedValues.Add(4));
            pollingRootDispatcher.ExecuteNextTask();

            balkingDispatcher.Dispatch(() => this.processedValues.Add(5));
            balkingDispatcher.Dispatch(() => this.processedValues.Add(6));
            pollingRootDispatcher.ExecuteNextTask();

            Check.That(this.processedValues).HasSize(3).And.ContainsExactly(3, 4, 6);
        }
コード例 #5
0
        public void TasksDispatchedWhileBusyAreDiscarded()
        {
            var pollingRootDispatcher = new PollingDispatcher();
            var balkingDispatcher = new BalkingDispatcher(pollingRootDispatcher);

            balkingDispatcher.Dispatch(() => this.processedValues.Add(1));
            balkingDispatcher.Dispatch(() => this.processedValues.Add(2));
            
            balkingDispatcher.Dispatch(() => this.processedValues.Add(3));
            pollingRootDispatcher.ExecuteNextTask();
            
            // Should have executed only the latest task before the ExecuteNextTask
            Check.That(this.processedValues).HasSize(1).And.ContainsExactly(3);

            balkingDispatcher.Dispatch(() => this.processedValues.Add(4));
            pollingRootDispatcher.ExecuteNextTask();

            balkingDispatcher.Dispatch(() => this.processedValues.Add(5));
            balkingDispatcher.Dispatch(() => this.processedValues.Add(6));
            pollingRootDispatcher.ExecuteNextTask();

            Check.That(this.processedValues).HasSize(3).And.ContainsExactly(3, 4, 6);
        }
コード例 #6
0
        public void CallingExecuteNextTaskDoesNotThrowWhenNoTaskIsDispatched()
        {
            var pollingDispatcher = new PollingDispatcher();

            pollingDispatcher.ExecuteNextTask();
        }
コード例 #7
0
 public void CallingExecuteNextTaskDoesNotThrowWhenNoTaskIsDispatched()
 {
     var pollingDispatcher = new PollingDispatcher();
     pollingDispatcher.ExecuteNextTask();
 }