Example #1
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 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));
        }