public void TestRunningToFailByEvaluatorScenario()
        {
            var taskState = new TaskStateMachine();

            taskState.MoveNext(TaskStateEvent.SubmittedTask);
            taskState.MoveNext(TaskStateEvent.RunningTask);
            Assert.True(taskState.MoveNext(TaskStateEvent.FailedTaskEvaluatorError).Equals(TaskState.TaskFailedByEvaluatorFailure), "Failed to move from RunningTask to TaskFailedByEvaluatorFailure state with FailedTaskEvaluatorError.");
            Assert.True(taskState.IsFinalState(), "TaskFailedByEvaluatorFailure should be a final state.");
        }
        public void TestRunningToCloseToFailedTaskSystemErrorScenario()
        {
            var taskState = new TaskStateMachine();

            taskState.MoveNext(TaskStateEvent.SubmittedTask);
            taskState.MoveNext(TaskStateEvent.RunningTask);
            taskState.MoveNext(TaskStateEvent.WaitingTaskToClose);
            Assert.True(taskState.MoveNext(TaskStateEvent.FailedTaskSystemError).Equals(TaskState.TaskClosedByDriver), "Failed to move from WaitingTaskToClose to TaskClosedByDriver state with FailedTaskSystemError.");
        }
        public void TestRunningToWaitingTaskToCloseToComplete()
        {
            var taskState = new TaskStateMachine();

            taskState.MoveNext(TaskStateEvent.SubmittedTask);
            taskState.MoveNext(TaskStateEvent.RunningTask);
            taskState.MoveNext(TaskStateEvent.WaitingTaskToClose);
            taskState.MoveNext(TaskStateEvent.CompletedTask);
            Assert.Equal(TaskState.TaskClosedByDriver, taskState.CurrentState);
        }
        public void TestRunningToCloseScenario()
        {
            var taskState = new TaskStateMachine();

            taskState.MoveNext(TaskStateEvent.SubmittedTask);
            taskState.MoveNext(TaskStateEvent.RunningTask);
            Assert.True(taskState.MoveNext(TaskStateEvent.WaitingTaskToClose).Equals(TaskState.TaskWaitingForClose), "Failed to move from RunningTask to TaskWaitingForClose state.");
            Assert.False(taskState.IsFinalState(), "TaskWaitingForClose should not be a final state.");
            Assert.True(taskState.MoveNext(TaskStateEvent.ClosedTask).Equals(TaskState.TaskClosedByDriver), "Failed to move from TaskWaitingForClose to TaskClosedByDriver state.");
            Assert.True(taskState.IsFinalState(), "TaskClosedByDriver should be a final state.");
        }
        public void TestNewToCompleteScenario()
        {
            var taskState = new TaskStateMachine();

            Assert.True(taskState.CurrentState.Equals(TaskState.TaskNew), "State of newly created task should be TaskNew");
            Assert.False(taskState.IsFinalState(), "TaskNew should not be a final state.");
            Assert.True(taskState.MoveNext(TaskStateEvent.SubmittedTask).Equals(TaskState.TaskSubmitted), "Failed to move from TaskNew to TaskSubmitted state.");
            Assert.False(taskState.IsFinalState(), "TaskSubmitted should not be a final state.");
            Assert.True(taskState.MoveNext(TaskStateEvent.RunningTask).Equals(TaskState.TaskRunning), "Failed to move from TaskSubmitted to TaskRunning state.");
            Assert.False(taskState.IsFinalState(), "TaskRunning should not be a final state.");
            Assert.True(taskState.MoveNext(TaskStateEvent.CompletedTask).Equals(TaskState.TaskCompleted), "Failed to move from TaskRunning to TaskCompleted state.");
            Assert.True(taskState.IsFinalState(), "TaskCompleted should be a final state.");
        }
        public void TestFromRunningToNotAllowedTransitions()
        {
            var taskState = new TaskStateMachine();

            taskState.MoveNext(TaskStateEvent.SubmittedTask);
            taskState.MoveNext(TaskStateEvent.RunningTask);

            Action moveNext = () => taskState.MoveNext(TaskStateEvent.SubmittedTask);

            Assert.Throws <TaskStateTransitionException>(moveNext);

            moveNext = () => taskState.MoveNext(TaskStateEvent.ClosedTask);
            Assert.Throws <TaskStateTransitionException>(moveNext);
        }
        public void TestFromFailToNotAllowedTransitions()
        {
            var taskState = new TaskStateMachine();

            taskState.MoveNext(TaskStateEvent.SubmittedTask);
            taskState.MoveNext(TaskStateEvent.RunningTask);

            taskState.MoveNext(TaskStateEvent.FailedTaskEvaluatorError);
            Assert.True(taskState.CurrentState.Equals(TaskState.TaskFailedByEvaluatorFailure), "Failed to move to TaskFailedByEvaluatorFailure state.");

            Action moveNext = () => taskState.MoveNext(TaskStateEvent.RunningTask);

            Assert.Throws <TaskStateTransitionException>(moveNext);

            moveNext = () => taskState.MoveNext(TaskStateEvent.ClosedTask);
            Assert.Throws <TaskStateTransitionException>(moveNext);

            moveNext = () => taskState.MoveNext(TaskStateEvent.CompletedTask);
            Assert.Throws <TaskStateTransitionException>(moveNext);

            moveNext = () => taskState.MoveNext(TaskStateEvent.SubmittedTask);
            Assert.Throws <TaskStateTransitionException>(moveNext);

            moveNext = () => taskState.MoveNext(TaskStateEvent.WaitingTaskToClose);
            Assert.Throws <TaskStateTransitionException>(moveNext);

            moveNext = () => taskState.MoveNext(TaskStateEvent.FailedTaskAppError);
            Assert.Throws <TaskStateTransitionException>(moveNext);

            moveNext = () => taskState.MoveNext(TaskStateEvent.FailedTaskCommunicationError);
            Assert.Throws <TaskStateTransitionException>(moveNext);

            moveNext = () => taskState.MoveNext(TaskStateEvent.FailedTaskSystemError);
            Assert.Throws <TaskStateTransitionException>(moveNext);
        }