Skip to content
Merged
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
2 changes: 1 addition & 1 deletion samples/book-app-project-cs/Services/BookCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public Book AddBook(string title, string author, int year)
return book;
}

public List<Book> ListBooks() => _books;
public List<Book> ListBooks() => _books.ToList();

public Book? FindBookByTitle(string title)
{
Expand Down
10 changes: 10 additions & 0 deletions samples/book-app-project-cs/Tests/BookCollectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ public void RemoveBook_NonexistentBook_ShouldReturnFalse()
Assert.False(result);
}

[Fact]
public void ListBooks_ShouldReturnCopy_AndPreventExternalMutation()
{
_collection.AddBook("Dune", "Frank Herbert", 1965);
var books = _collection.ListBooks();
books.Clear();

Assert.Single(_collection.Books);
}

// --- FindByAuthor ---

[Fact]
Expand Down