After reading the first 7 chapters of Pro ASP.NET MVC Framework -a very recommended read, i'd say. Throughout my reading, the author -Steve Sanderson, touched on some TDD practices a lot. Now my question is:
Steve used to perform his unit tests against the controllers themselves, an example of the book:
[Test]
public void List_Includes_All_Products_When_Category_IsNull() {
//Arrange:
IProductsRepository repository = MockProductsRepository(
new Product { Name = "First Product", Category= "Cat11"},
new Product { Name = "SecondProduct", Category = "Cat22" }
);
ProductsController controller = new ProductsController(repository);
controller.PageSize = 10;
//Act:
var result = controller.List(null, 1);
//Assert:
Assert.IsNotNull(result, "Didn't render view!");
var model = controller.ViewData.Model as IList<Product>;
Assert.AreEqual(2, model.Count, "Got wrong number of products!");
Assert.AreEqual(model[0].Name, "First Product", "Not the expected first item.");
Assert.AreEqual(model[1].Name, "SecondProduct", "Not the expected second item.");
}
I understand why Steve is testing this, obviously he needs to check his logic against the ViewData flags he set, that's why he needs to call the List controller action, my question is, Is that enough? I mean, shouldn't one test his Model objects first? Steve is using LINQ2SQL as his ORM tool, and he pretty much isn't using anything outside LINQ functionality, I mean the example only selects data, and updates by calling the LINQ built in methods; no business validation. On my real app, there is a lot of business validations that should be made, is it going to be enough (or rather easier) for me to start testing on the controller level, ignoring my Model classes (because I don't think it's a good idea)?
Waiting for your ideas Gus!