Example #1
0
        public void CleanUpSetsStateToTerminatedIfStatusIsExecuting()
        {
            var task = new TaskStub
            {
                OnRunAction = c =>
                {
                    // This will break the run leaving the task in
                    // the executing state
                    throw new Exception();
                }
            };

            task.Initialise();
            var result = task.Run(null);

            Assert.Throws <Exception>(() => result.Count());
            task.CleanUp();
            Assert.AreEqual(TaskState.Terminated, task.State);
        }
Example #2
0
        public void RunReturnsChildTasks()
        {
            var ran       = false;
            var childTask = new TaskStub
            {
                OnRunAction = c =>
                {
                    // This should not be triggered as Run() does not run the child
                    // tasks - instead it is the caller's job to run them
                    ran = true;
                    return(null);
                }
            };
            var task = new TaskStub
            {
                OnRunAction = c => new[] { childTask }
            };
            var contextMock = GenerateContextMock();
            var result      = task.Run(contextMock.Object);

            Assert.AreEqual(result.Count(), 1); // This line is needed to actually trigger the method
            Assert.IsFalse(ran);
        }
Example #3
0
        public void RunSetsStateToCompleted()
        {
            var  ran = false;
            var  intermediateState = TaskState.Unknown;
            Task task = null;
            Func <TaskExecutionContext, IEnumerable <Task> > action = c =>
            {
                ran = true;
                intermediateState = task.State;
                return(null);
            };

            task = new TaskStub
            {
                OnRunAction = action
            };
            var contextMock = GenerateContextMock();
            var result      = task.Run(contextMock.Object);

            Assert.AreEqual(result.Count(), 0); // This line is needed to actually trigger the method
            Assert.AreEqual(TaskState.Completed, task.State);
            Assert.AreEqual(TaskState.Executing, intermediateState);
            Assert.IsTrue(ran);
        }