示例#1
0
        public void LoadTasks(TaskList taskList)
        {
            string[] lines = System.IO.File.ReadAllLines(@"List.txt");
            foreach (string line in lines)
            {
                Task task = new Task();
                var items = line.Split(';');
                task.TaskDescription = items[1];
                if (items[0] == "[X]")
                {
                    task.IsDone = true;
                }

                task.IsNewTask = false;
                task.TaskId = items[2];
                task.DueDate = Convert.ToDateTime(items[3]);
                task.DoneDate = Convert.ToDateTime(items[4]);
                int i = items.Length;
                TagList tags = new TagList();
                while (i > 5)
                {
                    Tag tag = new Tag(items[i - 1]);
                    tags.AddTag(ref tag);
                    i--;
                }

                task.TagList = tags;
                taskList.AddTask(ref task);
            }
        }
 public void Add(Task item)
 {
     item.IsNewTask = true;
        Tasks.AddTask(ref item);
        var loader = new FileIO();
        loader.SaveTasks(Tasks.GetTasks());
 }
示例#3
0
 public void AddTask(ref Task task)
 {
     if(task.IsNewTask)
         task.TaskId = Guid.NewGuid().ToString().Substring(0, 4);
         tasks.Add(task);
         size++;
 }
示例#4
0
 public void ItShouldAddTasks()
 {
     TaskList testList = new TaskList();
     Task testTask = new Task();
     testTask.TaskDescription = "First task";
     testList.AddTask(ref testTask);
     bool actual = testList.HasTask(testTask);
     bool expected = true;
     Assert.AreEqual(expected, actual);
 }
 public void ItShouldNotAddSameTaskToTaskList()
 {
     var testAddCommand = new AddCommand();
     var arguments = new ArgumentList(new string[] { "add", "I added something" }, new string[] { "add" });
     var taskList = new TaskList();
     Task testTask1 = new Task();
     testTask1.TaskDescription = "I added something";
     taskList.AddTask(ref testTask1);
     testAddCommand.Execute(arguments, taskList, new TagList(), new TagFolder());
     int actual = taskList.GetListSize();
     int expected = 1;
     Assert.AreEqual(expected, actual);
 }
示例#6
0
 public void ItShouldAssignTagToTask()
 {
     TaskList testList = new TaskList();
     Task testTask1 = new Task();
     testTask1.TaskDescription = "First task";
     testList.AddTask(ref testTask1);
     TaskTagger tagTasks = new TaskTagger(testList.GetTasks());
     tagTasks.AssignTag(testTask1.TaskId, "urgent");
     testList.SetTasks(tagTasks.GetTasks());
     string actual = testList.GetTask(0).TagList.GetTag(0).Name;
     string expected = "urgent";
     Assert.AreEqual(expected, actual);
 }
示例#7
0
 public void ItShouldChangeTasksDescription()
 {
     TaskList testList = new TaskList();
     Task testTask1 = new Task();
     testTask1.TaskDescription = "First task";
     Task testTask2 = new Task();
     testTask2.TaskDescription = "Second task";
     testList.AddTask(ref testTask1);
     testList.AddTask(ref testTask2);
     testList.ChangeTask(testTask1.TaskId, "Changed task", 0);
     string actual = testList.GetTask(0).TaskDescription;
     string expected = "Changed task";
     Assert.AreEqual(expected, actual);
 }
示例#8
0
 public void ItShouldAddDateToTasksMarkedAsDone()
 {
     TaskList testList = new TaskList();
     Task testTask1 = new Task();
     testTask1.TaskDescription = "First task";
     Task testTask2 = new Task();
     testTask2.TaskDescription = "Second task";
     testList.AddTask(ref testTask1);
     testList.AddTask(ref testTask2);
     testList.MarkAsDone(testTask1.TaskId);
     string actual = testList.GetTask(0).DoneDate.Date.ToString("d");
     string expected = DateTime.Today.Date.ToString("d");
     Assert.AreEqual(expected, actual);
 }
示例#9
0
 public bool HasTask(Task task)
 {
     return tasks.Contains(task);
 }
示例#10
0
 private static void ListPart(Task t, string part)
 {
     Console.Write(t.TaskDescription.Length <= 30 ? part : t.TaskDescription.Substring(0, 27) + "...");
 }
示例#11
0
 public void ItShouldChangeTasksDueDate()
 {
     TaskList testList = new TaskList();
     Task testTask1 = new Task();
     testTask1.DueDate = Convert.ToDateTime("2/21/2016");
     testList.AddTask(ref testTask1);
     testList.ChangeTask(testTask1.TaskId, "2/22/2016", 1);
     string actual = testList.GetTask(0).DueDate.Date.ToString("d");
     string expected = "2/22/2016";
     Assert.AreEqual(expected, actual);
 }
