I just started working on a new project. As you know, I got agile religion earlier this month, and I am a born-again coder, who wants to test his code as he goes. Also, after doing a few TDD projects, not doing it seems wrong, and it is just not as fun.
So I got a new .Net project, and this time I actually can do it right. I am going to do it right. I set up Moq and NUnit, and off I go to test land. Now All what I have to figure out is how to mock HttpRequest to test an upload method. I research the question. And in most cases, most of the solutions involved Asp.net mvc. I kept trying to find something specific to just plain asp.net, but the information that I got was either very old, or was a tangential mention that in an mvc page about how the solution could also work with regular asp.net pages.
So the pragmatic solution was to move the back end of the project to mvc. Fortunately for me the project only has a couple of pages of code, and translating the behavior from asp.net to mvc was quick. In fact, it seems that it takes a lot less work code to do the same work.
I am not saying that it is not possible to TDD regular asp.net. I am sure it is. But most of the information and resources exist for asp.net mvc, so, if it is possible, it makes a lot more sense to adopt it if one wants to TDD a asp.net project.
Comments
Actually, MVC makes it easier
Actually, MVC makes it easier to follow good programming practices, while WebForms makes it easy to create 'Balls of Mud'.
I am finding that using the patterns used in MVC (S.O.L.I.D and Domain Driven Design), in my WebForm applications also is very testable. You can use a MVC or MVP pattern in WebForms. The code-behind just delegates to the controller.
Have the controller create a viewmodel which is stored in a protected field in the codebehind. Now render the page using this viewmodel, similar to the way it is done in MVC (without HtmlHelpers).
Very testable, very TDD.
Thanks, Mathew! Once I get
Thanks, Mathew!
Once I get more experience with MVC, I will probably adapt this technique in other projects. Heck, I may want to just create a simple proof-of-concept project to truly absorb your idea.
Thanks again!