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
42 changes: 42 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Domain Model

- 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 prioritise tasks e.g. low, medium, high
- I want to list all tasks by priority


| Classes | Methods/Properties | Scenario | Outputs |
|-------------------|-------------------------------|---------------|-----------|
|ToDoList.cs |AddTask(Task t) |adds task t to the todolist |void |
|ToDoList.cs |GetAllTasks() |fetches out all tasks |List<TaskItem> |
|TaskItem.cs |ChangeStatus() |flips boolean value of StatusComplete |void |
|ToDoList.cs |GetAllCompleteTasks() |fetches all tasks where statusComplete == true|List<TaskItem> |
|ToDoList.cs |GetAllIncompleteTasks() |fetches all tasks where statusComplete == false|List<TaskItem> |
|ToDoList.cs |DoesTaskExist(Task t) |Checks if a given task exists in toDoList|bool |
|ToDoList.cs |RemoveTask(Task t) |Removes a given TaskItem from todoList.|void |
|ToDoList.cs |GetAllTasksInOrder() |fetches all tasks in alphabetical order |List<TaskItem> |
|ToDoList.cs |GetAllTasksInReverseOrder() |fetches all tasks in reverse alphabetical order |List<TaskItem> |
|ToDoList.cs |GetTasksSortedByPriority() |fetches all tasks in order by priority |List<TaskItem> |



## Extension tests

- 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.
- I want to be able to see the date and time that I completed a task.
- I want to know which task took the longest amount of time to complete.
- I want to know which task took the shortest amount of time to complete.
- I want to know which tasks took longer than 5 days to complete.
- I want to categorise tasks e.g. study, work, admin etc
- I want to list all tasks by category
52 changes: 52 additions & 0 deletions tdd-todo-list.CSharp.Main/Program.cs
Original file line number Diff line number Diff line change
@@ -1,2 +1,54 @@
// See https://aka.ms/new-console-template for more information
using tdd_todo_list.CSharp.Main;
using TaskItem = tdd_todo_list.CSharp.Main.TaskItem;

Console.WriteLine("Hello, World!");

TodoList todoList = new TodoList();
TaskItem t1 = new TaskItem("vaske", "vaske trapp og kjeller", 3, "husarbeid");
TaskItem t2 = new TaskItem("rydde", "rydde kjøkken", 1, "husarbeid");
TaskItem t3 = new TaskItem("lade", "lade mobilen", 1, "annet", true);
todoList.AddTask(t1);
todoList.AddTask(t2);
todoList.AddTask(t3);

todoList.PrintAllTasks();

todoList.GetAllTasksInOrder();
todoList.PrintAllTasks();

todoList.PrintListOfTasks(todoList.GetCompletedTasks());
Console.WriteLine();

Console.WriteLine(todoList.GetTaskById(1));

todoList.UpdateNameById(1, "nyttNavn");

Console.WriteLine();
todoList.PrintAllTasks();

Console.WriteLine();
Console.WriteLine();

Console.WriteLine(t1.ToString());
t1.ChangeStatus();
Console.WriteLine(t1.ToString());

Console.WriteLine();
Console.WriteLine(todoList.DoesTaskExistByName("rydde"));

Console.WriteLine();
Console.WriteLine(todoList.GetTaskById(1));

todoList.UpdateNameById(1, "nyttNavnForTest");
todoList.PrintAllTasks();
Console.WriteLine(t1.Name);

Console.WriteLine();
Console.WriteLine(t3.ShowDateTimeOfCreation());

