For such a small code base, the changes required by the new tests caused a fairly significant change. First, we added an IsComplete property to the Todo model:
internal class Todo
{
public bool IsComplete { get; set; }
public string Description { get; set; }
internal void Validate()
{
Description = Description ?? throw new DescriptionRequiredException();
}
}
The rest of the changes affect the TodoList class. A boolean property was added to toggle the visibility of completed items, the Complete method was modified to only mark the item as complete, and a where clause was added to the items retrieved from the list:
internal class TodoList
{
private readonly List<Todo> _items = new List<Todo>();
public IEnumerable<Todo> Items => _items.Where(t => !t.IsComplete || ShowCompleted);
public bool ShowCompleted { get; set; }
public void AddTodo(Todo item)
{
item = item ?? throw new ArgumentNullException();
item.Validate();
_items.Add(item);
}
public void Complete(Todo item)
{
item.IsComplete = true;
}
}