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); }
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); }
public void CanExecuteReturnsTrueWithNoConditions() { var contextMock = GenerateContextMock(); var task = new TaskStub(); var expected = task.CanRun(contextMock.Object); Assert.IsTrue(expected); }
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()); }
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); }
public void InitialiseSetsStateToPending() { var initialised = false; var task = new TaskStub { OnInitialiseAction = () => initialised = true }; task.Initialise(); Assert.AreEqual(TaskState.Pending, task.State); Assert.IsTrue(initialised); }
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); }
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); }
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); }
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); }
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); }
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); }
public void IntegrationAsksHostAndContinuesOnAllowed() { 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>())); var executionFactoryMock = new Mock <ITaskExecutionFactory>(MockBehavior.Strict); InitialiseExecutionContext(executionFactoryMock); var project = new ProjectStub("Test", task) { Host = hostMock.Object, 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); }
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); }
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); }
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); }
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); }
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); }
public void NewTaskHasAStateOfLoaded() { var task = new TaskStub(); Assert.AreEqual(TaskState.Loaded, task.State); }