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); }
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); }
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); }
public void CallingExecuteNextTaskDoesNotThrowWhenNoTaskIsDispatched() { var pollingDispatcher = new PollingDispatcher(); pollingDispatcher.ExecuteNextTask(); }