示例#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);
            }
        }
示例#2
0
 public void ListTags(TagList tagList, TaskList tasklist)
 {
     TaskTagger tagTasks = new TaskTagger(tasklist.GetTasks());
     Console.WriteLine("Tags and the number of tasks they are assigned to:");
     foreach (Tag tg in tagList)
         Console.Write(tg.Name + ":" + tagTasks.CountTag(tg.Name) + " ");
     Console.WriteLine();
 }
示例#3
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 ItShouldAddDueDateToTaskList()
 {
     var testAddCommand = new AddCommand();
     var arguments = new ArgumentList(new string[] { "add", "I added something", "2/7/2016" }, new string[] { "add" });
     var taskList = new TaskList();
     testAddCommand.Execute(arguments, taskList, new TagList(), new TagFolder());
     string actual = taskList.GetTask(0).DueDate.Date.ToString("d");
     string expected = "2/7/2016";
     Assert.AreEqual(expected, actual);
 }
 public void ItShouldAddToTaskList()
 {
     var testAddCommand = new AddCommand();
     var arguments = new ArgumentList(new string[] { "add", "I added something" }, new string[] { "add" });
     var taskList = new TaskList();
     testAddCommand.Execute(arguments, taskList, new TagList(), new TagFolder());
     string actual = taskList.GetTask(0).TaskDescription;
     string expected = "I added something";
     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);
 }
示例#7
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);
 }
示例#8
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);
 }
示例#9
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);
 }
示例#10
0
 public static void Main(string[] args)
 {
     try
     {
         var commands = new string[] { "add", "done", "remove", "--help", "list", "filter", "change", "due", "tag", "untag", "delete", "filterTag", "folder", "filterFolder" };
         var arguments = new ArgumentList(args, commands);
         var taskList = new TaskList();
         var tagList = new TagList();
         var tagFolder = new TagFolder();
         var loader = new FileIO();
         loader.LoadTasks(taskList);
         loader.LoadTags(ref tagList);
         loader.LoadFolder(ref tagFolder);
         var dictionary = new Dictionary<string, ICommand>();
         dictionary.Add(commands[0], new AddCommand());
         dictionary.Add(commands[1], new DoneCommand());
         dictionary.Add(commands[2], new RemoveCommand());
         dictionary.Add(commands[3], new HelpCommand());
         dictionary.Add(commands[4], new ListCommand());
         dictionary.Add(commands[5], new FilterCommand());
         dictionary.Add(commands[6], new ChangeCommand());
         dictionary.Add(commands[7], new DueCommand());
         dictionary.Add(commands[8], new TagCommand());
         dictionary.Add(commands[9], new UntagCommand());
         dictionary.Add(commands[10], new DeleteCommand());
         dictionary.Add(commands[11], new FilterTagCommand());
         dictionary.Add(commands[12], new FolderCommand());
         dictionary.Add(commands[13], new FilterFolderCommand());
         var invoker = new Invoker(dictionary);
             ICommand command = invoker.GetCommand(arguments.GetCommand());
             command.Execute(arguments, taskList, tagList, tagFolder);
     }
     catch (ArgumentException)
     {
         Console.WriteLine("Invalid Command");
     }
     catch (IndexOutOfRangeException)
     {
         DisplayHelp();
     }
     catch (FormatException)
     {
         Console.WriteLine("Invalid date entered");
     }
 }
示例#11
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);
 }
示例#12
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);
 }
示例#13
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);
 }
示例#14
0
 public void ItShouldFilterTasksThatArePastDue()
 {
     var testAddCommand = new AddCommand();
     var arguments1 = new ArgumentList(new string[] { "add", "I added something", DateTime.Today.ToString("d") }, new string[] { "add" });
     var arguments2 = new ArgumentList(new string[] { "add", "I added something else", "1/7/2016" }, new string[] { "add" });
     var taskList = new TaskList();
     testAddCommand.Execute(arguments1, taskList, new TagList(), new TagFolder());
     testAddCommand.Execute(arguments2, taskList, new TagList(), new TagFolder());
     var actual = taskList.FilterDue("past")[0].TaskDescription;
     var expected = "I added something else";
     Assert.AreEqual(expected, actual);
 }
示例#15
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);
 }
示例#16
0
 public void ItShouldAddtoTaskList()
 {
     TaskList test = new TaskList();
     test.AddTask("Create first test");
 }
示例#17
0
 public void ListTags(TagList tagList, TaskList tasklist)
 {
     TaskTagger tagTasks = new TaskTagger(tasklist.GetTasks());
     FileStream fs = new FileStream(@"Export.html", FileMode.Create);
     StreamWriter sw = new StreamWriter(fs);
     sw.Write("<h2> Tags and the number of tasks they are assigned to: </h2>");
     sw.Write("<ul>");
     foreach (Tag tg in tagList)
         sw.Write("<li>" + tg.Name + ": " + tagTasks.CountTag(tg.Name) + "</li>");
     sw.Write("</ul>");
     sw.Close();
     Process.Start("IExplore.exe", Directory.GetCurrentDirectory() + "\\Export.html");
 }
示例#18
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);
 }
示例#19
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);
 }