public void ZTaskStack_PullDangerTasks()
        {
            // Arrange
            ZTaskStack testStack = new ZTaskStack();

            testStack.PushAll(tasks);
            IEnumerable <ITask> dangers = tasks.Where(t =>
            {
                ZScheduledTask st = t as ZScheduledTask;
                if (st != null && st.IsInDanger())
                {
                    return(true);
                }
                return(false);
            });
            int numOfDangers = dangers.Count();

            // Assume
            Assume.That(testStack.PeekAll(), Is.EquivalentTo(tasks));

            // Act
            testStack.PullDangerTasks();

            // Assert
            var actual = testStack.PeekTasks(numOfDangers);

            Assert.That(actual, Is.EquivalentTo(dangers));
        }
Пример #2
0
        /// <summary>
        /// Reasd a task from console, and if successful pushes
        /// the task to the manager.
        /// </summary>
        /// <param name="scheduled"></param>
        /// <param name="priority"></param>
        /// <returns></returns>
        public ConsoleStatus GetTask(bool scheduled, bool priority)
        {
            ConsoleStatus status;

            status = GetTitle(out string title);
            if (Bad(status))
            {
                return(status);
            }

            status = GetDescription(out string description);
            if (Bad(status))
            {
                return(status);
            }

            if (scheduled)
            {
                status = GetDeadline(out DateTime? deadline_wrapper);
                if (Bad(status))
                {
                    return(status);
                }

                status = GetBuffer(out TimeSpan? buffer_wrapper);
                if (Bad(status))
                {
                    return(status);
                }

                // Creating and pushing a scheduled task
                var task_scheduled = new ZScheduledTask()
                {
                    Title       = title,
                    Description = description,
                    Deadline    = deadline_wrapper.Value,
                    ZBuffer     = buffer_wrapper.Value
                };

                if (priority)
                {
                    manager.PushTaskWithPriority(task_scheduled);
                }
                else
                {
                    manager.PushTask(task_scheduled);
                }
            }
            else
            {
                manager.PushTask(new ZTask()
                {
                    Title       = title,
                    Description = description,
                });
            }

            return(status);
        }
        public void SetUpFixture()
        {
            task = new ZTask()
            {
                Title       = ZTestUtil.TestTitle,
                Description = ZTestUtil.TestDescription
            };

            scheduledTask = new ZScheduledTask()
            {
                Title       = ZTestUtil.TestTitle,
                Description = ZTestUtil.TestDescription,
                Deadline    = DateTime.Now,
                ZBuffer     = TimeSpan.FromMinutes(50)
            };
        }
        public void ZTaskManager_GetAndUpdateCurrentTask()
        {
            // Arrange
            foreach (ITask task in tasks)
            {
                manager.PushTask(task);
            }

            ITask          lastTask   = tasks[tasks.Count - 1];
            ZScheduledTask mostUrgent = pTasks[0];

            // Select the most urgent task
            int priorityListLength = pTasks.Count;

            for (int i = 1; i < priorityListLength; ++i)
            {
                if (pTasks[i].GetUrgentDate() < mostUrgent.GetUrgentDate())
                {
                    mostUrgent = pTasks[i];
                }
            }


            // Assume
            Assume.That(manager.CurrentTask, Is.EqualTo(lastTask));

            // Act I - push priority
            foreach (var task in pTasks) // tasks with priority
            {
                manager.PushTaskWithPriority(task);
            }

            // Assert I - Current Task is still stale
            Assert.That(manager.CurrentTask, Is.EqualTo(lastTask));

            // Act II - update Current Task
            manager.Update();

            // Assert II - Current Task is updated
            Assert.That(manager.CurrentTask, Is.EqualTo(mostUrgent));
        }
        public void PrintCurrentTask()
        {
            PrintBright(FormatUtil.BreakLine);
            if (manager.CurrentTaskIsPrioritized)
            {
                PrintWarning(FormatUtil.PrioritizedLabel);
            }
            ZScheduledTask sCur = manager.CurrentTask as ZScheduledTask;

            if (sCur != null)
            {
                if (sCur.IsInDanger())
                {
                    PrintWarning(FormatUtil.UrgentLabel);
                }
                else if (sCur.IsInDanger())
                {
                    PrintWarning(FormatUtil.DangerLabel);
                }
            }
            PromptBright(manager.CurrentTask.ToString());
            PrintBright(FormatUtil.BreakLine);
        }
        public ConsoleStatus ResetCurrentTaskBuffer()
        {
            // Setting conditions for buffer-resetting
            if (manager.CurrentTaskNotLoaded)
            {
                throw new Exception(ZTaskManager.YouHaveNotLoadedACurrentTask);
            }
            else
            {
                ZScheduledTask scheduled = manager.CurrentTask as ZScheduledTask;
                if (scheduled == null)
                {
                    throw new Exception($"Task '{manager.CurrentTask.Title}' is not scheduled!");
                }

                // Gather information from the task
                string   title      = scheduled.Title;
                TimeSpan buffer_old = scheduled.ZBuffer;

                // Read new buffer
                ConsoleStatus status = reader.GetTimeSpan(out TimeSpan? newBuffer, "Enter the new buffer (1.hh:mm:ss:00:00): ");
                if (Bad(status))
                {
                    if (status == ConsoleStatus.Cancel)
                    {
                        Print("Operation Cancelled ...");
                    }
                    return(status);
                }

                // Reset Buffer, Print Message and Return OK
                scheduled.ResetBuffer(newBuffer.Value);
                Print($"Task '{title}' has been stretched from {buffer_old.ToString()} to {scheduled.ZBuffer.ToString()}");

                return(ConsoleStatus.OK);
            }
        }
        /// <summary>
        /// Stretches the deadline of the current task.
        /// Message: task '{taskName}' has been stretched from '{originalTime}'
        /// to '{newTime}' ...
        /// </summary>
        /// <param name="commands"></param>
        /// <returns></returns>
        public ConsoleStatus StretchCurrentTaskDeadline()
        {
            // Setting conditions for deadline-stretching
            if (manager.CurrentTaskNotLoaded)
            {
                throw new Exception(ZTaskManager.YouHaveNotLoadedACurrentTask);
            }
            else
            {
                ZScheduledTask scheduled = manager.CurrentTask as ZScheduledTask;
                if (scheduled == null)
                {
                    throw new Exception($"Task '{manager.CurrentTask.Title}' is not scheduled!");
                }

                // Gather information from the task
                string   title        = scheduled.Title;
                DateTime deadline_old = scheduled.Deadline;

                // Get the time from console and check status
                ConsoleStatus status = reader.GetTimeSpan(out TimeSpan? stretch, "Enter the time span that you wish to stretch (dd.hh:mm:ss:00:00): ");
                if (Bad(status))
                {
                    if (status == ConsoleStatus.Cancel)
                    {
                        Print("Operation Cancelled ...");
                    }
                    return(status);
                }

                // Put off current task by the value, print message and return
                scheduled.PutOff(stretch.Value);
                Print($"Task '{title}' has been stretched from {deadline_old.ToString("o")} to {scheduled.Deadline.ToString("o")}");

                return(ConsoleStatus.OK);
            }
        }
        /// <summary>
        /// Resets the deadline of the current task
        /// </summary>
        /// <returns>Console Task</returns>
        public ConsoleStatus ResetCurrentTaskDeadline()
        {
            // Setting conditions for deadline-resetting
            if (manager.CurrentTaskNotLoaded)
            {
                throw new Exception(ZTaskManager.YouHaveNotLoadedACurrentTask);
            }
            else
            {
                ZScheduledTask scheduled = manager.CurrentTask as ZScheduledTask;
                if (scheduled == null)
                {
                    throw new Exception($"Task '{manager.CurrentTask.Title}' is not scheduled!");
                }

                // Gather information from the task
                string   title        = scheduled.Title;
                DateTime deadline_old = scheduled.Deadline;

                // Read new deadline
                ConsoleStatus status = reader.GetDeadline(out DateTime? deadline);
                if (Bad(status))
                {
                    if (status == ConsoleStatus.Cancel)
                    {
                        Print("Operation Cancelled ...");
                    }
                    return(status);
                }

                scheduled.ResetDeadline(deadline.Value);
                Print($"Task '{title}'s Deadline has been reset from {deadline_old.ToString("o")} to {scheduled.Deadline.ToString("o")}");

                return(ConsoleStatus.OK);
            }
        }
Пример #9
0
        public void PriorityList_GetMostUrgentTask(string method)
        {
            // Arrange
            var            getFunc    = SelectViewMethod(method);
            ZPriorityList  pList      = new ZPriorityList();
            ZScheduledTask mostUrgent = pTasks[0];

            for (int i = 1; i < pTasks.Count; i++)
            {
                if (pTasks[i].GetUrgentDate() < mostUrgent.GetUrgentDate())
                {
                    mostUrgent = pTasks[i];
                }
            }

            // Assume
            Assume.That(mostUrgent, Is.EqualTo(pTasks[2])); // manually selected

            // Act
            PushAllTasks(pList, pTasks);

            // Assert
            Assert.That(getFunc(pList), Is.EqualTo(mostUrgent));
        }
 public void SetUpFixture()
 {
     task = new ZScheduledTask();
 }