In C#, How do I go about mocking a list of objects?
I am attempting an exercise and it specifies that in the arrange section of my unit test that I need to "mock a List of Book
objects".
What is the syntax for creating a mock list of Book objects? I have tried creating mock Book objects and adding them to a list of books but this didn't work.
public void Test_GetAllBooks_ReturnsListOfBooksItReceivesFromReadAllMethodOfReadItemCommand_WhenCalled()
{
//Arrange
Mock<ReadItemCommand> mockReadItemCommand = new Mock<ReadItemCommand>();
Catalogue catalogue = new Catalogue(mockReadItemCommand.Object);
Mock<Book> mockBook1 = new Mock<Book>();
Mock<Book> mockBook2 = new Mock<Book>();
List<Book> mockBookList = new List<Book>();
mockBookList.Add(mockBook1);
mockBookList.Add(mockBook2);
mockReadItemCommand.Setup(r => r.ReadAll()).Returns(mockBookList);
//Act
List<Book> actual = catalogue.GetAllBooks();
//Assert
Assert.AreSame(mockBookList, actual);
}
This is giving me 2 compilation errors, both CS1503, on the two lines where I have tried to add the mock books to my list of type Book.