diff --git a/domain-model.md b/domain-model.md new file mode 100644 index 00000000..b7005375 --- /dev/null +++ b/domain-model.md @@ -0,0 +1,48 @@ +## Calculator Project + +# User Stories + + + +-I want to add tasks to my todo list. + +-I want to see all the tasks in my todo list. + +-I want to change the status of a task between incomplete and complete. + +-I want to be able to get only the complete tasks. + +-I want to be able to get only the incomplete tasks. + +-I want to search for a task and receive a message that says it wasn't found if it doesn't exist. + +-I want to remove tasks from my list. + +-I want to see all the tasks in my list ordered alphabetically in ascending order. + +-I want to see all the tasks in my list ordered alphabetically in descending order. + +-I want to be able to get a task by a unique ID. + +-I want to update the name of a task by providing its ID and a new name. + +-I want to be able to change the status of a task by providing its ID. + +-I want to be able to see the date and time that I created each task. + + + +| Classes | Methods/Properties | Scenario | Outputs | +|-----------------|----------------------------------------------------|---------------------------------|------------------ +|ToDoList.cs |AddTask(string task) |add task to task list |an extra task in the task list +|ToDoList.cs |ShowList() |shows all tasks in list |presentation of all the tasks in the list +|ToDoList.cs |changeStatus(string task) |change to(complete/incomplete) | +|ToDoList.cs |GetCompletedTasks() |finds complete tasks complete tasks +|ToDoList.cs |GetIncompletedTasks() |finds incomplete tasks |incomplete tasks +|ToDoList.cs |SearchTask(string task) |checks if task exists |message if it does not exist +|ToDoList.cs |RemoveTask(string task) |removes a given task | +|ToDoList.cs |SortAlphabeticalAscendingO() |orders alphabetically(ascending) |tasks in ascending alphabetical order +|ToDoList.cs |SortAlphabeticalDescendingO() |orders alphabetically(descending)|tasks in descending alphabetical order +|ToDoListExtension.cs |GetTaskById(int id) |returns a task by giving an id | +|ToDoListExtension.cs |UpdateName(int id, string name) |changes name of the task with the given id | +|ToDoListExtension.cs |UpdateStatusById(int id) |updates status on the task with the given id| diff --git a/tdd-todo-list.CSharp.Main/Extension.cs b/tdd-todo-list.CSharp.Main/Extension.cs index e4c08912..c406ec96 100644 --- a/tdd-todo-list.CSharp.Main/Extension.cs +++ b/tdd-todo-list.CSharp.Main/Extension.cs @@ -1,12 +1,187 @@ -using System; + +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Xml.Linq; + + namespace tdd_todo_list.CSharp.Main { public class TodoListExtension { + List todolist = new List(); + int idcounter = 0; + public string AddTask(string name) + { + ToDoTask task = new ToDoTask(); + task.Name = name; + task.Id = idcounter++; + todolist.Add(task); + return todolist.Last().Name; + + + + } + + public string ChangeStatus(string name) + + { + + ToDoTask? task = todolist.Find(x => x.Name == name); + if (task != null) + { + if (task.Status == "incomplete") + { + task.Status = "complete"; + return task.Status; + + } + else + { + task.Status = "incomplete"; + return task.Status; + + + + } + } + return "did not exist in list"; + + + } + + public List GetCompletedList() + { + List completedList = new List(); + + foreach (ToDoTask task in todolist) + { + if (task.Status == "complete") + { + completedList.Add(task); + + } + } + return completedList; + } + + public List GetIncompletedList() + { + List incompletedList = new List(); + + foreach (ToDoTask task in todolist) + { + if (task.Status == "incomplete") + { + incompletedList.Add(task); + + } + } + return incompletedList; + } + + + public int ListSize() + { + return todolist.Count; + } + + public string RemoveTask(string taskname) + { + ToDoTask? taskToRemove = todolist.Find(task => task.Name == taskname); + if (taskToRemove != null) + { + todolist.Remove(taskToRemove); + return taskToRemove.Name; + } + return "fantes ikke i listen"; + } + + public string SearchTask(string taskname) + { + + ToDoTask? task = todolist.Find(x => x.Name == taskname); + if (task != null) + { + return task.Name; + + } + return "this task does not exist"; + } + + public string ShowList() + + { + string allTasks = ""; + foreach (ToDoTask task in todolist) + { + + allTasks += " " + task.Name + ": " + task.Status + "\n"; + + } + Console.WriteLine(allTasks); + + + + return allTasks; + + } + + public List SortAlphabetical() + + { + List sorted = todolist.OrderBy(x => x.Name).ToList(); + return sorted; + } + + public List SortAlphabeticalDescending() + { + List sorted = todolist.OrderByDescending(x => x.Name).ToList(); + return sorted; + } + public string getTaskById(int id) + { + ToDoTask? task = todolist.Find(x => x.Id == id); + foreach (ToDoTask todo in todolist) + { + Console.WriteLine(todo.Id); + } + + if (task != null) + { + return task.Name; + } + return "this id does not exist!"; + + } + + public void UpdateName(int id, string name) + { + ToDoTask? task = todolist.Find(x => x.Id == id); + if (task!= null) + { + task.Name = name; + } + + + } + public String UpdateStatusById(int id) + { + ToDoTask? task = todolist.Find(x => x.Id == id); + if (task != null) + { + ChangeStatus(task.Name); + return task.Status; + } + return "the id does not exist"; + + } + + + + } } diff --git a/tdd-todo-list.CSharp.Main/ToDoList.cs b/tdd-todo-list.CSharp.Main/ToDoList.cs index 835cb600..36ecbec4 100644 --- a/tdd-todo-list.CSharp.Main/ToDoList.cs +++ b/tdd-todo-list.CSharp.Main/ToDoList.cs @@ -3,10 +3,143 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Xml.Linq; namespace tdd_todo_list.CSharp.Main { public class TodoList + { + List todolist = new List(); + + public string AddTask(string name) + { + ToDoTask task = new ToDoTask(); + task.Name = name; + todolist.Add(task); + + return todolist.Last().Name; + + + + } + + public string ChangeStatus(string name) + + { + + ToDoTask? task = todolist.Find(x => x.Name == name); + if (task != null) { + if (task.Status == "incomplete") + { + task.Status = "complete"; + return task.Status; + + } + else + { + task.Status = "incomplete"; + return task.Status; + + + + } + } + return "did not exist in list"; + + + } + + public List GetCompletedList() + { + List completedList = new List(); + + foreach (ToDoTask task in todolist) + { + if (task.Status == "complete") + { + completedList.Add(task); + + } + } + return completedList; + } + + public List GetIncompletedList() + { + List incompletedList = new List(); + + foreach (ToDoTask task in todolist) + { + if (task.Status == "incomplete") + { + incompletedList.Add(task); + + } + } + return incompletedList; + } + + + + public int ListSize() + { + return todolist.Count; + } + + public string RemoveTask(string taskname) + { + ToDoTask? taskToRemove = todolist.Find(task => task.Name == taskname); + if (taskToRemove != null) + { + todolist.Remove(taskToRemove); + return taskToRemove.Name; + } + return "fantes ikke i listen"; + } + + public string SearchTask(string taskname) + { + + ToDoTask? task = todolist.Find(x => x.Name == taskname); + if (task != null) + { + return task.Name; + + } + return "this task does not exist"; + } + + public string ShowList() + + { + string allTasks = ""; + foreach (ToDoTask task in todolist) + { + + allTasks += " " +task.Name +": " + task.Status+ "\n"; + + } + Console.WriteLine(allTasks); + + + + return allTasks; + + } + + public List SortAlphabetical() + + { + List sorted = todolist.OrderBy(x => x.Name).ToList(); + return sorted; + } + + public List SortAlphabeticalDescending() + { + List sorted = todolist.OrderByDescending(x => x.Name).ToList(); + return sorted; + } + } } diff --git a/tdd-todo-list.CSharp.Main/ToDoTask.cs b/tdd-todo-list.CSharp.Main/ToDoTask.cs new file mode 100644 index 00000000..eea00f49 --- /dev/null +++ b/tdd-todo-list.CSharp.Main/ToDoTask.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace tdd_todo_list.CSharp.Main +{ + public class ToDoTask + + { + string name = ""; + + int id = 0; + string status; + DateTime now = DateTime.Now; + + public ToDoTask() + { + status = "incomplete"; + Console.WriteLine(now.ToString()); + + + } + public int Id + { + get { return id; } + set { id = value; } + } + + + public string Name + { + get { return name; } + set { name = value; } + } + + public string Status + { + get { return status; } + set { status = value; } + } + } +} diff --git a/tdd-todo-list.CSharp.Test/CoreTests.cs b/tdd-todo-list.CSharp.Test/CoreTests.cs index 084cce19..4270f0e1 100644 --- a/tdd-todo-list.CSharp.Test/CoreTests.cs +++ b/tdd-todo-list.CSharp.Test/CoreTests.cs @@ -1,5 +1,6 @@ using tdd_todo_list.CSharp.Main; using NUnit.Framework; +using System.Diagnostics.CodeAnalysis; namespace tdd_todo_list.CSharp.Test { @@ -8,10 +9,228 @@ public class CoreTests { [Test] - public void FirstTest() + public void addingTasks() { TodoList core = new TodoList(); - Assert.Pass(); + + core.AddTask("clean your room"); + int result = core.ListSize(); + int expected = 1; + + + + Assert.IsTrue(result == expected); + } + + [Test] + public void viewTasks() + { + TodoList core = new TodoList(); + + + core.AddTask("clean your room"); + core.AddTask("do dishes"); + core.AddTask("do homework"); + core.AddTask("do groceries"); + core.ChangeStatus("do dishes"); + + string result = core.ShowList(); + string expected = + + " clean your room: incomplete\n" + " " + + "do dishes: complete\n" + " " + + "do homework: incomplete\n" + " " + + "do groceries: incomplete\n"; + + + + Assert.IsTrue(result == expected); + } + [Test] + + public void SetStatus() + { + TodoList core = new TodoList(); + core.AddTask("clean your room"); + core.AddTask("do dishes"); + core.AddTask("do homework"); + core.AddTask("do groceries"); + string result = core.ChangeStatus("do homework"); + result = core.ChangeStatus("do homework"); + string expected = "incomplete"; + Assert.IsTrue(result == expected); + + } + + [Test] + public void OnlyCompleted() + { + //arrange + TodoList core = new TodoList(); + + + //action + core.AddTask("clean your room"); + core.AddTask("do dishes"); + core.AddTask("do homework"); + core.AddTask("do groceries"); + + core.ChangeStatus("clean your room"); + core.ChangeStatus("do homework"); + core.ChangeStatus("do groceries"); + + List result = core.GetCompletedList(); + + + + + + + Assert.That(result.Count == 3); + + + + + } + [Test] + public void OnlyInCompleted() + { + //arrange + TodoList core = new TodoList(); + + + //action + core.AddTask("clean your room"); + core.AddTask("do dishes"); + core.AddTask("do homework"); + core.AddTask("do groceries"); + + core.ChangeStatus("clean your room"); + core.ChangeStatus("do homework"); + core.ChangeStatus("do groceries"); + + core.ChangeStatus("do homework"); + core.ChangeStatus("do groceries"); + + List result = core.GetIncompletedList(); + + + Assert.That(result.Count == 3); + + } + + [Test] + public void TaskNotExists() + { + TodoList core = new TodoList(); + core.AddTask("clean your room"); + core.AddTask("do dishes"); + core.AddTask("do homework"); + core.AddTask("do groceries"); + string taskname = "do push ups"; + + + string result = core.SearchTask(taskname); + string expected = "this task does not exist"; + + Assert.That(result == expected); + + } + [Test] + public void TaskExists() + { + TodoList core = new TodoList(); + core.AddTask("clean your room"); + core.AddTask("do dishes"); + core.AddTask("do homework"); + core.AddTask("do groceries"); + string taskname = "do groceries"; + + + string result = core.SearchTask(taskname); + string expected = "do groceries"; + + Assert.That(result == expected); + + } + [Test] + public void RemovingFromList() + { + TodoList core = new TodoList(); + core.AddTask("clean your room"); + core.AddTask("do dishes"); + core.AddTask("do homework"); + core.AddTask("do groceries"); + string expected = "do dishes"; + + + string result = core.RemoveTask("do dishes"); + + Assert.That(result == expected && core.ListSize() == 3); + + + } + [Test] + + public void AlphabeticalAscending() + { + TodoList core = new TodoList(); + core.AddTask("clean your room"); + core.AddTask("do dishes"); + core.AddTask("a little nap"); + core.AddTask("do groceries"); + + List tempresult = core.SortAlphabetical(); + List result = new List(); + + foreach (ToDoTask task in tempresult) + { + result.Add(task.Name); + } + + + List expected = new List() + { + "a little nap", + "clean your room", + "do dishes", + "do groceries", + }; + Assert.AreEqual(expected, result); + + + + } + [Test] + public void AlphabeticalDescending() + { + TodoList core = new TodoList(); + core.AddTask("clean your room"); + core.AddTask("do dishes"); + core.AddTask("a little nap"); + core.AddTask("do groceries"); + + List tempresult = core.SortAlphabeticalDescending(); + List result = new List(); + + foreach (ToDoTask task in tempresult) + { + result.Add(task.Name); + } + + + List expected = new List() + { + + "do groceries", + "do dishes", + "clean your room", + "a little nap", + }; + Assert.AreEqual(expected, result); + + } } -} \ No newline at end of file + + } \ No newline at end of file diff --git a/tdd-todo-list.CSharp.Test/ExtensionTests.cs b/tdd-todo-list.CSharp.Test/ExtensionTests.cs index bdc82ad7..9daf1b6f 100644 --- a/tdd-todo-list.CSharp.Test/ExtensionTests.cs +++ b/tdd-todo-list.CSharp.Test/ExtensionTests.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using NUnit.Framework; namespace tdd_todo_list.CSharp.Test { @@ -14,5 +15,53 @@ public ExtensionTests() { _extension = new TodoListExtension(); } + [Test] + public void IdCheck() + { + TodoListExtension extension= new TodoListExtension(); + + extension.AddTask("clean your room"); + + extension.AddTask("do dishes"); + extension.AddTask("do homework"); + extension.AddTask("do groceries"); + string expected = "do homework"; + + String result = extension.getTaskById(2); + Assert.That(result, Is.EqualTo(expected)); + + + + + + } + + [Test] + public void NameCheck() + { + TodoListExtension extension = new TodoListExtension(); + String expected = "skip breakfast"; + extension.AddTask("wake up"); + extension.AddTask("brush teeth"); + extension.AddTask("eat breakfast"); + extension.UpdateName(2, "skip breakfast"); + String result=extension.getTaskById(2); + + Assert.That (result, Is.EqualTo(expected)); + + } + [Test] + public void TestChangeStatusById() + { + TodoListExtension extension = new TodoListExtension(); + String expected = "complete"; + extension.AddTask("wake up"); + extension.AddTask("brush teeth"); + extension.AddTask("eat breakfast"); + String result = extension.UpdateStatusById(1); + + + Assert.That(result == expected); + } } } diff --git a/tdd-todo-list.sln b/tdd-todo-list.sln index 66d24763..2a5e0bbd 100644 --- a/tdd-todo-list.sln +++ b/tdd-todo-list.sln @@ -10,6 +10,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{663B0373-6031-46F8-ADD5-9AF01A5E82D5}" ProjectSection(SolutionItems) = preProject .github\workflows\core-criteria.yml = .github\workflows\core-criteria.yml + domain-model.md = domain-model.md .github\workflows\extension-criteria.yml = .github\workflows\extension-criteria.yml README.md = README.md EndProjectSection