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
15 changes: 15 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
| Classes | Methods | Scenario | Output |
|---------|-------------------|----------------------------------------------|------------------------|
|TodoList | AddTask | I want to add tasks to my todo list | task added |
| | ShowTasks | I want to see all the tasks in my todo list | List<Tasks> |
| | ToggleStatus | I want to change the status of a task | String output |
| | GetComplet | I want to be able to get only the complete |
| | GetIncomplet | I want to be able to get only the inccomplete|
| | FindTask | I want to search for a task and receive a |
| | | message that says it wasn't found if |
| | | it doesn't exist. |
| | RemoveTask | I want to remove tasks from my list. |
| | TaskAscending | I want to see all the tasks in my list |
| | | ordered alphabetically in ascending order |
| | TaskDescending | I want to see all the tasks in my list |
| | | ordered alphabetically in descending order. |
14 changes: 14 additions & 0 deletions tdd-todo-list.CSharp.Main/Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,19 @@ namespace tdd_todo_list.CSharp.Main
{
public class TodoListExtension
{
private List<Task> tasks = new List<Task>();
private int nextId = 1;

public void AddTask(string name)
{
tasks.Add(new Task(nextId++, name));
}

public string FindTaskByID(int id)
{
var task = tasks.Find(x => x.Id == id);

return task == null ? $"no task with id: {id}" : $"{task.Name} - {task.IsComplete}";
}
}
}
25 changes: 23 additions & 2 deletions tdd-todo-list.CSharp.Main/Program.cs
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
using NUnit.Framework.Interfaces;
using System;
using tdd_todo_list.CSharp.Main;


TodoList toDoList = new TodoList();

TodoListExtension extension = new TodoListExtension();

toDoList.AddTask("Buy food");
toDoList.AddTask("exercise");
toDoList.AddTask("auy food");
toDoList.AddTask("cxercise");

extension.AddTask("check");

var allTasks = toDoList.ShowTasks();
Console.WriteLine(string.Join("\n", allTasks));

var idTasks = extension.FindTaskByID(1);
Console.WriteLine(string.Join("\n", idTasks));


121 changes: 121 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,128 @@

namespace tdd_todo_list.CSharp.Main
{
public class Task
{
public int Id { get; set; }
public string Name { get; set; }
public bool IsComplete { get; set; }

public Task(int id, string name)
{
Id = id;
Name = name;
IsComplete = false;
}

public void ToggleStatus()
{
IsComplete = !IsComplete;
}
}
public class TodoList
{
private List<Task> tasks = new List<Task>();
private int nextId = 1;

public void AddTask(string name)
{
tasks.Add(new Task(nextId++, name));
}

public List<string> ShowTasks()
{
if (tasks.Count == 0)
{
return new List<string> { "no tasks" };
}

return tasks.Select(task => $"{task.Id}. {task.Name} - {task.IsComplete}").ToList();
}

public string FindTask(string name)
{
var task = tasks.FirstOrDefault(task => task.Name == name);

return task == null ? $"no task named: {name}" : $"{task.Name} - {task.IsComplete}";
}

public string RemoveTask(string name)
{
var taskToRemove = tasks.FirstOrDefault(task => task.Name == name);

if (taskToRemove != null)
{
tasks.Remove(taskToRemove);
return $"removed {name}";
}
else
{
return $"could not find: '{name}'";
}
}

public bool ToggleStatus(string name)
{
var taskToChange = tasks.FirstOrDefault(task => task.Name == name);

if (taskToChange != null)
{
taskToChange.ToggleStatus();
return true;
}
return false;
}

public List<string> ShowComplete()
{
if (tasks.Count == 0)
{
return new List<string> { "no tasks" };
}

return tasks
.Where(task => task.IsComplete)
.Select(task => $"{task.Id}. {task.Name} - {task.IsComplete}")
.ToList();
}

public List<string> ShowInComplete()
{
if (tasks.Count == 0)
{
return new List<string> { "no tasks" };
}

return tasks
.Where(task => !task.IsComplete)
.Select(task => $"{task.Id}. {task.Name} - {task.IsComplete}")
.ToList();
}

public List<string> ShowAscending()
{
if (tasks.Count == 0)
{
return new List<string> { "no tasks" };
}

return tasks
.OrderBy(t => t.Name)
.Select(task => $"{task.Name}, {task.IsComplete}")
.ToList();
}

public List<string> ShowDescending()
{
if (tasks.Count == 0)
{
return new List<string> { "no tasks" };
}

return tasks
.OrderByDescending(t => t.Name)
.Select(task => $"{task.Name}, {task.IsComplete}")
.ToList();
}
}
}
113 changes: 111 additions & 2 deletions tdd-todo-list.CSharp.Test/CoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,121 @@ namespace tdd_todo_list.CSharp.Test
[TestFixture]
public class CoreTests
{

[Test]
public void FirstTest()
{
TodoList core = new TodoList();
Assert.Pass();
}

[Test]
public void AddTask()
{
TodoList toDoList = new TodoList();

toDoList.AddTask("Buy groceries");
var tasks = toDoList.ShowTasks();

var expected = new List<string> { "1. Buy groceries - False" };
CollectionAssert.AreEqual(expected, tasks);
}

[Test]
public void FindTask()
{
TodoList toDoList = new TodoList();
toDoList.AddTask("Buy groceries");
toDoList.AddTask("Call");

var taskFound = toDoList.FindTask("Buy groceries");
var taskNotFound = toDoList.FindTask("Non-existent task");

Assert.AreEqual("Buy groceries - False", taskFound);
Assert.AreEqual("no task named: Non-existent task", taskNotFound);
}

[Test]
public void RemoveTask()
{
TodoList toDoList = new TodoList();
toDoList.AddTask("Buy groceries");

var removeSuccess = toDoList.RemoveTask("Buy groceries");
var removeFailure = toDoList.RemoveTask("tasks");
var tasksAfterRemoval = toDoList.ShowTasks();

Assert.AreEqual("removed Buy groceries", removeSuccess);
Assert.AreEqual("could not find: 'tasks'", removeFailure);
CollectionAssert.AreEqual(new List<string> { "no tasks" }, tasksAfterRemoval);
}

[Test]
public void ToggleStatus()
{
TodoList toDoList = new TodoList();
toDoList.AddTask("Buy groceries");

var toggleSuccess = toDoList.ToggleStatus("Buy groceries");
var taskStatusAfterToggle = toDoList.FindTask("Buy groceries");
var toggleFailure = toDoList.ToggleStatus("Non-existent task");

Assert.IsTrue(toggleSuccess);
Assert.AreEqual("Buy groceries - True", taskStatusAfterToggle);
Assert.IsFalse(toggleFailure);
}

[Test]
public void ShowComplete()
{
TodoList toDoList = new TodoList();
toDoList.AddTask("Buy groceries");
toDoList.AddTask("run");
toDoList.ToggleStatus("run");

var completeTasks = toDoList.ShowComplete();

var expected = new List<string> { "2. run - True" };
CollectionAssert.AreEqual(expected, completeTasks);
}

[Test]
public void ShowInComplete()
{
TodoList toDoList = new TodoList();
toDoList.AddTask("Buy groceries");
toDoList.AddTask("run");
toDoList.ToggleStatus("run");

var incompleteTasks = toDoList.ShowInComplete();

var expected = new List<string> { "1. Buy groceries - False" };
CollectionAssert.AreEqual(expected, incompleteTasks);
}

[Test]
public void ShowAscending()
{
TodoList toDoList = new TodoList();
toDoList.AddTask("Buy groceries");
toDoList.AddTask("run");

var ascendingTasks = toDoList.ShowAscending();

var expected = new List<string> { "Buy groceries, False", "run, False" };
CollectionAssert.AreEqual(expected, ascendingTasks);
}

[Test]
public void ShowDescending()
{
TodoList toDoList = new TodoList();
toDoList.AddTask("Buy groceries");
toDoList.AddTask("run");

var descendingTasks = toDoList.ShowDescending();

var expected = new List<string> { "run, False", "Buy groceries, False" };
CollectionAssert.AreEqual(expected, descendingTasks);
}
}
}
}
28 changes: 28 additions & 0 deletions tdd-todo-list.CSharp.Test/ExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,43 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;

