Creating the First Test
Back to our test controller. Now, we need to test whether the index page returns all the products or not. Let's create a new Test Method.
[TestMethod]
public void Index_Returns_All_Products_In_DB()
{
// Arrange
// Act
// Assert
}
The idea is we want to create a mock of repository. Then, when we call GetAll() method, it should return two books.
// creating a mock of repository
var productRepository = Mock.Create<Repository>();
// creating a 'should return' result
Mock.Arrange(() => productRepository.GetAll()).
Returns(new List<Product>()
{
new Product { Genre = "Fiction", Id = 1, Name = "Hunger Games", Price = 200000},
new Product { Genre = "Fiction", Id = 2, Name = "Hunger Games 2", Price = 300000}
}).MustBeCalled();