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

| Classes | Methods/Properties | Scenario | Outputs
| ----------- | ------------------------------------------------------ | --------------------------------------- | ---------------------------------
| Task.cs | string Name | Name the task | Task name
| Task.cs | Guid Id | Unique identifier for the task | Task ID
| Task.cs | bool IsComplete | Track completion status | True or false
| Task.cs | enum Priority | Task priority Low, Medium, High | Priority status of 3 possible levels
| Task.cs | enum Category | Task categories for differation | Category name
| TodoList.cs | AddTask(string name, enum priority, enum category) | Add task to the list | Task added to list
| TodoList.cs | GetAllTasks() | View all tasks | List of tasks
| TodoList.cs | GetCompletedTasks() | View only completed tasks | Filtered list of tasks
| TodoList.cs | GetIncompleteTasks() | View only incomplete tasks | Filtered list of tasks
| TodoList.cs | ChangeTaskStatus(Guid id, bool isComplete) | Mark task complete/incomplete by ID | Updated task status
| TodoList.cs | SearchTask(string name) | Search task by name | Task found or "Not Found" message
| TodoList.cs | RemoveTask(Guid id) | Remove task from list | Task removed by id
| TodoList.cs | GetTasksAscendingAZ() | Get tasks sorted A-Z | Alphabetically sorted list
| TodoList.cs | GetTasksDescendingAZ() | Get tasks sorted Z-A | Alphabetically sorted list
| TodoList.cs | GetTasksByPriority(string priority) | List tasks by selected priority | List of tasks by priority

# Extension Requirements

