Пример #1
0
 public void CanExecuteReturnsTrueWithNoConditions()
 {
     var contextMock = GenerateContextMock();
     var task = new TaskStub();
     var expected = task.CanRun(contextMock.Object);
     Assert.IsTrue(expected);
 }
Пример #2
0
 public void RunReturnsAllTasks()
 {
     var childTask = new TaskStub();
     var task = new Sequence(childTask);
     var result = task.Run(null);
     Assert.AreEqual(1, result.Count());
     Assert.AreSame(childTask, result.First());
 }
Пример #3
0
 public void InitialiseSetsStateToPending()
 {
     var initialised = false;
     var task = new TaskStub
                    {
                        OnInitialiseAction = () => initialised = true
                    };
     task.Initialise();
     Assert.AreEqual(TaskState.Pending, task.State);
     Assert.IsTrue(initialised);
 }
Пример #4
0
 public void ValidateSetsStateAndFiresOnValidate()
 {
     var validated = false;
     var task = new TaskStub
                    {
                        OnValidateAction = vl => validated = true
                    };
     var validationMock = new Mock<IValidationLog>();
     task.Validate(validationMock.Object);
     Assert.AreEqual(TaskState.Validated, task.State);
     Assert.IsTrue(validated);
 }
Пример #5
0
 public void CanExecuteReturnsFalseWhenAnyConditionIsFalse()
 {
     var contextMock = GenerateContextMock();
     var condition1Mock = new Mock<TaskCondition>();
     var condition2Mock = new Mock<TaskCondition>();
     condition1Mock.Setup(c => c.Evaluate(contextMock.Object)).Returns(true);
     condition2Mock.Setup(c => c.Evaluate(contextMock.Object)).Returns(false);
     var task = new TaskStub();
     task.Conditions.Add(condition1Mock.Object);
     task.Conditions.Add(condition2Mock.Object);
     var expected = task.CanRun(contextMock.Object);
     Assert.IsFalse(expected);
 }
Пример #6
0
 public void ValidateValidatesFailureActions()
 {
     var validated = false;
     var failureActionStub = new TaskFailureActionStub
                             {
                                 OnValidate = vl => validated = true
                             };
     var task = new TaskStub();
     task.FailureActions.Add(failureActionStub);
     var validationMock = new Mock<IValidationLog>();
     task.Validate(validationMock.Object);
     Assert.IsTrue(validated);
 }
Пример #7
0
 public void ValidateValidatesConditions()
 {
     var validated = false;
     var conditionStub = new TaskConditionStub
                             {
                                 OnValidate = vl => validated = true
                             };
     var task = new TaskStub();
     task.Conditions.Add(conditionStub);
     var validationMock = new Mock<IValidationLog>();
     task.Validate(validationMock.Object);
     Assert.IsTrue(validated);
 }
Пример #8
0
 public void IntegrateHandlesErrorDuringInitialisation()
 {
     var ran = false;
     var cleanedUp = false;
     var dummy = new TaskStub
                     {
                         OnInitialiseAction = () =>
                                                  {
                                                      throw new Exception("Oops!");
                                                  },
                         OnRunAction = c =>
                                           {
                                               ran = true;
                                               return null;
                                           },
                         OnCleanUpAction = () => cleanedUp = true
                     };
     var project = new Project("test", dummy);
     var request = new IntegrationRequest("Dummy");
     project.Integrate(request);
     Assert.IsFalse(ran);
     Assert.IsTrue(cleanedUp);
 }
Пример #9
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);
 }
Пример #10
0
 public void CleanUpSetsStateToSkippedIfStatusIsPending()
 {
     var cleanedUp = false;
     var task = new TaskStub
                    {
                        OnCleanUpAction = () => cleanedUp = true
                    };
     task.Initialise();
     task.CleanUp();
     Assert.AreEqual(TaskState.Skipped, task.State);
     Assert.IsTrue(cleanedUp);
 }
Пример #11
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);
 }
Пример #12
0
        public void IntegrationAsksHostAndStopsOnDenied()
        {
            var triggered = false;
            var trigger = GenerateRunOnceTrigger(() => triggered = true);
            var ran = false;
            var task = new TaskStub
                           {
                               OnRunAction = tc =>
                                                 {
                                                     ran = true;
                                                     return null;
                                                 }
                           };
            var hostMock = new Mock<ServerItem>(MockBehavior.Strict);
            hostMock.Setup(h => h.AskToIntegrate(It.IsAny<IntegrationContext>()))
                .Callback((IntegrationContext c) => c.Cancel());
            var project = new ProjectStub("Test", task)
                              {
                                  Host = hostMock.Object,
                                  OnLoadState = () => { },
                                  OnSaveState = () => { },
                                  Clock = new SystemClock()
                              };
            project.Triggers.Add(trigger);
            project.Start();

            // Give the project time to start
            Thread.Sleep(100);
            project.Stop();

            // Give the project time to stop
            Thread.Sleep(1000);
            Assert.IsTrue(triggered);
            Assert.IsFalse(ran);
            Assert.IsNull(project.MainThreadException);
        }