示例#12
0
 public void ItShouldRemoveTasks()
 {
     TaskList testList = new TaskList();
     Task testTask1 = new Task();
     testTask1.TaskDescription = "First task";
     Task testTask2 = new Task();
     testTask2.TaskDescription = "Second task";
     Task testTask3 = new Task();
     testTask3.TaskDescription = "Third task";
     testList.AddTask(ref testTask1);
     testList.AddTask(ref testTask2);
     testList.AddTask(ref testTask3);
     testList.RemoveTask(testTask2.TaskId);
     string actual = testList.GetTask(1).TaskDescription;
     string expected = "Third task";
     Assert.AreEqual(expected, actual);
 }
示例#13
0
 public void ItShouldMarkTasksAsDone()
 {
     TaskList testList = new TaskList();
     Task testTask1 = new Task();
     testTask1.TaskDescription = "First task";
     Task testTask2 = new Task();
     testTask2.TaskDescription = "Second task";
     testList.AddTask(ref testTask1);
     testList.AddTask(ref testTask2);
     testList.MarkAsDone(testTask1.TaskId);
     bool actual = testList.GetTask(0).IsDone;
     bool expected = true;
     Assert.AreEqual(expected, actual);
 }
示例#14
0
 public void ItShouldFilterTasksByTaglist()
 {
     TaskList testList = new TaskList();
     Task testTask1 = new Task();
     testTask1.TaskDescription = "First task";
     testTask1.TaskId = "AAAA";
     Task testTask2 = new Task();
     testTask2.TaskDescription = "Second";
     testTask2.TaskId = "BBBB";
     Task testTask3 = new Task();
     testTask3.TaskId = "CCCC";
     testTask3.TaskDescription = "Third task";
     testList.AddTask(ref testTask1);
     testList.AddTask(ref testTask2);
     testList.AddTask(ref testTask3);
     TaskTagger tagTasks = new TaskTagger(testList.GetTasks());
     tagTasks.AssignTag(testTask1.TaskId, "funny");
     tagTasks.AssignTag(testTask2.TaskId, "sad");
     tagTasks.AssignTag(testTask3.TaskId, "happy");
     testList.SetTasks(tagTasks.GetTasks());
     var taglist = new List<Tag>();
     Tag happy = new Tag("happy");
     Tag sad = new Tag("sad");
     taglist.Add(sad);
     taglist.Add(happy);
     List<Task> filteredList = testList.FilterByTagList(taglist);
     var actual = filteredList;
     var expected = new List<Task>();
     expected.Add(testList.GetTask(1));
     expected.Add(testList.GetTask(2));
     CollectionAssert.AreEqual(expected, actual);
 }
示例#15
0
 public void ItShouldFilterTasks()
 {
     TaskList testList = new TaskList();
     Task testTask1 = new Task();
     testTask1.TaskDescription = "First task";
     Task testTask2 = new Task();
     testTask2.TaskDescription = "Second";
     Task testTask3 = new Task();
     testTask3.TaskDescription = "Third task";
     testList.AddTask(ref testTask1);
     testList.AddTask(ref testTask2);
     testList.AddTask(ref testTask3);
     List<Task> filteredList = testList.FilterTasks("task");
     var actual = filteredList;
     var expected = new List<Task>();
     expected.Add(testTask1);
     expected.Add(testTask3);
     CollectionAssert.AreEqual(expected, actual);
 }
示例#16
0
 public void ItShouldDeleteTagFromEveryTask()
 {
     TaskList testList = new TaskList();
     Task testTask1 = new Task();
     testTask1.TaskDescription = "First task";
     testTask1.TaskId = "AAAA";
     testList.AddTask(ref testTask1);
     Task testTask2 = new Task();
     testTask2.TaskDescription = "Second task";
     testTask2.TaskId = "XXXX";
     testList.AddTask(ref testTask2);
     TaskTagger tagTasks = new TaskTagger(testList.GetTasks());
     tagTasks.AssignTag(testTask1.TaskId, "urgent");
     tagTasks.AssignTag(testTask1.TaskId, "important");
     tagTasks.AssignTag(testTask2.TaskId, "important");
     tagTasks.DeleteTag("important");
     testList.SetTasks(tagTasks.GetTasks());
     int actual = testList.GetTask(0).TagList.GetListSize()+testList.GetTask(1).TagList.GetListSize();
     int expected = 1;
     Assert.AreEqual(expected, actual);
 }