From 8359620a113758cef265bac827d1fcb13d8b4964 Mon Sep 17 00:00:00 2001 From: Lowe Raivio Date: Thu, 9 Jan 2025 16:56:04 +0100 Subject: [PATCH 1/2] Core and extended objectives completed --- domain-model.md | 0 tdd-todo-list.CSharp.Main/TaskEntry.cs | 75 +++ tdd-todo-list.CSharp.Main/ToDoList.cs | 85 ++++ tdd-todo-list.CSharp.Main/domain-model.md | 43 ++ .../tdd-todo-list.CSharp.Main.csproj | 2 +- tdd-todo-list.CSharp.Test/CoreTests.cs | 426 +++++++++++++++++- tdd-todo-list.CSharp.Test/ExtensionTests.cs | 104 +++++ 7 files changed, 733 insertions(+), 2 deletions(-) create mode 100644 domain-model.md create mode 100644 tdd-todo-list.CSharp.Main/TaskEntry.cs create mode 100644 tdd-todo-list.CSharp.Main/domain-model.md diff --git a/domain-model.md b/domain-model.md new file mode 100644 index 00000000..e69de29b diff --git a/tdd-todo-list.CSharp.Main/TaskEntry.cs b/tdd-todo-list.CSharp.Main/TaskEntry.cs new file mode 100644 index 00000000..4757209d --- /dev/null +++ b/tdd-todo-list.CSharp.Main/TaskEntry.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace tdd_todo_list.CSharp.Main +{ + public class TaskEntry : IComparable + { + private string _name = "undefined"; + private bool _completed = false; + private int _id = -1; + public DateTime _date = DateTime.Now; + public string Name { get => _name; set => _name = value; } + public bool Completed { get => _completed; set => _completed = value; } + public DateTime CreationDate { get => _date;} + public int Id { get => _id; } + + + public TaskEntry(string taskName, int assignedId) + { + this.Name = taskName; + this._id = assignedId; + } + + private class SortByDate : IComparer + { + public int Compare(TaskEntry? x, TaskEntry? y) + { + if ( x == null || y == null) + return 0; + + return x._date.CompareTo(y._date); + } + } + private class SortByName_ascending : IComparer + { + public int Compare(TaskEntry? x, TaskEntry? y) + { + if (x == null || y == null) + return 0; + return x._name.CompareTo(y._name); + } + } + private class SortByName_descending : IComparer + { + public int Compare(TaskEntry? x, TaskEntry? y) + { + if (x == null || y == null) + return 0; + return x._name.CompareTo(y._name) * -1; + } + } + public static IComparer get_SortByDate() + { + return new SortByDate(); + } + public static IComparer get_SortByName_ascending() + { + return new SortByName_ascending(); + } + public static IComparer get_SortByName_descending() + { + return new SortByName_descending(); + } + + public int CompareTo(TaskEntry? other) + { + return get_SortByDate().Compare(this,other); + } + } +} diff --git a/tdd-todo-list.CSharp.Main/ToDoList.cs b/tdd-todo-list.CSharp.Main/ToDoList.cs index 835cb600..8d7e68a8 100644 --- a/tdd-todo-list.CSharp.Main/ToDoList.cs +++ b/tdd-todo-list.CSharp.Main/ToDoList.cs @@ -6,7 +6,92 @@ namespace tdd_todo_list.CSharp.Main { + + public class TodoList { + private Dictionary _tasks = new Dictionary(); + public int NrOfTasks { get => _tasks.Count; } + + private IComparer _orderComparable = TaskEntry.get_SortByDate(); + public TodoList() { } + + private static int _uniqueId = -1; + private static int getUniqueId() + { + return ++_uniqueId; + } + + + public int AddTask(string taskName) + { + int uniqueId = TodoList.getUniqueId(); + TaskEntry newTask = new TaskEntry(taskName, uniqueId); + _tasks.Add(uniqueId, newTask); + + return uniqueId; + + } + public TaskEntry? GetTask(int taskId) + { + + if(this._tasks.ContainsKey(taskId)) + return this._tasks[taskId]; + + return null; + + } + public void RemoveTask(int taskId) + { + + if(!this._tasks.ContainsKey(taskId)) + return; + + this._tasks.Remove(taskId); + + } + public void EditTaskName(int taskId, string newName) + { + + if(!this._tasks.ContainsKey(taskId)) + return; + + this._tasks[taskId].Name = newName; + + } + public void ToggleTaskCompletion(int taskId) + { + this._tasks[taskId].Completed = !this._tasks[taskId].Completed; + } + + public List SearchTask(string searchTerm) + { + return this._tasks.ToList().Where(x => x.Value.Name.Contains(searchTerm)).Select(x=> x.Value).ToList(); + } + + public void SetTaskOrder_Ascending() { + this._orderComparable = TaskEntry.get_SortByName_ascending(); + } + public void SetTaskOrder_Descending() { + this._orderComparable = TaskEntry.get_SortByName_descending(); + } + public void SetTaskOrder_asAdded() { + this._orderComparable = TaskEntry.get_SortByDate(); + } + + public List GetTaskList_all() + { + return this._tasks.Values.Order(_orderComparable).ToList(); + } + public List GetTaskList_completed() + { + + return this._tasks.Values.ToList().Where(x => x.Completed).Order(_orderComparable).ToList(); + } + public List GetTaskList_incompleted() + { + return this._tasks.Values.ToList().Where(x => !x.Completed).Order(_orderComparable).ToList(); + } + } } diff --git a/tdd-todo-list.CSharp.Main/domain-model.md b/tdd-todo-list.CSharp.Main/domain-model.md new file mode 100644 index 00000000..d1c10451 --- /dev/null +++ b/tdd-todo-list.CSharp.Main/domain-model.md @@ -0,0 +1,43 @@ + +### Requirements: +1. I want to add tasks to my todo list. +2. I want to see all the tasks in my todo list. +3. I want to change the status of a task between incomplete and complete. +4. I want to be able to get only the complete tasks. +5. I want to be able to get only the incomplete tasks. +6. I want to search for a task and receive a message that says it wasn't found if it doesn't exist. +7. I want to remove tasks from my list. +8. I want to see all the tasks in my list ordered alphabetically in ascending order. +9. I want to see all the tasks in my list ordered alphabetically in descending order. + +### Extended Reqirements: +10. I want to be able to get a task by a unique ID. +11. I want to update the name of a task by providing its ID and a new name. +12. I want to be able to change the status of a task by providing its ID. +13. I want to be able to see the date and time that I created each task. + + +### Domain Table + +| **User Story ID** | **Classes** | **Method/Property** | **Scenario** | **Outputs** | **Is Extension? (empty=False)** | +|-------------------|-------------|-------------------------|--------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------|---------------------------------| +| 1 | TodoList | AddTask | Add task with a string description/value | String stored in list | | +| 10 | TodoList | GetTask | Retrieve added task from list given ID | returns requested Task instance | True | +| 2 | TodoList | GetTaskList_all | Want all the tasks in a list | returns List of TaskEntry objects | | +| 4 | TodoList | GetTaskList_completed | Want all the completed tasks in a list | returns List of all completed TaskEntry objects | | +| 5 | TodoList | GetTaskList_incompleted | Want all the incompleted tasks in a list | returns List of all incompleted TaskEntry objects | | +| 3 | TodoList | ToggleTaskStatus | Given task ID, Toggle status between incomplete/complete | if incomplete, call result in toggled to complete. if Complete, call results in incomplete | True | +| 6-- | TodoList | SearchTask | Want to be able to search for a task without knowing the Task ID | returns list of Tasks that matches the search criteria, or if no matching enrties exist | | +| 7 | TodoList | RemoveTask | Remove a task from the list based on task id | List is changed with requested task removed | | +| 8 | TodoList | SetTaskOrder_Ascending | Change order of tasks. Ascends in alphabetically order | List order is changed to ascending alphabetically | | +| 9 | TodoList | SetTaskOrder_Descending | Change order of tasks. Descends in alphabetically order | List order is changed to descending alphabetically | | +| extra | TodoList | SetTaskOrder_asAdded | Change order of tasks to the order for when they where added | List order is changed to the order they where added | | +| 11 | TodoList | EditTaskName | Provide ID and new name to the task which we want to change | Task Entry is changed with the name | True | +| | | | | | | +| 1 | TaskEntry | Constructor | Create a Task Object, provide name and description | Task with name and description created | | +| 13 | TaskEntry | -- | Upon creation, time and date should be stored, and a ID managed by owner. | Task will have a creation date/time | True | +| 11 | TaskEntry | SetName (Name prop) | Change name of Task | Task name will be changed to provided name | | +| 6 | TaskEntry | GetName (Name prop) | Retrieve the name | returns Task name as string | | +| 3,12 | TaskEntry | Completed (prop) | Set Completion status to True/False | Completion Status will be changed | | +| 4,5 | TaskEntry | Completed (prop) | Retrieve the task completion status | Completion status will be returned as boolean value | | +| | | | | | | \ No newline at end of file diff --git a/tdd-todo-list.CSharp.Main/tdd-todo-list.CSharp.Main.csproj b/tdd-todo-list.CSharp.Main/tdd-todo-list.CSharp.Main.csproj index 765165d1..14b769ef 100644 --- a/tdd-todo-list.CSharp.Main/tdd-todo-list.CSharp.Main.csproj +++ b/tdd-todo-list.CSharp.Main/tdd-todo-list.CSharp.Main.csproj @@ -1,4 +1,4 @@ - + Exe diff --git a/tdd-todo-list.CSharp.Test/CoreTests.cs b/tdd-todo-list.CSharp.Test/CoreTests.cs index 084cce19..26042e51 100644 --- a/tdd-todo-list.CSharp.Test/CoreTests.cs +++ b/tdd-todo-list.CSharp.Test/CoreTests.cs @@ -8,10 +8,434 @@ public class CoreTests { [Test] - public void FirstTest() + public void createTodoList() { TodoList core = new TodoList(); + Assert.That(core.NrOfTasks, Is.EqualTo(0)); Assert.Pass(); + + } + + [Test] + public void createTaskEntry() + { + TaskEntry task = new TaskEntry("my First Task", -1); + Assert.Pass(); + } + + + [TestCase("My First Task")] + public void addTask(string taskName) + { + //Arrange + TodoList core = new TodoList(); + int nrOfEntriesBeforeAdd = core.NrOfTasks; + //Act + int taskId = core.AddTask(taskName); + //Assert + Assert.IsTrue(nrOfEntriesBeforeAdd == (core.NrOfTasks - 1)); + } + [TestCase("My First Task")] + public void addTaskThenRetrieve(string taskName) + { + //Arrange + TodoList core = new TodoList(); + int nrOfEntriesBeforeAdd = core.NrOfTasks; + //Act + int taskId = core.AddTask(taskName); + TaskEntry? addedTask = core.GetTask(taskId); + //Assert + Assert.IsTrue(nrOfEntriesBeforeAdd == (core.NrOfTasks - 1)); + Assert.That(addedTask != null); + Assert.That(taskName == addedTask?.Name); + } + + //[TestCase(new string[]{"My First Task", "My second Task", "My third Task", "My fourth Task", "another", "yes, this is task"})] + [TestCase(new object[]{"My First Task", "My second Task", "My third Task", "My fourth Task", "another", "yes, this is task"})] + [TestCase(new object[] { "another", "another", "another", "another", "another" })] + [TestCase(new object[] { "another", "another", "another", "another", "another", "yes, this is task" })] + public void addTaskThenRetrieve_multiple(params string[] taskNames) + { + //Arrange + TodoList core = new TodoList(); + int nrOfEntriesBeforeAdd = core.NrOfTasks; + List< Tuple> retrievedTasks_names = new List< Tuple>(); + //Act + foreach (string n in taskNames) + { + + int taskId = core.AddTask(n); + TaskEntry? addedTask = core.GetTask(taskId); + if (addedTask != null) + retrievedTasks_names.Add(new (addedTask, n )); + else + Assert.Fail(); + } + //Assert + foreach(var rt in retrievedTasks_names) + { + TaskEntry task = rt.Item1; + string taskName = rt.Item2; + Assert.That(task != null); + Assert.That(taskName == task?.Name); + } + Assert.IsTrue(nrOfEntriesBeforeAdd == (core.NrOfTasks - taskNames.Length)); + } + + [TestCase(new object[]{"My First Task", "My second Task", "My third Task", "My fourth Task", "another", "yes, this is task"})] + [TestCase(new object[]{ "another", "another", "another", "another", "another"})] + [TestCase(new object[]{ "another", "another", "another", "another", "another", "yes, this is task"})] + public void taskList_validateAdded(params string[] taskNames) + { + //Arrange + TodoList core = new TodoList(); + Dictionary retrievedTasks_names = new Dictionary(); + foreach (string n in taskNames) + { + + int taskId = core.AddTask(n); + retrievedTasks_names[taskId] = n; + } + //Act + List tasklist = core.GetTaskList_all(); + + //Assert + Assert.IsTrue(tasklist.Count != 0); + Assert.IsTrue(tasklist.Count == taskNames.Count()); + foreach (var t in tasklist) + { + Assert.That(retrievedTasks_names.ContainsKey(t.Id)); + Assert.That(retrievedTasks_names[t.Id] == t.Name ); + } + } + + [Test] + public void taskList_addThenCheckCompletionStatus() + { + //Arrange + TodoList core = new TodoList(); + int testTaskId = core.AddTask("my Test Task"); + //Act + TaskEntry? task = core.GetTask(testTaskId); + + //Assert + Assert.IsNotNull(task); + Assert.IsFalse(task?.Completed); + } + [Test] + public void taskList_addThenMarkAsCompleted() + { + //Arrange + TodoList core = new TodoList(); + int testTaskId = core.AddTask("my Test Task"); + //Act + TaskEntry? task = core.GetTask(testTaskId); + + core.ToggleTaskCompletion(testTaskId); // Toggels to Complete + task = core.GetTask(testTaskId); + + //Assert + Assert.IsTrue(task?.Completed); + Assert.IsNotNull(task); + } + [Test] + public void taskList_addThenMarkAsCompletedThenMarkAsIncomplete() + { + //Arrange + TodoList core = new TodoList(); + int testTaskId = core.AddTask("my Test Task"); + //Act + TaskEntry? task = core.GetTask(testTaskId); + + core.ToggleTaskCompletion(testTaskId); // Toggels to Complete + core.ToggleTaskCompletion(testTaskId); // Toggles to Incomplete + task = core.GetTask(testTaskId); + + //Assert + Assert.IsFalse(task?.Completed); + Assert.IsNotNull(task); + } + [Test] + public void taskList_accesssCreationDateTime() + { + //Arrange + TodoList core = new TodoList(); + var timeBefore = DateTime.Now; + int testTaskId = core.AddTask("my Test Task"); + var timeAfter = DateTime.Now; + TaskEntry? task = core.GetTask(testTaskId); + //Act + + + var accessedCreationDate = task?.CreationDate; + + //Assert + Assert.IsNotNull(task); + Assert.IsInstanceOf(typeof(DateTime), accessedCreationDate); + Assert.Less(timeBefore, accessedCreationDate); + Assert.Greater(timeAfter, accessedCreationDate); + } + [Test] + public void taskList_getCompleted() + { + //Arrange + TodoList core = new TodoList(); + int task_id_a = core.AddTask("my a Task"); + int task_id_b = core.AddTask("my b Task"); + int task_id_c = core.AddTask("my c Task"); + int task_id_d = core.AddTask("my d Task"); + int task_id_e = core.AddTask("my e Task"); + List> taskId_completionStatus = new List> + { + new (task_id_a, true ), + new (task_id_b, false), + new (task_id_c, true), + new (task_id_d, true), + new (task_id_e, false), + }; + List completedTaskIds = taskId_completionStatus.Where(x => x.Item2).Select(x => x.Item1).ToList(); + foreach (var (taskId, status) in taskId_completionStatus) + { + if (status) + core.ToggleTaskCompletion(taskId); + } + + // act + var completedTasks = core.GetTaskList_completed(); + + //assert + foreach (var task in completedTasks) + { + Assert.Contains(task.Id, completedTaskIds); + } + Assert.AreEqual(completedTasks.Count, completedTaskIds.Count); + + } + [Test] + public void taskList_getIncompleted() + { + //Arrange + TodoList core = new TodoList(); + int task_id_a = core.AddTask("my a Task"); + int task_id_b = core.AddTask("my b Task"); + int task_id_c = core.AddTask("my c Task"); + int task_id_d = core.AddTask("my d Task"); + int task_id_e = core.AddTask("my e Task"); + List> taskId_completionStatus = new List> + { + new (task_id_a, true ), + new (task_id_b, false), + new (task_id_c, true), + new (task_id_d, true), + new (task_id_e, false), + }; + List incompletedTaskIds = taskId_completionStatus.Where(x => !x.Item2).Select(x => x.Item1).ToList(); + foreach (var (taskId, status) in taskId_completionStatus) + { + if (!status) + core.ToggleTaskCompletion(taskId); + } + + //assert + var completedTasks = core.GetTaskList_completed(); + + //assert + foreach (var task in completedTasks) + { + Assert.Contains(task.Id, incompletedTaskIds); + } + Assert.AreEqual(completedTasks.Count, incompletedTaskIds.Count); + + } + [Test] + public void taskList_search() + { + //Arrange + TodoList core = new TodoList(); + int task_id_a = core.AddTask("my a cool Task"); + int task_id_b = core.AddTask("my b coolest Task"); + int task_id_c = core.AddTask("my c very Task"); + int task_id_d = core.AddTask("my d fine Task"); + int task_id_e = core.AddTask("my e fine Task"); + int task_id_f = core.AddTask("ye its abc"); + List, string>> searchPhrase_ExpectedIdMatches_pairs = new List, string>> + { + new (new List{task_id_a, task_id_b}, "cool" ), + new (new List{task_id_a,task_id_b,task_id_c,task_id_d,task_id_e,}, "my" ), + new (new List{task_id_d,task_id_e,}, "fine" ), + new (new List{task_id_b,task_id_c,task_id_d,task_id_e,}, "e" ), + new (new List{task_id_b,task_id_f,}, "b" ), + }; + + + //assert + foreach (var (expectedMatch_ids, searchText) in searchPhrase_ExpectedIdMatches_pairs) + { + var results = core.SearchTask(searchText); + var resultIds = results.Select(x => x.Id).ToList(); + foreach (int expectedMatch in expectedMatch_ids) + { + Assert.Contains(expectedMatch, resultIds); + } + } + + } + [Test] + public void taskList_removeTask() + { + //Arrange + TodoList core = new TodoList(); + int task_id_a = core.AddTask("my a cool Task"); + int task_id_b = core.AddTask("my b coolest Task"); + int task_id_c = core.AddTask("my c very Task"); + int task_id_d = core.AddTask("my d fine Task"); + int task_id_e = core.AddTask("my e fine Task"); + int task_id_f = core.AddTask("ye its abc"); + + //act + int pre_nr_tasks = core.NrOfTasks; + core.RemoveTask(task_id_a); + TaskEntry? entry = core.GetTask(task_id_a); + + //assert + Assert.AreEqual(pre_nr_tasks, core.NrOfTasks+1); + Assert.IsNull(entry); + + } + [Test] + public void taskList_getOrderAscending() + { + //Arrange + TodoList core = new TodoList(); + int task_id_b = core.AddTask("b"); + int task_id_d = core.AddTask("d"); + int task_id_a = core.AddTask("a"); + int task_id_e = core.AddTask("e"); + int task_id_f = core.AddTask("f"); + int task_id_c = core.AddTask("c"); + + var expectedOrder = new List + { + "a", + "b", + "c", + "d", + "e", + "f", + }; + + //act + core.SetTaskOrder_Ascending(); + var allTasks = core.GetTaskList_all(); + + + //assert + for (int i = 0; i < allTasks.Count; i++) + { + var task = allTasks[i]; + var expected = expectedOrder[i]; + Assert.AreEqual(expected, task.Name); + } + + } + [Test] + public void taskList_getOrderDescending() + { + //Arrange + TodoList core = new TodoList(); + int task_id_b = core.AddTask("b"); + int task_id_d = core.AddTask("d"); + int task_id_a = core.AddTask("a"); + int task_id_e = core.AddTask("e"); + int task_id_f = core.AddTask("f"); + int task_id_c = core.AddTask("c"); + + var expectedOrder = new List + { + "f", + "e", + "d", + "c", + "b", + "a", + }; + + //act + core.SetTaskOrder_Descending(); + var allTasks = core.GetTaskList_all(); + + + //assert + for (int i = 0; i < allTasks.Count; i++) + { + var task = allTasks[i]; + var expected = expectedOrder[i]; + Assert.AreEqual(expected, task.Name); + } + + } + + [Test] + public void taskList_getOrderByAsAdded() + { + //Arrange + TodoList core = new TodoList(); + int task_id_a = core.AddTask("first"); + int task_id_b = core.AddTask("second"); + int task_id_c = core.AddTask("third"); + int task_id_d = core.AddTask("fourth"); + int task_id_e = core.AddTask("fifth"); + int task_id_f = core.AddTask("sixth"); + + var expectedOrder = new List + { + "first", + "second", + "third", + "fourth", + "fifth", + "sixth", + }; + + //act + + // Changing order, just because sortByAsAdded is default... + core.SetTaskOrder_Descending(); + var dummy = core.GetTaskList_all(); + + core.SetTaskOrder_asAdded(); + var allTasks = core.GetTaskList_all(); + + + //assert + for (int i = 0; i < allTasks.Count; i++) + { + var task = allTasks[i]; + var expected = expectedOrder[i]; + Assert.AreEqual(expected, task.Name); + } + + } + + [Test] + public void taskList_editTaskname() + { + //Arrange + TodoList core = new TodoList(); + string initName = "My initial task Name"; + string newName = "myNewName"; + int taskId = core.AddTask(initName); + + //act + core.EditTaskName(taskId, newName); + + //assert + TaskEntry? renamedTask = core.GetTask(taskId); + if (renamedTask != null) + Assert.AreEqual(renamedTask.Name, newName); + else + Assert.Fail(); + } } } \ 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..2ba5cb29 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,108 @@ public ExtensionTests() { _extension = new TodoListExtension(); } + + // NOTE: These exists in the CoreTests.cs as well. They're just copied here in case you have some automates check + + [TestCase("My First Task")] + public void addTaskThenRetrieve(string taskName) + { + // Requirement: I want to be able to get a task by a unique ID. + + //Arrange + TodoList core = new TodoList(); + int nrOfEntriesBeforeAdd = core.NrOfTasks; + //Act + int taskId = core.AddTask(taskName); + TaskEntry? addedTask = core.GetTask(taskId); + //Assert + Assert.IsTrue(nrOfEntriesBeforeAdd == (core.NrOfTasks - 1)); + Assert.That(addedTask != null); + Assert.That(taskName == addedTask?.Name); + } + + [Test] + public void taskList_editTaskname() + { + // Requirement: I want to update the name of a task by providing its ID and a new name. + + //Arrange + TodoList core = new TodoList(); + string initName = "My initial task Name"; + string newName = "myNewName"; + int taskId = core.AddTask(initName); + + //act + core.EditTaskName(taskId, newName); + + //assert + TaskEntry? renamedTask = core.GetTask(taskId); + if (renamedTask != null) + Assert.AreEqual(renamedTask.Name, newName); + else + Assert.Fail(); + + } + [Test] + public void taskList_addThenMarkAsCompleted() + { + // Requirement: I want to be able to change the status of a task by providing its ID. + + //Arrange + TodoList core = new TodoList(); + int testTaskId = core.AddTask("my Test Task"); + //Act + TaskEntry? task = core.GetTask(testTaskId); + + core.ToggleTaskCompletion(testTaskId); // Toggels to Complete + task = core.GetTask(testTaskId); + + //Assert + Assert.IsTrue(task?.Completed); + Assert.IsNotNull(task); + } + [Test] + public void taskList_addThenMarkAsCompletedThenMarkAsIncomplete() + { + // Requirement: I want to be able to change the status of a task by providing its ID. + + //Arrange + TodoList core = new TodoList(); + int testTaskId = core.AddTask("my Test Task"); + //Act + TaskEntry? task = core.GetTask(testTaskId); + + core.ToggleTaskCompletion(testTaskId); // Toggels to Complete + core.ToggleTaskCompletion(testTaskId); // Toggles to Incomplete + task = core.GetTask(testTaskId); + + //Assert + Assert.IsFalse(task?.Completed); + Assert.IsNotNull(task); + } + + [Test] + public void taskList_accesssCreationDateTime() + { + // Requirement: I want to be able to see the date and time that I created each task. + + //Arrange + TodoList core = new TodoList(); + var timeBefore = DateTime.Now; + int testTaskId = core.AddTask("my Test Task"); + var timeAfter = DateTime.Now; + TaskEntry? task = core.GetTask(testTaskId); + //Act + + + var accessedCreationDate = task?.CreationDate; + + //Assert + Assert.IsNotNull(task); + Assert.IsInstanceOf(typeof(DateTime), accessedCreationDate); + Assert.Less(timeBefore, accessedCreationDate); + Assert.Greater(timeAfter, accessedCreationDate); + } + } } From b8a5640fd9271bea61ed5d5e1488d865f68858bd Mon Sep 17 00:00:00 2001 From: Lowe Raivio Date: Thu, 9 Jan 2025 17:00:14 +0100 Subject: [PATCH 2/2] Added a copy of domain-model.md in the root dir... (in case automated testing requires it) --- domain-model.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/domain-model.md b/domain-model.md index e69de29b..d1c10451 100644 --- a/domain-model.md +++ b/domain-model.md @@ -0,0 +1,43 @@ + +### Requirements: +1. I want to add tasks to my todo list. +2. I want to see all the tasks in my todo list. +3. I want to change the status of a task between incomplete and complete. +4. I want to be able to get only the complete tasks. +5. I want to be able to get only the incomplete tasks. +6. I want to search for a task and receive a message that says it wasn't found if it doesn't exist. +7. I want to remove tasks from my list. +8. I want to see all the tasks in my list ordered alphabetically in ascending order. +9. I want to see all the tasks in my list ordered alphabetically in descending order. + +### Extended Reqirements: +10. I want to be able to get a task by a unique ID. +11. I want to update the name of a task by providing its ID and a new name. +12. I want to be able to change the status of a task by providing its ID. +13. I want to be able to see the date and time that I created each task. + + +### Domain Table + +| **User Story ID** | **Classes** | **Method/Property** | **Scenario** | **Outputs** | **Is Extension? (empty=False)** | +|-------------------|-------------|-------------------------|--------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------|---------------------------------| +| 1 | TodoList | AddTask | Add task with a string description/value | String stored in list | | +| 10 | TodoList | GetTask | Retrieve added task from list given ID | returns requested Task instance | True | +| 2 | TodoList | GetTaskList_all | Want all the tasks in a list | returns List of TaskEntry objects | | +| 4 | TodoList | GetTaskList_completed | Want all the completed tasks in a list | returns List of all completed TaskEntry objects | | +| 5 | TodoList | GetTaskList_incompleted | Want all the incompleted tasks in a list | returns List of all incompleted TaskEntry objects | | +| 3 | TodoList | ToggleTaskStatus | Given task ID, Toggle status between incomplete/complete | if incomplete, call result in toggled to complete. if Complete, call results in incomplete | True | +| 6-- | TodoList | SearchTask | Want to be able to search for a task without knowing the Task ID | returns list of Tasks that matches the search criteria, or if no matching enrties exist | | +| 7 | TodoList | RemoveTask | Remove a task from the list based on task id | List is changed with requested task removed | | +| 8 | TodoList | SetTaskOrder_Ascending | Change order of tasks. Ascends in alphabetically order | List order is changed to ascending alphabetically | | +| 9 | TodoList | SetTaskOrder_Descending | Change order of tasks. Descends in alphabetically order | List order is changed to descending alphabetically | | +| extra | TodoList | SetTaskOrder_asAdded | Change order of tasks to the order for when they where added | List order is changed to the order they where added | | +| 11 | TodoList | EditTaskName | Provide ID and new name to the task which we want to change | Task Entry is changed with the name | True | +| | | | | | | +| 1 | TaskEntry | Constructor | Create a Task Object, provide name and description | Task with name and description created | | +| 13 | TaskEntry | -- | Upon creation, time and date should be stored, and a ID managed by owner. | Task will have a creation date/time | True | +| 11 | TaskEntry | SetName (Name prop) | Change name of Task | Task name will be changed to provided name | | +| 6 | TaskEntry | GetName (Name prop) | Retrieve the name | returns Task name as string | | +| 3,12 | TaskEntry | Completed (prop) | Set Completion status to True/False | Completion Status will be changed | | +| 4,5 | TaskEntry | Completed (prop) | Retrieve the task completion status | Completion status will be returned as boolean value | | +| | | | | | | \ No newline at end of file