Using TDD with MVC Controller actions and ActionFilterAttribute
I am deve开发者_如何学JAVAloping using TDD and ASP.Net MVC.
I have a custom ActionFilterAttribute which needs to be applied to certain controller actions and was wondering the best approach to this using TDD.
- Currently the attribute itself has a set of unit tests.
- I develop the controller action with tests as per normal but ignore the case handled by the attribute.
- I add a unit test that uses relfection to ensure the attribute is applied (with correct parameters) to the action.
If this a suitable way to go about it?
It sounds like it is.
What confuses You? Test that tests if attribute is applied? There is nothing bad with that. Testing actual constructions of code is very useful technique. You can force various conventions too with this approach like naming of classes in particular namespace, existence of public constructors w/o arguments, etc.
精彩评论