I was wondering the best practice for unit-testing controller actions that utilize model binding.
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult AddProduct(Product product)
{
}
I was wondering how you invoke the controller's method for unit testing. If you try something like this...
public void Catalog_AddProduct()
{
CatalogController controller = new CatalogController();
// some mocking for controller context, setting form values etc...
controller.AddProduct(// ?);
}
Some might suggest removing Product as a parameter but, I also have another AddProduct controller action that is used for just HTTP-Gets. The only solution I could think of is maybe accepting a namevalue collection (form data) and just using UpdateModel/TryUpdateModel.
I also want to test the model binding itself is working properly so I'd like to put the responsibility of creating the new product to the model binder.