Пример #13
0
        public void IntegrationStartsFromTrigger()
        {
            var triggered = false;
            var trigger = GenerateRunOnceTrigger(() => triggered = true);
            var ran = false;
            var task = new TaskStub
                           {
                               OnRunAction = tc =>
                                                 {
                                                     ran = true;
                                                     return null;
                                                 }
                           };
            var executionFactoryMock = new Mock<ITaskExecutionFactory>(MockBehavior.Strict);
            InitialiseExecutionContext(executionFactoryMock);
            var project = new ProjectStub("Test", task)
                              {
                                  TaskExecutionFactory = executionFactoryMock.Object,
                                  OnLoadState = () => { },
                                  OnSaveState = () => { },
                                  Clock = new SystemClock()
                              };
            project.Triggers.Add(trigger);
            project.Start();

            // Give the project time to start
            Thread.Sleep(100);
            project.Stop();

            // Give the project time to stop
            Thread.Sleep(1000);
            Assert.IsTrue(triggered);
            Assert.IsTrue(ran);
            Assert.IsNull(project.MainThreadException);
        }
Пример #14
0
 public void IntegrateSkipsTasksWhoseConditionsFail()
 {
     var conditionMock = new Mock<TaskCondition>(MockBehavior.Strict);
     conditionMock.Setup(c => c.Evaluate(It.IsAny<TaskExecutionContext>()))
         .Returns(false);
     var initialised = false;
     var ran = false;
     var cleanedUp = false;
     var dummy = new TaskStub
                     {
                         OnInitialiseAction = () => initialised = true,
                         OnRunAction = c =>
                                           {
                                               ran = true;
                                               return null;
                                           },
                         OnCleanUpAction = () => cleanedUp = true
                     };
     dummy.Conditions.Add(conditionMock.Object);
     var executionFactoryMock = new Mock<ITaskExecutionFactory>(MockBehavior.Strict);
     var contextMock = InitialiseExecutionContext(executionFactoryMock);
     contextMock.Setup(ec => ec.AddEntryToBuildLog("Task 'TaskStub' has been skipped"));
     var project = new Project("test", dummy)
                       {
                           TaskExecutionFactory = executionFactoryMock.Object
                       };
     var request = new IntegrationRequest("Dummy");
     project.Integrate(request);
     Assert.IsTrue(initialised);
     Assert.IsFalse(ran);
     Assert.IsTrue(cleanedUp);
 }
Пример #15
0
 public void IntegrateHandlesErrorDuringTaskCleanUp()
 {
     var initialised = false;
     var ran = false;
     var dummy = new TaskStub
                     {
                         OnInitialiseAction = () => initialised = true,
                         OnRunAction = c =>
                                           {
                                               ran = true;
                                               return null;
                                           },
                         OnCleanUpAction = () =>
                                               {
                                                   throw new Exception("Oops");
                                               }
                     };
     var executionFactoryMock = new Mock<ITaskExecutionFactory>(MockBehavior.Strict);
     InitialiseExecutionContext(executionFactoryMock);
     var project = new Project("test", dummy)
                       {
                           TaskExecutionFactory = executionFactoryMock.Object
                       };
     var request = new IntegrationRequest("Dummy");
     project.Integrate(request);
     Assert.IsTrue(initialised);
     Assert.IsTrue(ran);
 }
Пример #16
0
 public void SkipSetsStateToSkipped()
 {
     var task = new TaskStub();
     var contextMock = GenerateContextMock();
     contextMock.Setup(ec => ec.AddEntryToBuildLog("Task 'TaskStub' has been skipped"));
     task.Skip(contextMock.Object);
     Assert.AreEqual(TaskState.Skipped, task.State);
 }
Пример #17
0
 public void NewTaskHasAStateOfLoaded()
 {
     var task = new TaskStub();
     Assert.AreEqual(TaskState.Loaded, task.State);
 }
Пример #18
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);
 }
Пример #19
0
 public void IntegrateInitialisesRunsAndCleansUp()
 {
     var initialised = false;
     var ran = false;
     var cleanedUp = false;
     var dummy = new TaskStub
                     {
                         OnInitialiseAction = () => initialised = true,
                         OnRunAction = c => { ran = true; return null; },
                         OnCleanUpAction = () => cleanedUp = true
                     };
     var executionFactoryMock = new Mock<ITaskExecutionFactory>(MockBehavior.Strict);
     InitialiseExecutionContext(executionFactoryMock);
     var project = new Project("test", dummy)
                       {
                           TaskExecutionFactory = executionFactoryMock.Object
                       };
     var request = new IntegrationRequest("Dummy");
     project.Integrate(request);
     Assert.IsTrue(initialised);
     Assert.IsTrue(ran);
     Assert.IsTrue(cleanedUp);
 }