From 976ae360aa3f1c62c016c220894a8536018b909d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elisabeth=20R=C3=B8ysland?= Date: Mon, 11 Aug 2025 08:08:33 +0200 Subject: [PATCH] =?UTF-8?q?Elisabeth=20R=C3=B8ysland?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain-model.md | 79 +++++++ tdd-todo-list.CSharp.Main/Enums.cs | 15 ++ tdd-todo-list.CSharp.Main/TaskItem.cs | 16 ++ tdd-todo-list.CSharp.Main/ToDoList.cs | 20 ++ tdd-todo-list.CSharp.Test/CoreTests.cs | 224 +++++++++++++++++++- tdd-todo-list.CSharp.Test/ExtensionTests.cs | 2 + tdd-todo-list.sln | 1 + 7 files changed, 351 insertions(+), 6 deletions(-) create mode 100644 domain-model.md create mode 100644 tdd-todo-list.CSharp.Main/Enums.cs create mode 100644 tdd-todo-list.CSharp.Main/TaskItem.cs diff --git a/domain-model.md b/domain-model.md new file mode 100644 index 00000000..855c0577 --- /dev/null +++ b/domain-model.md @@ -0,0 +1,79 @@ +# Domain models + +## Core requirements + +1. I want to add tasks to my todo list. + +| Classes | Methods/Properties | Scenario | Outputs | +|-------------|--------------------|-----------------------------------|---------| +| ToDoList.cs | Add(TaskItem task) | Add task to List MyList | bool | + + +2. I want to see all the tasks in my todo list. + +| Classes | Methods/Properties | Scenario | Outputs | +|-------------|--------------------------------------------|-------------------------------------------|----------------| +| ToDoList.cs | public List MyList { get; set; } | Return all tasks in List MyList | List | + + +3. I want to change the status of a task between incomplete and complete. + +| Classes | Methods/Properties | Scenario | Outputs | +|-------------|---------------------------------------|-----------------------------------|---------| +| TaskItem.cs | public bool IsCompleted { get; set; } | Changes IsCompleted to true/false | bool | + + +4. I want to be able to get only the complete tasks. + +| Classes | Methods/Properties | Scenario | Outputs | +|-------------|----------------------------------------------------|--------------------------------|----------------| +| ToDoList.cs | public List CompletedTasks { get; set; } | Return all the completed tasks | List | + + +5. I want to be able to get only the incomplete tasks. + +| Classes | Methods/Properties | Scenario | Outputs | +|-------------|------------------------------------------------------|----------------------------------|----------------| +| ToDoList.cs | public List IncompletedTasks { get; set; } | Return all the incompleted tasks | List | + + +6. I want to search for a task and receive a message that says it wasn't found if it doesn't exist. + +| Classes | Methods/Properties | Scenario | Outputs | +|-------------|----------------------------------------|---------------------------------------|---------| +| ToDoList.cs | Search(TodoList todolist, string name) | Returns task name or "Task not found" | string | + + +7. I want to remove tasks from my list. + +| Classes | Methods/Properties | Scenario | Outputs | +|-------------|-----------------------|----------------------------------------|---------| +| ToDoList.cs | Remove(TaskItem task) | Remove task from List MyList | bool | + + +8. I want to see all the tasks in my list ordered alphabetically in ascending order. + +| Classes | Methods/Properties | Scenario | Outputs | +|-------------|----------------------------------------------------------|---------------------------------------------------|----------------| +| ToDoList.cs | public List TasksSortedAscending { get; set; } | Return the list in alphabetically ascending order | List | + + +9. I want to see all the tasks in my list ordered alphabetically in descending order. + +| Classes | Methods/Properties | Scenario | Outputs | +|-------------|-----------------------------------------------------------|----------------------------------------------------|----------------| +| ToDoList.cs | public List TasksSortedDescending { get; set; } | Return the list in alphabetically descending order | List | + + +10. I want to prioritise tasks e.g. low, medium, high + +| Classes | Methods/Properties | Scenario | Outputs | +|-------------|----------------------------------------|--------------------------------------------------|---------| +| TaskItem.cs | public Priority priority { get; set; } | Possible to set task to low/medium/high priority | bool | + + +11. I want to list all tasks by priority + +| Classes | Methods/Properties | Scenario | Outputs | +|-------------|-----------------------------------------------------------|-----------------------------------|----------------| +| ToDoList.cs | public List TasksSortedByPriority { get; set; } | Return the list in priority order | List | diff --git a/tdd-todo-list.CSharp.Main/Enums.cs b/tdd-todo-list.CSharp.Main/Enums.cs new file mode 100644 index 00000000..bf97947c --- /dev/null +++ b/tdd-todo-list.CSharp.Main/Enums.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace tdd_todo_list.CSharp.Main +{ + public enum Priority + { + High, + Medium, + Low + } +} diff --git a/tdd-todo-list.CSharp.Main/TaskItem.cs b/tdd-todo-list.CSharp.Main/TaskItem.cs new file mode 100644 index 00000000..96e5d587 --- /dev/null +++ b/tdd-todo-list.CSharp.Main/TaskItem.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace tdd_todo_list.CSharp.Main { + public class TaskItem + { + //public Guid Id { get; set; } = Guid.NewGuid(); + + public string Name { get; set; } + public bool IsCompleted { get; set; } = false; + public Priority Priority { get; set; } + } +} diff --git a/tdd-todo-list.CSharp.Main/ToDoList.cs b/tdd-todo-list.CSharp.Main/ToDoList.cs index 835cb600..2b4852fa 100644 --- a/tdd-todo-list.CSharp.Main/ToDoList.cs +++ b/tdd-todo-list.CSharp.Main/ToDoList.cs @@ -8,5 +8,25 @@ namespace tdd_todo_list.CSharp.Main { public class TodoList { + public List MyList { get; set; } = new List(); + + public List CompletedTasks { get { return MyList.Where(x => x.IsCompleted == true).ToList(); } } + public List IncompletedTasks { get { return MyList.Where(x => x.IsCompleted == false).ToList(); } } + + public List TasksSortedAscending { get { return MyList.OrderBy(x => x.Name).ToList(); } } + public List TasksSortedDescending { get { return MyList.OrderByDescending(x => x.Name).ToList(); } } + public List TasksSortedByPriority { get { return MyList.OrderBy(x => x.Priority).ToList(); } } + + public string Search(TodoList todolist, string name) + { + if(todolist.MyList.Any(t => t.Name == name)) + { + return name; + } + else + { + return "Task not found"; + } + } } } diff --git a/tdd-todo-list.CSharp.Test/CoreTests.cs b/tdd-todo-list.CSharp.Test/CoreTests.cs index 084cce19..291279c2 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 NUnit.Framework; +using System.Xml.Linq; +using tdd_todo_list.CSharp.Main; namespace tdd_todo_list.CSharp.Test { @@ -7,11 +8,222 @@ namespace tdd_todo_list.CSharp.Test public class CoreTests { + // 1. I want to add tasks to my todo list. [Test] - public void FirstTest() + public void AddTaskToToDoList() { - TodoList core = new TodoList(); - Assert.Pass(); + // arrange + TodoList todolist = new TodoList(); + var task = new TaskItem { Name = "Do the dishes" }; + + // act + todolist.MyList.Add(task); + + //assert + Assert.IsTrue(todolist.MyList.Count == 1); + Assert.That(todolist.MyList[0].Name, Is.EqualTo("Do the dishes")); + } + + // 2. I want to see all the tasks in my todo list. + [Test] + public void SeeAllTasksInToDoList() + { + // arrange + TodoList todolist = new TodoList(); + var task1 = new TaskItem { Name = "Do the dishes" }; + var task2 = new TaskItem { Name = "Clean the bathroom" }; + todolist.MyList.Add(task1); + todolist.MyList.Add(task2); + + //act + var result = todolist.MyList; + + //assert + Assert.IsTrue(todolist.MyList.Count == 2); + Assert.That(todolist.MyList[0].Name, Is.EqualTo(result[0].Name)); + Assert.That(todolist.MyList[1].Name, Is.EqualTo(result[1].Name)); + } + + // 3. I want to change the status of a task between incomplete and complete. + [Test] + public void ChangeStatusOfTask() + { + // arrange + TodoList todolist = new TodoList(); + var task1 = new TaskItem { Name = "Do the dishes" }; + var task2 = new TaskItem { Name = "Clean the bathroom", IsCompleted = true }; + todolist.MyList.Add(task1); + todolist.MyList.Add(task2); + + // act + todolist.MyList[0].IsCompleted = true; + todolist.MyList[1].IsCompleted = false; + + // assert + Assert.IsTrue(todolist.MyList[0].IsCompleted == true); + Assert.IsTrue(todolist.MyList[1].IsCompleted == false); + } + + // 4. I want to be able to get only the complete tasks. + [Test] + public void GetCompleteTasks() + { + // arrange + TodoList todolist = new TodoList(); + var task1 = new TaskItem { Name = "Do the dishes" }; + var task2 = new TaskItem { Name = "Clean the bathroom", IsCompleted = true }; + todolist.MyList.Add(task1); + todolist.MyList.Add(task2); + + // act + var result = todolist.CompletedTasks; + + // assert + Assert.IsTrue(result.Count == 1); + Assert.That(result[0].Name, Is.EqualTo(todolist.MyList[1].Name)); + } + + // 5. I want to be able to get only the incomplete tasks. + [Test] + public void GetInompleteTasks() + { + // arrange + TodoList todolist = new TodoList(); + var task1 = new TaskItem { Name = "Do the dishes" }; + var task2 = new TaskItem { Name = "Clean the bathroom", IsCompleted = true }; + todolist.MyList.Add(task1); + todolist.MyList.Add(task2); + + // act + var result = todolist.IncompletedTasks; + + // assert + Assert.IsTrue(result.Count == 1); + Assert.That(result[0].Name, Is.EqualTo(todolist.MyList[0].Name)); + } + + // 6. I want to search for a task and receive a message that says it wasn't found if it doesn't exist. + [Test] + public void SearchForTask() + { + // arrange + TodoList todolist = new TodoList(); + var task = new TaskItem { Name = "Do the dishes" }; + todolist.MyList.Add(task); + + // act + var result1 = todolist.Search(todolist, "Do the dishes"); + var result2 = todolist.Search(todolist, "Walk the dog"); + + // assert + Assert.IsTrue(result1 == "Do the dishes"); + Assert.IsTrue(result2 == "Task not found"); + } + + // 7. I want to remove tasks from my list. + [Test] + public void RemoveTaskFromToDoList() + { + // arrange + TodoList todolist = new TodoList(); + var task1 = new TaskItem { Name = "Do the dishes" }; + var task2 = new TaskItem { Name = "Clean the bathroom" }; + todolist.MyList.Add(task1); + todolist.MyList.Add(task2); + + // act + todolist.MyList.Remove(task1); + + //assert + Assert.IsTrue(todolist.MyList.Count == 1); + Assert.That(todolist.MyList[0].Name, Is.EqualTo("Clean the bathroom")); + } + + // 8. I want to see all the tasks in my list ordered alphabetically in ascending order. + [Test] + public void GetTasksAlphabeticallyInAscendingOrder() + { + // arrange + TodoList todolist = new TodoList(); + var task1 = new TaskItem { Name = "Do the dishes" }; + var task2 = new TaskItem { Name = "Clean the bathroom" }; + todolist.MyList.Add(task1); + todolist.MyList.Add(task2); + + // act + var result = todolist.TasksSortedAscending; + + // assert + Assert.IsTrue(result.Count == 2); + Assert.That(result[0].Name, Is.EqualTo(todolist.MyList[1].Name)); + Assert.That(result[1].Name, Is.EqualTo(todolist.MyList[0].Name)); + } + + // 9. I want to see all the tasks in my list ordered alphabetically in descending order. + [Test] + public void GetTasksAlphabeticallyInDescendingOrder() + { + // arrange + TodoList todolist = new TodoList(); + var task1 = new TaskItem { Name = "Clean the bathroom" }; + var task2 = new TaskItem { Name = "Do the dishes" }; + todolist.MyList.Add(task1); + todolist.MyList.Add(task2); + + // act + var result = todolist.TasksSortedDescending; + + // assert + Assert.IsTrue(result.Count == 2); + Assert.That(result[0].Name, Is.EqualTo(todolist.MyList[1].Name)); + Assert.That(result[1].Name, Is.EqualTo(todolist.MyList[0].Name)); + } + + // 10. I want to prioritise tasks e.g. low, medium, high + [Test] + public void PrioritiseTask() + { + // arrange + TodoList todolist = new TodoList(); + var task1 = new TaskItem { Name = "Clean the bathroom" }; + var task2 = new TaskItem { Name = "Do the dishes" }; + var task3 = new TaskItem { Name = "Walk the dog" }; + todolist.MyList.Add(task1); + todolist.MyList.Add(task2); + todolist.MyList.Add(task3); + + // act + todolist.MyList[0].Priority = Priority.Low; + todolist.MyList[1].Priority = Priority.High; + todolist.MyList[2].Priority = Priority.Medium; + + // assert + Assert.IsTrue(todolist.MyList[0].Priority == Priority.Low); + Assert.IsTrue(todolist.MyList[1].Priority == Priority.High); + Assert.IsTrue(todolist.MyList[2].Priority == Priority.Medium); + } + + // 11. I want to list all tasks by priority + [Test] + public void GetTasksInPriorityOrder() + { + // arrange + TodoList todolist = new TodoList(); + var task1 = new TaskItem { Name = "Clean the bathroom", Priority = Priority.Low }; + var task2 = new TaskItem { Name = "Do the dishes", Priority = Priority.High }; + var task3 = new TaskItem { Name = "Walk the dog", Priority = Priority.Medium }; + todolist.MyList.Add(task1); + todolist.MyList.Add(task2); + todolist.MyList.Add(task3); + + // act + var result = todolist.TasksSortedByPriority; + + // assert + Assert.IsTrue(result.Count == 3); + Assert.That(result[0].Priority, Is.EqualTo(todolist.MyList[1].Priority)); + Assert.That(result[1].Priority, Is.EqualTo(todolist.MyList[2].Priority)); + Assert.That(result[2].Priority, Is.EqualTo(todolist.MyList[0].Priority)); } } -} \ 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..63b994d2 100644 --- a/tdd-todo-list.CSharp.Test/ExtensionTests.cs +++ b/tdd-todo-list.CSharp.Test/ExtensionTests.cs @@ -14,5 +14,7 @@ public ExtensionTests() { _extension = new TodoListExtension(); } + + } } 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