Currently I'm reading a book (Pro ASP.Net Framework).
In this book, the author suggests to use a Moq framework to help to do TDD.
[Test]
public void List_Presents_Correct_Page_Of_Products()
{
IProductsRepository repository = MockProductsRepository(
new Product { Name = "P1" }, new Product { Name = "P2" },
new Product { Name = "P3" }, new Product { Name = "P4" },
new Product { Name = "P5" }
);
ProductsController controller = new ProductsController(repository);
...
}
static IProductsRepository MockProductsRepository(params Product[] prods)
{
// Generate an implementor of IProductsRepository at runtime using Moq
var mockProductsRepos = new Moq.Mock<IProductsRepository>();
mockProductsRepos.Setup(x => x.Products).Returns(prods.AsQueryable());
return mockProductsRepos.Object;
}
In the model layer, we've define a FakeRepository, and a SqlRepository.
The fact is I don't see the advantage of using this moq framework. Why don't we only use our FakeRepository ? Or clear our FakeRepository and add fake product on it ?
At first, I thought that the moq framework was there to generate fake data so you don't have to if you have for example 100 fake objects to generate.
What I miss ?