| Classes | Methods/Properties | Scenario | Outputs
| ----------- | ------------------------------------------ | ---------------------------------------- | -------------
| Task.cs | GetTaskById(int id) | Retrieve task by ID | Task with matching id
| Task.cs | UpdateTaskName(int id, string newName) | Update task name | Updated task name
| Task.cs | ChangeStatusById(int id, bool isComplete) | Change task status using ID | Updated task
| Task.cs | CreatedAt(DateTime ) | Show creation time | DateTime of creation
| Task.cs | CompletedAt (DateTime) | Show completed time | DateTime of completion
| ToDoList.cs | GetLongestCompletionTime() | Find task that took longest to complete | Task with biggest difference in CreatedAt & CompletedAt
| ToDoList.cs | GetShortestCompletionTime() | Find task that took shortest to complete | Task with shortest difference in CreatedAt & CompletedAt
| ToDoList.cs | GetTasksLongerThanDays(int days) | List tasks completed after x days | List of tasks where the time it took is longer than x days
| ToDoList.cs | GetTasksByCategory(enum category) | List all tasks by category | List of tasks displayed by category
30 changes: 30 additions & 0 deletions tdd-todo-list.CSharp.Main/Task.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tdd_todo_list.CSharp.Main
{
public class Task
{
public Guid Id { get; set; }
public string Name { get; set; }
public bool IsComplete { get; set; }
public Priority Priority { get; set; }
public Category Category { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime CompletedAt { get; set; }

public Task(string name, Priority priority, Category category)
{
Id = Guid.NewGuid();
Name = name;
Priority = priority;
Category = category;
IsComplete = false;
CreatedAt = DateTime.Now;
}
}
}
122 changes: 121 additions & 1 deletion tdd-todo-list.CSharp.Main/ToDoList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,127 @@

namespace tdd_todo_list.CSharp.Main
{
public class TodoList

public enum Priority
{
Low,
Medium,
High
}
public enum Category
{
Work,
School,
Life
}

public class ToDoList
{
private List<Task> tasks = new List<Task>();

public void AddTask(string name, Priority priority, Category category)
{
var task = new Task(name, priority, category);
tasks.Add(task);
}

public List<Task> GetAllTasks()
{
return tasks;
}

public List<Task> GetCompletedTasks()
{
return tasks.Where(x => x.IsComplete).ToList();
}

public List<Task> GetInCompletedTasks()
{
return tasks.Where(x => !x.IsComplete).ToList();
}

public List<Task> ChangeTaskStatus(Guid id, bool isComplete)
{
var task = tasks.Find(x => x.Id == id);
if (task != null)
{
task.IsComplete = isComplete;
task.CompletedAt = isComplete ? DateTime.Now : default;
}
return tasks;
}

public Task? SearchTask(string name)
{
return tasks.Find(x => x.Name == name);
}

public void RemoveTask(Guid id)
{
var task = tasks.FirstOrDefault(t => t.Id == id);
if (task != null)
{
tasks.Remove(task);
}
}

public List<Task> GetTasksAscendingAZ()
{
return tasks.OrderBy(x => x.Name).ToList();
}

public List<Task> GetTasksDescendingAZ()
{
return tasks.OrderByDescending(x => x.Name).ToList();
}

public List<Task> GetTasksByPriority()
{
return tasks.OrderByDescending(x =>x.Priority).ToList();
}

public Task? GetTaskById(Guid id)
{
return tasks.Find(x => x.Id == id);
}

public void UpdateTaskName(Guid id, string newName)
{
var task = tasks.Find(x => x.Id == id);
if ( task != null)
{
task.Name = newName;
}
}

public void ChangeStatusById(Guid id, bool isComplete)
{
var task = tasks.Find(x => x.Id == id);
if ( task != null)
{
task.IsComplete = isComplete;
task.CompletedAt = isComplete ? DateTime.Now : default;
}
}

public Task GetLongestCompletionTime()
{
return null;

Check warning on line 114 in tdd-todo-list.CSharp.Main/ToDoList.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 114 in tdd-todo-list.CSharp.Main/ToDoList.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 114 in tdd-todo-list.CSharp.Main/ToDoList.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 114 in tdd-todo-list.CSharp.Main/ToDoList.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.
}

public Task GetShortestCompletionTime()
{
return null;

Check warning on line 119 in tdd-todo-list.CSharp.Main/ToDoList.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 119 in tdd-todo-list.CSharp.Main/ToDoList.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 119 in tdd-todo-list.CSharp.Main/ToDoList.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 119 in tdd-todo-list.CSharp.Main/ToDoList.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.
}

public List<Task> GetTasksLongerThanDays(int days)
{
return null;

Check warning on line 124 in tdd-todo-list.CSharp.Main/ToDoList.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 124 in tdd-todo-list.CSharp.Main/ToDoList.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 124 in tdd-todo-list.CSharp.Main/ToDoList.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 124 in tdd-todo-list.CSharp.Main/ToDoList.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.
}

public List<Task> GetTasksByCategory(Category category)
{
return tasks.Where(x => x.Category == category).ToList();
}
}
}
166 changes: 161 additions & 5 deletions tdd-todo-list.CSharp.Test/CoreTests.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,173 @@
using tdd_todo_list.CSharp.Main;
using NUnit.Framework;
using NUnit.Framework;
using System.Collections.Generic;
using tdd_todo_list.CSharp.Main;

namespace tdd_todo_list.CSharp.Test
{
[TestFixture]
public class CoreTests
{
[Test]
public void AddedTaskToList()
{
//arrange
ToDoList list = new ToDoList();
list.AddTask("Test", Priority.High, Category.Work);

//act
var tasks = list.GetAllTasks();

//assert
Assert.That(tasks[0].Name, Is.EqualTo("Test"));
}

[Test]
public void ShowsAllTasksOnList()
{
//arrange
ToDoList list = new ToDoList();
list.AddTask("Test1", Priority.High, Category.Work);
list.AddTask("Test2", Priority.Medium, Category.School);
list.AddTask("Test3", Priority.Low, Category.Life);

//act
var allTasks = list.GetAllTasks();

//assert
Assert.That(allTasks.Count, Is.EqualTo(3));

}

[Test]
public void ChangeTaskStatus()
{
//arrange
ToDoList list = new ToDoList();
list.AddTask("Test", Priority.High, Category.Work);

//act
var changed = list.GetAllTasks()[0];
list.ChangeTaskStatus(changed.Id, true);

//assert
Assert.That(changed.IsComplete, Is.True);
}

[Test]
public void GetOnlyCompletedTasks()
{
//arrange
ToDoList list = new ToDoList();
list.AddTask("Test1", Priority.High, Category.Work);
list.AddTask("Test2", Priority.Medium, Category.School);

//act
var tasks = list.GetAllTasks()[1];
list.ChangeTaskStatus(tasks.Id, true);

//assert
var completedTasks = list.GetCompletedTasks();
Assert.That(completedTasks[0].Name, Is.EqualTo("Test2"));
}

[Test]
public void GetOnlyInCompletedTasks()
{
//arrange
ToDoList list = new ToDoList();
list.AddTask("Test1", Priority.High, Category.Work);
list.AddTask("Test2", Priority.Medium, Category.School);

//act
var completedTasks = list.GetInCompletedTasks();

//assert
Assert.That(completedTasks.Count, Is.EqualTo(2));
}

[Test]
public void ErrorMessageIfTaskNotFound()
{
//arrange
ToDoList list = new ToDoList();
list.AddTask("Test1", Priority.High, Category.Work);

//act
var search = list.SearchTask("Test32");

//assert
Assert.Null(search);
}

[Test]
public void FirstTest()
public void RemoveTaskById()
{
TodoList core = new TodoList();
Assert.Pass();
//arrange
ToDoList list = new ToDoList();
list.AddTask("Test1", Priority.High, Category.Work);
var task = list.GetAllTasks().First();

//act
list.RemoveTask(task.Id);

//assert
Assert.That(list.GetAllTasks().Count, Is.EqualTo(0));
}

[Test]
public void GetTasksAscendingAZ()
{
//arrange
ToDoList list = new ToDoList();
list.AddTask("Bread", Priority.High, Category.Work);
list.AddTask("Ants", Priority.High, Category.Work);
list.AddTask("Crab", Priority.High, Category.Work);

//act
var ascendingList = list.GetTasksAscendingAZ();

//assert
Assert.That(ascendingList[0].Name, Is.EqualTo("Ants"));
Assert.That(ascendingList[1].Name, Is.EqualTo("Bread"));
Assert.That(ascendingList[2].Name, Is.EqualTo("Crab"));
}

[Test]
public void GetTasksDescendingAZ()
{
//arrange
ToDoList list = new ToDoList();

list.AddTask("Bread", Priority.High, Category.Work);
list.AddTask("Ants", Priority.High, Category.Work);
list.AddTask("Crab", Priority.High, Category.Work);

//act
var ascendingList = list.GetTasksDescendingAZ();

//assert
Assert.That(ascendingList[0].Name, Is.EqualTo("Crab"));
Assert.That(ascendingList[1].Name, Is.EqualTo("Bread"));
Assert.That(ascendingList[2].Name, Is.EqualTo("Ants"));
}

[Test]
public void ListTasksByPriority()
{
//arrange
ToDoList list = new ToDoList();

list.AddTask("Test1", Priority.Medium, Category.Work);
list.AddTask("Test2", Priority.Low, Category.School);
list.AddTask("Test3", Priority.High, Category.Life);

//act
var byPriority = list.GetTasksByPriority();

//assert
Assert.That(byPriority[0].Name, Is.EqualTo("Test3"));
Assert.That(byPriority[1].Name, Is.EqualTo("Test1"));
Assert.That(byPriority[2].Name, Is.EqualTo("Test2"));
}
}
}
Loading
Loading