Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -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 | |
| | | | | | |
75 changes: 75 additions & 0 deletions tdd-todo-list.CSharp.Main/TaskEntry.cs
Original file line number Diff line number Diff line change
@@ -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<TaskEntry>
{
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<TaskEntry>
{
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<TaskEntry>
{
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<TaskEntry>
{
public int Compare(TaskEntry? x, TaskEntry? y)
{
if (x == null || y == null)
return 0;
return x._name.CompareTo(y._name) * -1;
}
}
public static IComparer<TaskEntry> get_SortByDate()
{
return new SortByDate();
}
public static IComparer<TaskEntry> get_SortByName_ascending()
{
return new SortByName_ascending();
}
public static IComparer<TaskEntry> get_SortByName_descending()
{
return new SortByName_descending();
}

public int CompareTo(TaskEntry? other)
{
return get_SortByDate().Compare(this,other);
}
}
}
85 changes: 85 additions & 0 deletions tdd-todo-list.CSharp.Main/ToDoList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,92 @@

namespace tdd_todo_list.CSharp.Main
{


public class TodoList
{
private Dictionary<int, TaskEntry> _tasks = new Dictionary<int, TaskEntry>();
public int NrOfTasks { get => _tasks.Count; }

private IComparer<TaskEntry> _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<TaskEntry> 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<TaskEntry> GetTaskList_all()
{
return this._tasks.Values.Order(_orderComparable).ToList();
}
public List<TaskEntry> GetTaskList_completed()
{

return this._tasks.Values.ToList().Where(x => x.Completed).Order(_orderComparable).ToList();
}
public List<TaskEntry> GetTaskList_incompleted()
{
return this._tasks.Values.ToList().Where(x => !x.Completed).Order(_orderComparable).ToList();
}

}
}
43 changes: 43 additions & 0 deletions tdd-todo-list.CSharp.Main/domain-model.md
Original file line number Diff line number Diff line change
@@ -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 | |
| | | | | | |
2 changes: 1 addition & 1 deletion tdd-todo-list.CSharp.Main/tdd-todo-list.CSharp.Main.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand Down
Loading
Loading