Are there any good resources for refactoring existing C# code to use LINQ while keeping your tests passing?

Posted by Paddyslacker on Programmers See other posts from Programmers or by Paddyslacker
Published on 2011-06-29T22:16:57Z Indexed on 2011/06/30 0:29 UTC
Read the original article Hit count: 198

Filed under:
|
|
|

I've been teaching myself a little LINQ and an exercise I thought would be useful was to take my existing Project Euler C# code, which I built using Test Driven Development and gradually convert it to LINQ. I realise that LINQ is not always the best solution for all of the Project Euler problems, but I don't want to get into that here.

I'm wondering whether or not it's feasible to refactor "traditional" OO C# code to use LINQ and functional programming syntax whilst keeping all of your tests passing. I can't find a way to make the tiny steps I'm used to making using TDD when converting to LINQ and this is a roadblock for me. I seem to have to make large changes to come up with a single function that I then replace whole chunks of my code with.

I realise I could write this from scratch in LINQ, but in the real world, I'd like to be able to replace parts of my existing C# code to take advantage of LINQ where appropriate.

Has anyone been successful with this approach? What resources did you find useful for refactoring existing C# code to use LINQ whilst taking a Test Driven Development approach?

© Programmers or respective owner

Related posts about c#

Related posts about TDD