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

## Core requirements

1. I want to add tasks to my todo list.

| Classes | Methods/Properties | Scenario | Outputs |
|-------------|--------------------|-----------------------------------|---------|
| ToDoList.cs | Add(TaskItem task) | Add task to List<TaskItem> MyList | bool |


2. I want to see all the tasks in my todo list.

| Classes | Methods/Properties | Scenario | Outputs |
|-------------|--------------------------------------------|-------------------------------------------|----------------|
| ToDoList.cs | public List<TaskItem> MyList { get; set; } | Return all tasks in List<TaskItem> MyList | List<TaskItem> |


3. I want to change the status of a task between incomplete and complete.

| Classes | Methods/Properties | Scenario | Outputs |
|-------------|---------------------------------------|-----------------------------------|---------|
| TaskItem.cs | public bool IsCompleted { get; set; } | Changes IsCompleted to true/false | bool |


4. I want to be able to get only the complete tasks.

| Classes | Methods/Properties | Scenario | Outputs |
|-------------|----------------------------------------------------|--------------------------------|----------------|
| ToDoList.cs | public List<TaskItem> CompletedTasks { get; set; } | Return all the completed tasks | List<TaskItem> |


5. I want to be able to get only the incomplete tasks.

| Classes | Methods/Properties | Scenario | Outputs |
|-------------|------------------------------------------------------|----------------------------------|----------------|
| ToDoList.cs | public List<TaskItem> IncompletedTasks { get; set; } | Return all the incompleted tasks | List<TaskItem> |


6. I want to search for a task and receive a message that says it wasn't found if it doesn't exist.

| Classes | Methods/Properties | Scenario | Outputs |
|-------------|----------------------------------------|---------------------------------------|---------|
| ToDoList.cs | Search(TodoList todolist, string name) | Returns task name or "Task not found" | string |


7. I want to remove tasks from my list.

| Classes | Methods/Properties | Scenario | Outputs |
|-------------|-----------------------|----------------------------------------|---------|
| ToDoList.cs | Remove(TaskItem task) | Remove task from List<TaskItem> MyList | bool |


8. I want to see all the tasks in my list ordered alphabetically in ascending order.

| Classes | Methods/Properties | Scenario | Outputs |
|-------------|----------------------------------------------------------|---------------------------------------------------|----------------|
| ToDoList.cs | public List<TaskItem> TasksSortedAscending { get; set; } | Return the list in alphabetically ascending order | List<TaskItem> |


9. I want to see all the tasks in my list ordered alphabetically in descending order.

| Classes | Methods/Properties | Scenario | Outputs |
|-------------|-----------------------------------------------------------|----------------------------------------------------|----------------|
| ToDoList.cs | public List<TaskItem> TasksSortedDescending { get; set; } | Return the list in alphabetically descending order | List<TaskItem> |


10. I want to prioritise tasks e.g. low, medium, high

| Classes | Methods/Properties | Scenario | Outputs |
|-------------|----------------------------------------|--------------------------------------------------|---------|
| TaskItem.cs | public Priority priority { get; set; } | Possible to set task to low/medium/high priority | bool |


11. I want to list all tasks by priority

| Classes | Methods/Properties | Scenario | Outputs |
|-------------|-----------------------------------------------------------|-----------------------------------|----------------|
| ToDoList.cs | public List<TaskItem> TasksSortedByPriority { get; set; } | Return the list in priority order | List<TaskItem> |
15 changes: 15 additions & 0 deletions tdd-todo-list.CSharp.Main/Enums.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tdd_todo_list.CSharp.Main
{
public enum Priority
{
High,
Medium,
Low
}
}
16 changes: 16 additions & 0 deletions tdd-todo-list.CSharp.Main/TaskItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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
{
//public Guid Id { get; set; } = Guid.NewGuid();

public string Name { get; set; }

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

View workflow job for this annotation

GitHub Actions / build

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

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

View workflow job for this annotation

GitHub Actions / build

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

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

View workflow job for this annotation

GitHub Actions / build

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

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

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public bool IsCompleted { get; set; } = false;
public Priority Priority { get; set; }
}
}
20 changes: 20 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,25 @@ namespace tdd_todo_list.CSharp.Main
{
public class TodoList
{
public List<TaskItem> MyList { get; set; } = new List<TaskItem>();

public List<TaskItem> CompletedTasks { get { return MyList.Where(x => x.IsCompleted == true).ToList(); } }
public List<TaskItem> IncompletedTasks { get { return MyList.Where(x => x.IsCompleted == false).ToList(); } }

public List<TaskItem> TasksSortedAscending { get { return MyList.OrderBy(x => x.Name).ToList(); } }
public List<TaskItem> TasksSortedDescending { get { return MyList.OrderByDescending(x => x.Name).ToList(); } }
public List<TaskItem> TasksSortedByPriority { get { return MyList.OrderBy(x => x.Priority).ToList(); } }

public string Search(TodoList todolist, string name)
{
if(todolist.MyList.Any(t => t.Name == name))
{
return name;
}
else
{
return "Task not found";
}
}
}
}
224 changes: 218 additions & 6 deletions tdd-todo-list.CSharp.Test/CoreTests.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,229 @@
using tdd_todo_list.CSharp.Main;
using NUnit.Framework;
using NUnit.Framework;
using System.Xml.Linq;
using tdd_todo_list.CSharp.Main;