namespace tdd_todo_list.CSharp.Test
{
[TestFixture]
public class ExtensionTests
{
private TodoListExtension _extension;
public ExtensionTests()
{
_extension = new TodoListExtension();
}
[Test]
public void FindByID()
{
TodoListExtension toDoList = new TodoListExtension();
toDoList.AddTask("Buy groceries");

var taskFound = toDoList.FindTaskByID(1);
var taskNotFound = toDoList.FindTaskByID(100);

Assert.AreEqual("Buy groceries - False", taskFound);
Assert.AreEqual("no task with id: 100", taskNotFound);
}
[Test]
public void UpdateName()
{
TodoListExtension toDoList = new TodoListExtension();
toDoList.AddTask("Buy groceries");

var taskupdated = toDoList.UpdateName();

Check failure on line 37 in tdd-todo-list.CSharp.Test/ExtensionTests.cs

View workflow job for this annotation

GitHub Actions / build

'TodoListExtension' does not contain a definition for 'UpdateName' and no accessible extension method 'UpdateName' accepting a first argument of type 'TodoListExtension' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 37 in tdd-todo-list.CSharp.Test/ExtensionTests.cs

View workflow job for this annotation

GitHub Actions / build

'TodoListExtension' does not contain a definition for 'UpdateName' and no accessible extension method 'UpdateName' accepting a first argument of type 'TodoListExtension' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 37 in tdd-todo-list.CSharp.Test/ExtensionTests.cs

View workflow job for this annotation

GitHub Actions / build

'TodoListExtension' does not contain a definition for 'UpdateName' and no accessible extension method 'UpdateName' accepting a first argument of type 'TodoListExtension' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 37 in tdd-todo-list.CSharp.Test/ExtensionTests.cs

View workflow job for this annotation

GitHub Actions / build

'TodoListExtension' does not contain a definition for 'UpdateName' and no accessible extension method 'UpdateName' accepting a first argument of type 'TodoListExtension' could be found (are you missing a using directive or an assembly reference?)
var taskNotFound = toDoList.FindTaskByID(100);

Assert.AreEqual("Buy update - False", taskupdated);
Assert.AreEqual("no task with id: 100", taskNotFound);
}


}
}
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