From 87a67ec75929874c6e43cfdec4a3ef7998d7f761 Mon Sep 17 00:00:00 2001 From: Miadog7Extra Date: Mon, 13 Jan 2025 21:22:22 +0100 Subject: [PATCH 1/4] start --- domain-model.md | 3 ++ tdd-todo-list.CSharp.Main/Program.cs | 14 +++++++-- tdd-todo-list.CSharp.Main/ToDoList.cs | 45 +++++++++++++++++++++++++++ tdd-todo-list.sln | 1 + 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 domain-model.md diff --git a/domain-model.md b/domain-model.md new file mode 100644 index 00000000..2687f914 --- /dev/null +++ b/domain-model.md @@ -0,0 +1,3 @@ +| Classes | Methods | Scenario | Output | +|---------|-------------------|----------------------------------------------|---------------------------------| +| \ No newline at end of file diff --git a/tdd-todo-list.CSharp.Main/Program.cs b/tdd-todo-list.CSharp.Main/Program.cs index 3751555c..4c9c90c4 100644 --- a/tdd-todo-list.CSharp.Main/Program.cs +++ b/tdd-todo-list.CSharp.Main/Program.cs @@ -1,2 +1,12 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); +using System; +using tdd_todo_list.CSharp.Main; + + +TodoList toDoList = new TodoList(); + +toDoList.AddTask("Buy food"); +toDoList.AddTask("exercise"); + +toDoList.RemoveTask("Buy food"); + +toDoList.ShowTasks(); diff --git a/tdd-todo-list.CSharp.Main/ToDoList.cs b/tdd-todo-list.CSharp.Main/ToDoList.cs index 835cb600..2dfee88b 100644 --- a/tdd-todo-list.CSharp.Main/ToDoList.cs +++ b/tdd-todo-list.CSharp.Main/ToDoList.cs @@ -6,7 +6,52 @@ namespace tdd_todo_list.CSharp.Main { + public class Task + { + public int Id { get; set; } + public string Description { get; set; } + public bool IsComplete { get; set; } + + public Task(int id, string description) + { + Id = id; + Description = description; + IsComplete = false; + } + + public void ToggleStatus() + { + IsComplete = !IsComplete; + } + } public class TodoList { + private List tasks = new List(); + private int nextId = 1; + + public void AddTask(string description) + { + tasks.Add(new Task(nextId++, description)); + } + + public void ShowTasks() + { + if (tasks.Count == 0) + { + Console.WriteLine("no tasks"); + } + else + { + foreach (var task in tasks) + { + Console.WriteLine($"{task.Id}. {task.Description} - {task.IsComplete}"); + } + } + } + public void RemoveTask(string description) + { + tasks.Remove(new Task(nextId++, description)); + Console.WriteLine("removed task"); + } } } 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 From 5fe8c5a8ce2fff66df40b9e60ab1f52cbed78344 Mon Sep 17 00:00:00 2001 From: Miadog7Extra Date: Tue, 14 Jan 2025 08:34:18 +0100 Subject: [PATCH 2/4] Domain Model --- domain-model.md | 21 ++++++++++++++++++--- tdd-todo-list.CSharp.Main/Program.cs | 2 ++ tdd-todo-list.CSharp.Main/ToDoList.cs | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/domain-model.md b/domain-model.md index 2687f914..d3730672 100644 --- a/domain-model.md +++ b/domain-model.md @@ -1,3 +1,18 @@ -| Classes | Methods | Scenario | Output | -|---------|-------------------|----------------------------------------------|---------------------------------| -| \ No newline at end of file +| Classes | Methods | Scenario | Output | +|---------|-------------------|----------------------------------------------|------------------------| +|TodoList | AddTask | I want to add tasks to my todo list | task added | +| | ShowTasks | I want to see all the tasks in my todo list | List | +| | ToggleStatus | I want to change the status of a task | String output | +| | GetComplet | I want to be able to get only the complete | +| | GetIncomplet | I want to be able to get only the inccomplete| +| | FindTask | I want to search for a task and receive a | +| | | message that says it wasn't found if | +| | | it doesn't exist. | +| | RemoveTask | I want to remove tasks from my list. | +| | TaskAscending | I want to see all the tasks in my list | +| | | ordered alphabetically in ascending order | +| | TaskDescending | I want to see all the tasks in my list | +| | | ordered alphabetically in descending order. | +| | GetTaskById | I want to be able to get task by a unique ID | +| | UpdatedTask | I want to update the name of a task by | +| | | providing its ID and a new name. | diff --git a/tdd-todo-list.CSharp.Main/Program.cs b/tdd-todo-list.CSharp.Main/Program.cs index 4c9c90c4..346615f9 100644 --- a/tdd-todo-list.CSharp.Main/Program.cs +++ b/tdd-todo-list.CSharp.Main/Program.cs @@ -7,6 +7,8 @@ toDoList.AddTask("Buy food"); toDoList.AddTask("exercise"); +toDoList.ShowTasks(); + toDoList.RemoveTask("Buy food"); toDoList.ShowTasks(); diff --git a/tdd-todo-list.CSharp.Main/ToDoList.cs b/tdd-todo-list.CSharp.Main/ToDoList.cs index 2dfee88b..d7b0e506 100644 --- a/tdd-todo-list.CSharp.Main/ToDoList.cs +++ b/tdd-todo-list.CSharp.Main/ToDoList.cs @@ -50,7 +50,7 @@ public void ShowTasks() } public void RemoveTask(string description) { - tasks.Remove(new Task(nextId++, description)); + tasks.Remove Console.WriteLine("removed task"); } } From 55626f9fc15ffc90f4aebfc942f7ddd6a33f4f87 Mon Sep 17 00:00:00 2001 From: Miadog7Extra Date: Tue, 14 Jan 2025 12:27:44 +0100 Subject: [PATCH 3/4] core --- domain-model.md | 3 - tdd-todo-list.CSharp.Main/Extension.cs | 14 +++ tdd-todo-list.CSharp.Main/Program.cs | 10 ++- tdd-todo-list.CSharp.Main/ToDoList.cs | 104 ++++++++++++++++++++--- tdd-todo-list.CSharp.Test/CoreTests.cs | 113 ++++++++++++++++++++++++- 5 files changed, 221 insertions(+), 23 deletions(-) diff --git a/domain-model.md b/domain-model.md index d3730672..929890df 100644 --- a/domain-model.md +++ b/domain-model.md @@ -13,6 +13,3 @@ | | | ordered alphabetically in ascending order | | | TaskDescending | I want to see all the tasks in my list | | | | ordered alphabetically in descending order. | -| | GetTaskById | I want to be able to get task by a unique ID | -| | UpdatedTask | I want to update the name of a task by | -| | | providing its ID and a new name. | diff --git a/tdd-todo-list.CSharp.Main/Extension.cs b/tdd-todo-list.CSharp.Main/Extension.cs index e4c08912..f3738ebc 100644 --- a/tdd-todo-list.CSharp.Main/Extension.cs +++ b/tdd-todo-list.CSharp.Main/Extension.cs @@ -8,5 +8,19 @@ namespace tdd_todo_list.CSharp.Main { public class TodoListExtension { + private List tasks = new List(); + private int nextId = 1; + + public void AddTask(string name) + { + tasks.Add(new Task(nextId++, name)); + } + + public string FindTaskByID(int id) + { + var task = tasks.Find(x => x.Id == id); + + return task == null ? $"no task with id: {id}" : $"{task.Name} - {task.IsComplete}"; + } } } diff --git a/tdd-todo-list.CSharp.Main/Program.cs b/tdd-todo-list.CSharp.Main/Program.cs index 346615f9..656e0228 100644 --- a/tdd-todo-list.CSharp.Main/Program.cs +++ b/tdd-todo-list.CSharp.Main/Program.cs @@ -1,4 +1,5 @@ -using System; +using NUnit.Framework.Interfaces; +using System; using tdd_todo_list.CSharp.Main; @@ -6,9 +7,10 @@ toDoList.AddTask("Buy food"); toDoList.AddTask("exercise"); +toDoList.AddTask("auy food"); +toDoList.AddTask("cxercise"); -toDoList.ShowTasks(); +var allTasks = toDoList.ShowTasks(); +Console.WriteLine(string.Join("\n", allTasks)); -toDoList.RemoveTask("Buy food"); -toDoList.ShowTasks(); diff --git a/tdd-todo-list.CSharp.Main/ToDoList.cs b/tdd-todo-list.CSharp.Main/ToDoList.cs index d7b0e506..3dc9dc05 100644 --- a/tdd-todo-list.CSharp.Main/ToDoList.cs +++ b/tdd-todo-list.CSharp.Main/ToDoList.cs @@ -9,13 +9,13 @@ namespace tdd_todo_list.CSharp.Main public class Task { public int Id { get; set; } - public string Description { get; set; } + public string Name { get; set; } public bool IsComplete { get; set; } - public Task(int id, string description) + public Task(int id, string name) { Id = id; - Description = description; + Name = name; IsComplete = false; } @@ -29,29 +29,105 @@ public class TodoList private List tasks = new List(); private int nextId = 1; - public void AddTask(string description) + public void AddTask(string name) { - tasks.Add(new Task(nextId++, description)); + tasks.Add(new Task(nextId++, name)); } - public void ShowTasks() + public List ShowTasks() { if (tasks.Count == 0) { - Console.WriteLine("no tasks"); + return new List { "no tasks" }; + } + + return tasks.Select(task => $"{task.Id}. {task.Name} - {task.IsComplete}").ToList(); + } + + public string FindTask(string name) + { + var task = tasks.FirstOrDefault(task => task.Name == name); + + return task == null ? $"no task named: {name}" : $"{task.Name} - {task.IsComplete}"; + } + + public string RemoveTask(string name) + { + var taskToRemove = tasks.FirstOrDefault(task => task.Name == name); + + if (taskToRemove != null) + { + tasks.Remove(taskToRemove); + return $"removed {name}"; } else { - foreach (var task in tasks) - { - Console.WriteLine($"{task.Id}. {task.Description} - {task.IsComplete}"); - } + return $"could not find: '{name}'"; } } - public void RemoveTask(string description) + + public bool ToggleStatus(string name) { - tasks.Remove - Console.WriteLine("removed task"); + var taskToChange = tasks.FirstOrDefault(task => task.Name == name); + + if (taskToChange != null) + { + taskToChange.ToggleStatus(); + return true; + } + return false; + } + + public List ShowComplete() + { + if (tasks.Count == 0) + { + return new List { "no tasks" }; + } + + return tasks + .Where(task => task.IsComplete) + .Select(task => $"{task.Id}. {task.Name} - {task.IsComplete}") + .ToList(); + } + + public List ShowInComplete() + { + if (tasks.Count == 0) + { + return new List { "no tasks" }; + } + + return tasks + .Where(task => !task.IsComplete) + .Select(task => $"{task.Id}. {task.Name} - {task.IsComplete}") + .ToList(); + } + + public List ShowAscending() + { + if (tasks.Count == 0) + { + return new List { "no tasks" }; + } + + return tasks + .OrderBy(t => t.Name) + .Select(task => $"{task.Name}, {task.IsComplete}") + .ToList(); + } + + public List ShowDescending() + { + if (tasks.Count == 0) + { + return new List { "no tasks" }; + } + + return tasks + .OrderByDescending(t => t.Name) + .Select(task => $"{task.Name}, {task.IsComplete}") + .ToList(); } } } diff --git a/tdd-todo-list.CSharp.Test/CoreTests.cs b/tdd-todo-list.CSharp.Test/CoreTests.cs index 084cce19..1216b315 100644 --- a/tdd-todo-list.CSharp.Test/CoreTests.cs +++ b/tdd-todo-list.CSharp.Test/CoreTests.cs @@ -6,12 +6,121 @@ namespace tdd_todo_list.CSharp.Test [TestFixture] public class CoreTests { - [Test] public void FirstTest() { TodoList core = new TodoList(); Assert.Pass(); } + + [Test] + public void AddTask() + { + TodoList toDoList = new TodoList(); + + toDoList.AddTask("Buy groceries"); + var tasks = toDoList.ShowTasks(); + + var expected = new List { "1. Buy groceries - False" }; + CollectionAssert.AreEqual(expected, tasks); + } + + [Test] + public void FindTask() + { + TodoList toDoList = new TodoList(); + toDoList.AddTask("Buy groceries"); + toDoList.AddTask("Call"); + + var taskFound = toDoList.FindTask("Buy groceries"); + var taskNotFound = toDoList.FindTask("Non-existent task"); + + Assert.AreEqual("Buy groceries - False", taskFound); + Assert.AreEqual("no task named: Non-existent task", taskNotFound); + } + + [Test] + public void RemoveTask() + { + TodoList toDoList = new TodoList(); + toDoList.AddTask("Buy groceries"); + + var removeSuccess = toDoList.RemoveTask("Buy groceries"); + var removeFailure = toDoList.RemoveTask("tasks"); + var tasksAfterRemoval = toDoList.ShowTasks(); + + Assert.AreEqual("removed Buy groceries", removeSuccess); + Assert.AreEqual("could not find: 'tasks'", removeFailure); + CollectionAssert.AreEqual(new List { "no tasks" }, tasksAfterRemoval); + } + + [Test] + public void ToggleStatus() + { + TodoList toDoList = new TodoList(); + toDoList.AddTask("Buy groceries"); + + var toggleSuccess = toDoList.ToggleStatus("Buy groceries"); + var taskStatusAfterToggle = toDoList.FindTask("Buy groceries"); + var toggleFailure = toDoList.ToggleStatus("Non-existent task"); + + Assert.IsTrue(toggleSuccess); + Assert.AreEqual("Buy groceries - True", taskStatusAfterToggle); + Assert.IsFalse(toggleFailure); + } + + [Test] + public void ShowComplete() + { + TodoList toDoList = new TodoList(); + toDoList.AddTask("Buy groceries"); + toDoList.AddTask("run"); + toDoList.ToggleStatus("run"); + + var completeTasks = toDoList.ShowComplete(); + + var expected = new List { "2. run - True" }; + CollectionAssert.AreEqual(expected, completeTasks); + } + + [Test] + public void ShowInComplete() + { + TodoList toDoList = new TodoList(); + toDoList.AddTask("Buy groceries"); + toDoList.AddTask("run"); + toDoList.ToggleStatus("run"); + + var incompleteTasks = toDoList.ShowInComplete(); + + var expected = new List { "1. Buy groceries - False" }; + CollectionAssert.AreEqual(expected, incompleteTasks); + } + + [Test] + public void ShowAscending() + { + TodoList toDoList = new TodoList(); + toDoList.AddTask("Buy groceries"); + toDoList.AddTask("run"); + + var ascendingTasks = toDoList.ShowAscending(); + + var expected = new List { "Buy groceries, False", "run, False" }; + CollectionAssert.AreEqual(expected, ascendingTasks); + } + + [Test] + public void ShowDescending() + { + TodoList toDoList = new TodoList(); + toDoList.AddTask("Buy groceries"); + toDoList.AddTask("run"); + + var descendingTasks = toDoList.ShowDescending(); + + var expected = new List { "run, False", "Buy groceries, False" }; + CollectionAssert.AreEqual(expected, descendingTasks); + } } -} \ No newline at end of file +} From 37ee0de9ff33eb37bebf027e1e07f6b425a79556 Mon Sep 17 00:00:00 2001 From: Miadog7Extra Date: Tue, 14 Jan 2025 12:43:04 +0100 Subject: [PATCH 4/4] started extension --- tdd-todo-list.CSharp.Main/Program.cs | 7 ++++++ tdd-todo-list.CSharp.Test/ExtensionTests.cs | 28 +++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/tdd-todo-list.CSharp.Main/Program.cs b/tdd-todo-list.CSharp.Main/Program.cs index 656e0228..b2694c5c 100644 --- a/tdd-todo-list.CSharp.Main/Program.cs +++ b/tdd-todo-list.CSharp.Main/Program.cs @@ -5,12 +5,19 @@ TodoList toDoList = new TodoList(); +TodoListExtension extension = new TodoListExtension(); + toDoList.AddTask("Buy food"); toDoList.AddTask("exercise"); toDoList.AddTask("auy food"); toDoList.AddTask("cxercise"); +extension.AddTask("check"); + var allTasks = toDoList.ShowTasks(); Console.WriteLine(string.Join("\n", allTasks)); +var idTasks = extension.FindTaskByID(1); +Console.WriteLine(string.Join("\n", idTasks)); + diff --git a/tdd-todo-list.CSharp.Test/ExtensionTests.cs b/tdd-todo-list.CSharp.Test/ExtensionTests.cs index bdc82ad7..eb1530f0 100644 --- a/tdd-todo-list.CSharp.Test/ExtensionTests.cs +++ b/tdd-todo-list.CSharp.Test/ExtensionTests.cs @@ -4,9 +4,11 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using NUnit.Framework; namespace tdd_todo_list.CSharp.Test { + [TestFixture] public class ExtensionTests { private TodoListExtension _extension; @@ -14,5 +16,31 @@ public ExtensionTests() { _extension = new TodoListExtension(); } + [Test] + public void FindByID() + { + TodoListExtension toDoList = new TodoListExtension(); + toDoList.AddTask("Buy groceries"); + + var taskFound = toDoList.FindTaskByID(1); + var taskNotFound = toDoList.FindTaskByID(100); + + Assert.AreEqual("Buy groceries - False", taskFound); + Assert.AreEqual("no task with id: 100", taskNotFound); + } + [Test] + public void UpdateName() + { + TodoListExtension toDoList = new TodoListExtension(); + toDoList.AddTask("Buy groceries"); + + var taskupdated = toDoList.UpdateName(); + var taskNotFound = toDoList.FindTaskByID(100); + + Assert.AreEqual("Buy update - False", taskupdated); + Assert.AreEqual("no task with id: 100", taskNotFound); + } + + } }