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


| Classes | Methods/Properties | Scenario | Outputs |
|-----------------|----------------------------------------------------|------------------------------------------------------------------------------|-----------------------------------
|ToDoList.cs |AddTask(string id, Task task) |add a new task to the todo list |the added task |
|ToDoList.cs |RemoveTask(string id) |remove task from todo list |the removed task |
|ToDoList.cs |ChangeTaskStatus(string id, bool complete) |change task status between complete/incomplete |the task |
|ToDoList.cs |GetTasksByStatus(bool complete) |list all complete or incomplete tasks |List<Task> |
|ToDoList.cs |SearchTask(string id) |search for a task to see if it exists or not |bool |
|ToDoList.cs |ListTasksAlphabeticalOrder(string order) |see all tasks ordered alphabetically in either acending or descending order |List<Task> |
|ToDoList.cs |ListTasksByPriority() |list all tasks by priority |List<Task> |
|ToDoList.cs |RenameTaskById(string id) |change the name/description of a task with its id |task |
|ToDoList.cs |GetTaskCompletionTime(string id) |get timestamp a task was completed |DateTime |
|ToDoList.cs |findTasksLongerThan5Days() |get all tasks that have laster more than 5 days |List<Task> |
|ToDoList.cs |findShortestDurationTask() |find the task that took the shortest time |Task |
|ToDoList.cs |findLongestDurationTask() |find the task that took the longest time |Task |
|ToDoList.cs |getTasksByCategory(string c) |list all tasks that belong to a given category |List<Task> |
|Task.cs |calculateDuration() |calculate how long a task was active before it was completed |TimeSpan |
|ToDoList.cs |getTaskCompletionTime(string id) |get the time a task was completed |DateTime |
|ToDoList.cs |getTaskCreationTime(string id) |get the time a task was created |DateTime |
|ToDoList.cs |printAllTasks() |show in console the information about all tasks |void, text in console |
12 changes: 0 additions & 12 deletions tdd-todo-list.CSharp.Main/Extension.cs

This file was deleted.

28 changes: 26 additions & 2 deletions tdd-todo-list.CSharp.Main/Program.cs
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");


using NUnit.Framework;
using tdd_todo_list.CSharp.Main;
using Task = tdd_todo_list.CSharp.Main.Task;

DateTime now = DateTime.Now;
DateTime day = DateTime.Now.AddDays(1);
DateTime day2 = DateTime.Now.AddDays(2);
TodoList list = new TodoList();

Task task1 = new Task("1", "Water plants", 1, false, "Gardening");
Task task2 = new Task("2", "Fix car", 2, false, "Work");
Task task3 = new Task("1", "Take out trash", 1, true, "Work");
Task task4 = new Task("2", "Paint house", 3, false, "Work");



list.AddTask("1", task1);
list.AddTask("2", task2);
list.AddTask("3", task3);
list.AddTask("4", task4);


list.printAllTasks();

40 changes: 40 additions & 0 deletions tdd-todo-list.CSharp.Main/Task.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tdd_todo_list.CSharp.Main
{
public class Task(string id, string desc, int priority, bool completed, string category)
{
private string _id = id;
private string _desc = desc;
private int _priority = priority;
private bool _completed = completed;
private string _category = category;
private DateTime _created = DateTime.Now;
private DateTime _finished;
private TimeSpan _duration;

public string Id { get => _id; set => _id = value; }
public string Desc { get => _desc; set => _desc = value; }
public int Priority { get => _priority; set => _priority = value; }
public bool Completed { get => _completed; set => _completed = value; }
public string Category { get => _category; set => _category = value; }
public DateTime Created { get => _created; }
public DateTime Finished { get => _finished; set => _finished = value; }
public TimeSpan Duration { get => _duration; set => _duration = value; }


public TimeSpan calculateDuration()
{
TimeSpan duration = this._finished.Subtract(this._created);
this._duration = duration;
return duration;
}

}


}
151 changes: 151 additions & 0 deletions tdd-todo-list.CSharp.Main/ToDoList.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,163 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata.Ecma335;
using System.Text;
using System.Threading.Tasks;

namespace tdd_todo_list.CSharp.Main
{
public class TodoList
{

public Dictionary<string, Task> list = new Dictionary<string, Task>();

public Task AddTask(string id, Task task)
{
list.Add(id, task);
return task;
}

public Task ChangeTaskStatus(string id, bool v)
{
Task task = list[id];
task.Completed = v;
return task;
}

public List<Task> GetTasksByStatus(bool v)
{
List<Task> tasks = new List<Task>();
foreach (var task in list.Values) {
if(task.Completed == v)
{
tasks.Add(task);
}
}
return tasks;
}

public List<Task> ListTasksAlphabeticalOrder(string v)
{
List<Task> result = list.Values.ToList();
result.Sort((x, y) => string.Compare(x.Desc, y.Desc));

if (v.ToUpper().Equals("DESCENDING"))
{
result.Reverse();
}
return result;

}

public List<Task> ListTasksByPriority(int v)
{
List<Task> values = list.Values.ToList();
List<Task> result = new List<Task>();

foreach (var task in values)
{
if(task.Priority == v)
{
result.Add(task);
}
}
return result;
}

public Task RemoveTask(string id)
{
Task task = list[id];
list.Remove(id);
return task;
}

public Task RenameTaskbyId(string id, string v)
{
Task task = list[id];
task.Desc = v;
return task;
}

public bool SearchTask(string id)
{
if(list.ContainsKey(id)) { return true; }
else return false;
}

public List<Task> GetTasksByCategory(string c)
{
List<Task> tasks = new List<Task>();
foreach (var task in list.Values)
{
if (task.Category.Equals(c))
{
tasks.Add(task);
}
}
return tasks;
}

public DateTime getTaskCompletionTime(string id)
{
return list[id].Finished;
}

public TimeSpan getTaskDuration(string id)
{
Task task = list[id];
return task.Finished.Subtract(task.Created);

}

public Task findLongestDurationTask()
{
List<Task> tasks = list.Values.ToList();
tasks.Sort((task1, task2) => task1.Duration.CompareTo(task2.Duration));
tasks.Reverse();
return tasks.First();
}

public Task findShortestDurationTask()
{
List<Task> tasks = list.Values.ToList();
tasks.Sort((task1, task2) => task1.Duration.CompareTo(task2.Duration));
return tasks.First();
}

public void printTaskDurationById(string id)
{
Task task = list[id];
Console.WriteLine(task.Duration);
}


public List<Task> findTasksLongerThan5Days()
{
List<Task> tasks = list.Values.ToList();
List<Task> fiveDayTasks = new List<Task>();
TimeSpan fivedays = TimeSpan.FromDays(5);

foreach (Task task in tasks)
{
if(task.Duration.CompareTo(fivedays) > 0)
{
fiveDayTasks.Add(task);
}
}
return fiveDayTasks;
}

public void printAllTasks()
{
List<Task> tasks = list.Values.ToList();
foreach(Task task in tasks)
{
Console.WriteLine($"Task id: {task.Id}\nTask description: {task.Desc}\nTask priority: {task.Priority}" +
$"\nTask completed: {task.Completed}\nTask category: {task.Category}\nTask creation time: {task.Created}" +
$"\nTask completion time: {task.Finished}\nTask duration: {task.Duration}\n");
}
}

}
}
Loading
Loading