Console.WriteLine();
Console.WriteLine(t2.ShowDateTimeOfCompletion());
t2.ChangeStatus();
t2.ChangeStatus();
Console.WriteLine(t2.ShowDateTimeOfCompletion());
71 changes: 71 additions & 0 deletions tdd-todo-list.CSharp.Main/TaskItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
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
{
private static int _nextId = 1;

private int _id;
private string _name;
private bool _statusComplete;
private string _text;
private int _priority;
private string _category;

Check warning on line 18 in tdd-todo-list.CSharp.Main/TaskItem.cs

View workflow job for this annotation

GitHub Actions / build

The field 'TaskItem._category' is never used

Check warning on line 18 in tdd-todo-list.CSharp.Main/TaskItem.cs

View workflow job for this annotation

GitHub Actions / build

The field 'TaskItem._category' is never used

Check warning on line 18 in tdd-todo-list.CSharp.Main/TaskItem.cs

View workflow job for this annotation

GitHub Actions / build

The field 'TaskItem._category' is never used

Check warning on line 18 in tdd-todo-list.CSharp.Main/TaskItem.cs

View workflow job for this annotation

GitHub Actions / build

The field 'TaskItem._category' is never used
public DateTime _created;
public DateTime _completed;


public TaskItem(string name, string text, int priority, string category, bool statusComplete=false)

Check warning on line 23 in tdd-todo-list.CSharp.Main/TaskItem.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_category' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 23 in tdd-todo-list.CSharp.Main/TaskItem.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_category' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 23 in tdd-todo-list.CSharp.Main/TaskItem.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_category' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 23 in tdd-todo-list.CSharp.Main/TaskItem.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_category' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
{
_id = _nextId++;
_name = name;
_text = text;
_priority = priority;
_statusComplete = statusComplete;
_created = DateTime.Now;

}
public bool StatusComplete { get { return _statusComplete; } set { _statusComplete = value; } }
public string Text { get { return _text; } }
public string Name { get { return _name; } set { _name = value; } }
public int Id { get { return _id; } }
public DateTime Completed { get { return _completed; } set { _completed = value; } }
public int Priority { get { return _priority; } }

override
public string ToString()
{
return $" id: {_id} name: {_name} - text: {_text} - priority: {_priority} - status: {_statusComplete}";
}

public string ShowDateTimeOfCreation()
{
return _created.ToString() ;
}

public string ShowDateTimeOfCompletion()
{
return _completed.ToString();
}

public void ChangeStatus()
{
_statusComplete = !_statusComplete;
_completed = _statusComplete ? DateTime.Now : DateTime.MaxValue;
}









}
}
104 changes: 104 additions & 0 deletions tdd-todo-list.CSharp.Main/ToDoList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,109 @@ namespace tdd_todo_list.CSharp.Main
{
public class TodoList
{
private List<TaskItem> _tasks = new List<TaskItem>();

public TodoList()
{


}

//public List<TaskItem> Tasks { get { return _tasks; } }


public void AddTask(TaskItem task)
{
_tasks.Add(task);
}

public void PrintAllTasks()
{
foreach (var task in _tasks)
{
Console.WriteLine(task.ToString());
}
}

public List<TaskItem> GetAllTasks()
{
return _tasks;
}

public void ChangeStatus(TaskItem task)
{
task.StatusComplete = !task.StatusComplete;


task.Completed = task.StatusComplete ? DateTime.Now : DateTime.MaxValue;
}

public List<TaskItem> GetCompletedTasks()
{
return _tasks.Where(t => t.StatusComplete.Equals("complete")).ToList();
}

public List<TaskItem> GetIncompleteTasks()
{
return _tasks.Where(t => t.StatusComplete.Equals("incomplete")).ToList();
}

public void RemoveTask(TaskItem task)
{
_tasks.Remove(task);
}

public List<TaskItem> GetAllTasksInOrder()
{
return _tasks.OrderBy(t => t.Name).ToList();
}

public List<TaskItem> GetAllTasksInReverseOrder()
{
return _tasks.OrderByDescending(t => t.Name).ToList();
}

public List<TaskItem> GetAllTasksSortedByPriority()
{
return _tasks.OrderBy(t => t.Priority).ToList();
}

public void PrintListOfTasks(List<TaskItem> tasks)
{
foreach(var task in tasks)
{
Console.WriteLine(task.ToString());
}
}

public TaskItem GetTaskById(int id)
{
return _tasks.First(t => t.Id == id);
}

public void UpdateNameById(int id, string name)
{

GetTaskById(id).Name = name;
}

public void UpdateStatusById(int id, bool statusComplete)
{
TaskItem t = GetTaskById(id);
t.StatusComplete = statusComplete;

t.Completed = t.StatusComplete ? DateTime.Now : DateTime.MaxValue;
}

public bool DoesTaskExistByName(string name)
{
return _tasks.Any(t => t.Name == name);
}

public bool DoesTaskExist(TaskItem t)
{
return _tasks.Contains(t);
}
}

}
Loading
Loading