namespace tdd_todo_list.CSharp.Test
{
[TestFixture]
public class CoreTests
{

// 1. I want to add tasks to my todo list.
[Test]
public void FirstTest()
public void AddTaskToToDoList()
{
TodoList core = new TodoList();
Assert.Pass();
// arrange
TodoList todolist = new TodoList();
var task = new TaskItem { Name = "Do the dishes" };

// act
todolist.MyList.Add(task);

//assert
Assert.IsTrue(todolist.MyList.Count == 1);
Assert.That(todolist.MyList[0].Name, Is.EqualTo("Do the dishes"));
}

// 2. I want to see all the tasks in my todo list.
[Test]
public void SeeAllTasksInToDoList()
{
// arrange
TodoList todolist = new TodoList();
var task1 = new TaskItem { Name = "Do the dishes" };
var task2 = new TaskItem { Name = "Clean the bathroom" };
todolist.MyList.Add(task1);
todolist.MyList.Add(task2);

//act
var result = todolist.MyList;

//assert
Assert.IsTrue(todolist.MyList.Count == 2);
Assert.That(todolist.MyList[0].Name, Is.EqualTo(result[0].Name));
Assert.That(todolist.MyList[1].Name, Is.EqualTo(result[1].Name));
}

// 3. I want to change the status of a task between incomplete and complete.
[Test]
public void ChangeStatusOfTask()
{
// arrange
TodoList todolist = new TodoList();
var task1 = new TaskItem { Name = "Do the dishes" };
var task2 = new TaskItem { Name = "Clean the bathroom", IsCompleted = true };
todolist.MyList.Add(task1);
todolist.MyList.Add(task2);

// act
todolist.MyList[0].IsCompleted = true;
todolist.MyList[1].IsCompleted = false;

// assert
Assert.IsTrue(todolist.MyList[0].IsCompleted == true);
Assert.IsTrue(todolist.MyList[1].IsCompleted == false);
}

// 4. I want to be able to get only the complete tasks.
[Test]
public void GetCompleteTasks()
{
// arrange
TodoList todolist = new TodoList();
var task1 = new TaskItem { Name = "Do the dishes" };
var task2 = new TaskItem { Name = "Clean the bathroom", IsCompleted = true };
todolist.MyList.Add(task1);
todolist.MyList.Add(task2);

// act
var result = todolist.CompletedTasks;

// assert
Assert.IsTrue(result.Count == 1);
Assert.That(result[0].Name, Is.EqualTo(todolist.MyList[1].Name));
}

// 5. I want to be able to get only the incomplete tasks.
[Test]
public void GetInompleteTasks()
{
// arrange
TodoList todolist = new TodoList();
var task1 = new TaskItem { Name = "Do the dishes" };
var task2 = new TaskItem { Name = "Clean the bathroom", IsCompleted = true };
todolist.MyList.Add(task1);
todolist.MyList.Add(task2);

// act
var result = todolist.IncompletedTasks;

// assert
Assert.IsTrue(result.Count == 1);
Assert.That(result[0].Name, Is.EqualTo(todolist.MyList[0].Name));
}

// 6. I want to search for a task and receive a message that says it wasn't found if it doesn't exist.
[Test]
public void SearchForTask()
{
// arrange
TodoList todolist = new TodoList();
var task = new TaskItem { Name = "Do the dishes" };
todolist.MyList.Add(task);

// act
var result1 = todolist.Search(todolist, "Do the dishes");
var result2 = todolist.Search(todolist, "Walk the dog");

// assert
Assert.IsTrue(result1 == "Do the dishes");
Assert.IsTrue(result2 == "Task not found");
}

// 7. I want to remove tasks from my list.
[Test]
public void RemoveTaskFromToDoList()
{
// arrange
TodoList todolist = new TodoList();
var task1 = new TaskItem { Name = "Do the dishes" };
var task2 = new TaskItem { Name = "Clean the bathroom" };
todolist.MyList.Add(task1);
todolist.MyList.Add(task2);

// act
todolist.MyList.Remove(task1);

//assert
Assert.IsTrue(todolist.MyList.Count == 1);
Assert.That(todolist.MyList[0].Name, Is.EqualTo("Clean the bathroom"));
}

// 8. I want to see all the tasks in my list ordered alphabetically in ascending order.
[Test]
public void GetTasksAlphabeticallyInAscendingOrder()
{
// arrange
TodoList todolist = new TodoList();
var task1 = new TaskItem { Name = "Do the dishes" };
var task2 = new TaskItem { Name = "Clean the bathroom" };
todolist.MyList.Add(task1);
todolist.MyList.Add(task2);

// act
var result = todolist.TasksSortedAscending;

// assert
Assert.IsTrue(result.Count == 2);
Assert.That(result[0].Name, Is.EqualTo(todolist.MyList[1].Name));
Assert.That(result[1].Name, Is.EqualTo(todolist.MyList[0].Name));
}

// 9. I want to see all the tasks in my list ordered alphabetically in descending order.
[Test]
public void GetTasksAlphabeticallyInDescendingOrder()
{
// arrange
TodoList todolist = new TodoList();
var task1 = new TaskItem { Name = "Clean the bathroom" };
var task2 = new TaskItem { Name = "Do the dishes" };
todolist.MyList.Add(task1);
todolist.MyList.Add(task2);

// act
var result = todolist.TasksSortedDescending;

// assert
Assert.IsTrue(result.Count == 2);
Assert.That(result[0].Name, Is.EqualTo(todolist.MyList[1].Name));
Assert.That(result[1].Name, Is.EqualTo(todolist.MyList[0].Name));
}

// 10. I want to prioritise tasks e.g. low, medium, high
[Test]
public void PrioritiseTask()
{
// arrange
TodoList todolist = new TodoList();
var task1 = new TaskItem { Name = "Clean the bathroom" };
var task2 = new TaskItem { Name = "Do the dishes" };
var task3 = new TaskItem { Name = "Walk the dog" };
todolist.MyList.Add(task1);
todolist.MyList.Add(task2);
todolist.MyList.Add(task3);

// act
todolist.MyList[0].Priority = Priority.Low;
todolist.MyList[1].Priority = Priority.High;
todolist.MyList[2].Priority = Priority.Medium;

// assert
Assert.IsTrue(todolist.MyList[0].Priority == Priority.Low);
Assert.IsTrue(todolist.MyList[1].Priority == Priority.High);
Assert.IsTrue(todolist.MyList[2].Priority == Priority.Medium);
}

// 11. I want to list all tasks by priority
[Test]
public void GetTasksInPriorityOrder()
{
// arrange
TodoList todolist = new TodoList();
var task1 = new TaskItem { Name = "Clean the bathroom", Priority = Priority.Low };
var task2 = new TaskItem { Name = "Do the dishes", Priority = Priority.High };
var task3 = new TaskItem { Name = "Walk the dog", Priority = Priority.Medium };
todolist.MyList.Add(task1);
todolist.MyList.Add(task2);
todolist.MyList.Add(task3);

// act
var result = todolist.TasksSortedByPriority;

// assert
Assert.IsTrue(result.Count == 3);
Assert.That(result[0].Priority, Is.EqualTo(todolist.MyList[1].Priority));
Assert.That(result[1].Priority, Is.EqualTo(todolist.MyList[2].Priority));
Assert.That(result[2].Priority, Is.EqualTo(todolist.MyList[0].Priority));
}
}
}
}
2 changes: 2 additions & 0 deletions tdd-todo-list.CSharp.Test/ExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ public ExtensionTests()
{
_extension = new TodoListExtension();
}


}
}
1 change: 1 addition & 0 deletions tdd-todo-list.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{663B0373-6031-46F8-ADD5-9AF01A5E82D5}"
ProjectSection(SolutionItems) = preProject
.github\workflows\core-criteria.yml = .github\workflows\core-criteria.yml
domain-model.md = domain-model.md
.github\workflows\extension-criteria.yml = .github\workflows\extension-criteria.yml
README.md = README.md
EndProjectSection
Expand Down
Loading