Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm working on a large application written in asp.net web forms. It was developed under asp.net 1.0, and still uses DataGrid, though portions have been updated.

Most of the code resides in either the codebehind, or in controller classes that can't be instantiated outside of a running IIS. (The controller framework we use provides lifetime management tied to session state.) Data access is through a custom DAL, meaning that most of that code also requires a live database with proper data inside it.

I want to decouple the code from the database and the web server, so that I can run it under a test harness. Are there any good strategies for moving from this sort of code to a more testable structure?

share|improve this question
5  
Good luck. Seems like a major rewrite. Try to move as much logic as possible into a domain model and call the newly created model then from the controllers. Also create an interface for the DAL and make an adapter to use the current DAL with it. –  Falcon Aug 2 '11 at 14:51
add comment

1 Answer

The best way would be to refactor out the code-behind to logical layers (services, DAO/Repository, etc). Look at Model View Presenter for ideas how to abstract away the rest, but realistically an endeavor like this is usually better served by rewriting the thing properly; speaking from experience it's very hard to refactor WebForms when it's done terribly, chances are you will have to redo so much that you're basically rewriting the thing anyways.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.