Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I quickly create a class in the right place when following TDD using Visual Studio/ReSharper?

Suppose I'm following TDD and using VS/ReSharper. I start out writing a test like this:

[TestFixture]
class FooFixture
{
    [Test]
    public void ShouldDoSomething()
    {
        var foo = new Foo();
    } 
}

At this point, Foo doesn't exist. ReSharper suggests the option of creating the class, but it puts it right next to my test class in my test project, not in my real project. So I have it create the class, then move it to a new file, then move the file to the right place, and finally fix the namespace. This seems like a lot of work.

Is there a more efficient way to quickly create the Foo class and put it in the right place? It seems like the 'right place' could be guessed from the namespace of my test project.

like image 798
Paul Stovell Avatar asked Oct 09 '22 05:10

Paul Stovell


1 Answers

Move types into matching class refactoring is used for this purpose.

You're expected to generate a number of business logic types in the current test class and then move them to matching files/namespaces in one go.

Note that this refactoring is available in the text editor and on Solution Explorer nodes, meaning that you can batch-apply it to a heck lot of files.

like image 171
Jura Gorohovsky Avatar answered Oct 12 '22 09:10

Jura Gorohovsky