Before you make any changes, you must have automatic unit tests. In fact, you should not make changes to code that does not extend to unit tests of at least 80%.
In the real world, unit tests often do not exist. On the other hand, performing any refactoring without unit tests can completely ruin your code, which makes Management even less likely that you will make changes in the future. What to do?
Using a tool like ReSharper, you can start by using some “safer” refactoring. With caution, there is no reason why you won’t be able to repeatedly use the “Extract Method” to move your ADO.NET code into separate methods: “Make the Static Method” if it was not static yet, either “Move the Method” or “Make non-static method "to move the method to a separate class.
Once you exit the code, you can start writing automated tests. At this stage, they do not need to be “unit tests” in the strict sense of the word. In particular, these tests must be allowed to work with the database.
When you are left with only code that cannot be easily tested, you can very carefully begin to make this code more testable. You can do things like sets of sets of static methods into instance methods of new classes. You can also start injecting dependency injection to simplify testing using mock objects. But be very careful here - you are modifying code that does not have automated tests, and you will use refactoring that can really break stuff.
After you have done an adequate code test, you can reorganize the code to better understand it and then change it to use LINQ if you want.
John saunders
source share