Logo

Maarten Balliauw {blog}

ASP.NET, ASP.NET MVC, Azure, PHP, OpenXML, VSTS, ...

About the author

Maarten Balliauw is an MVP ASP.NET and is currently employed as .NET Software Engineer at RealDolmen. His interests are mainly web applications developed in ASP.NET (C#) or PHP.
More about me More about me
Send mail E-mail me


Microsoft Most Valuable Professional - MVP - ASP.NET

Subscribe to my RSS feed Follow me on Twitter! View Maarten Balliauw's profile on LinkedIn RealDolmen - Rock-solid passion for ICT
I'm a speaker at TechDays Belgium and TechDays Finland

Search

Latest Twitter

    Follow me on Twitter...

    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

    © Copyright Maarten Balliauw 2010

    ASP.NET MVC TDD using Visual Studio 2010

    Phil Haack announced yesterday that the tooling support for ASP.NET MVC is available for Visual Studio 2010. Troy Goode already blogged about the designer snippets (which are really really cool, just like other parts of the roadmap for ASP.NET MVC 2.0). I’ll give the new TDD workflow introduced in VS2010 a take.

    kick it on DotNetKicks.com

    Creating a new controller, the TDD way

    First of all, I’ll create a new ASP.NET MVC application in VS2010. After installing the project template (and the designer snippets if you are cool), this is easy in VS2010:

    Step 1

    Proceed and make sure to create a unit test project as well.

    Next, in your unit test project, add a new unit test class and name it DemoControllerTests.cs.

    Step 2Go ahead and start typing the following test:

    Step 3Now when you type CTRL-. (or right click the DemoController unknown class), you can pick “Generate other…”:

    Step 4A new window will appear,  where you can select the project where you want the new DemoController class to be created. Make sure to enter the MvcApplication project here (and not your test project).

    Step 5

    Great, that class has been generated. But how about the constructor accepting List<string>? Press CTRL-. and proceed with the suggested action.

    Step 6

    Continue typing your test and let VS2010 also implement the Index() action method.

    Step 7You can now finish the test code:

    Step 8The cool thing is: we did not have to go out of our DemoControllerTests.cs editor while writing this test class, while VS2010 took care of stubbing my DemoController in the background:Step 9Run your tests and see it fail. That’s the TDD approach: first make it fail, and then implement what’s needed:

    Step 10

    If you run your tests  now, you’ll see the test pass.

    Conclusion

    I like this new TDD approach and ASP.NET MVC! It’s not ReSharper yet, but I think its a fine step that the Visual Studio team has taken.

    kick it on DotNetKicks.com


    Categories: ASP.NET | C# | CodePlex | General | ICT | Internet | MVC | VSTS | VS2010

    Comments

    DotNetKicks.com | Reply

    Wednesday, June 10, 2009 9:13 AM

    trackback

    ASP.NET MVC TDD using Visual Studio 2010

    You've been kicked (a good thing) - Trackback from DotNetKicks.com

    Juliën Netherlands | Reply

    Wednesday, June 10, 2009 9:16 AM

    Juliën

    Excellent post again, Maarten!! TDD becomes much more intuïtive with full IDE+Intellisense support. Still the everlasting debate remains: "do you *want* TDD?" Now you can reply with "at least now you *can* easily!".

    Hadi Hariri Spain | Reply

    Wednesday, June 10, 2009 6:38 PM

    Hadi Hariri

    @Julïen,

    VS2010 has a long way to go to make TDD painless.

    Simone Italy | Reply

    Wednesday, June 10, 2009 10:01 AM

    Simone

    OK, now it comes with VS2010... but you can do the exact same things since VS2005 with ReSharper

    Maarten Balliauw Belgium | Reply

    Wednesday, June 10, 2009 10:18 AM

    Maarten Balliauw

    Was my end conclusion too. But still, it's great to see this coming into the IDE itself now.

    Simone Italy | Reply

    Wednesday, June 10, 2009 1:57 PM

    Simone

    Yes, exactly... many people use plain vanilla VisualStudio, without extensions, so cool to see it baked into the it

    Web Development Community | Reply

    Wednesday, June 10, 2009 10:42 AM

    trackback

    ASP.NET MVC TDD using Visual Studio 2010

    You are voted (great) - Trackback from Web Development Community

    progg.ru | Reply

    Wednesday, June 10, 2009 1:05 PM

    trackback

    TDD в ASP.NET MVC с использованием Visual Studio 2010

    Thank you for submitting this cool story - Trackback from progg.ru

    Imran United Kingdom | Reply

    Wednesday, June 10, 2009 2:33 PM

    Imran

    You can't do 'exaclty' the same thing in resharper (4.1) or atleast I havent found a way. The code genreation for classes will place in internal class in the file you are working on instead of allowing you to specify location. Correct me if I am wrong as i would love to havie this feature in 2k5 with r#4.1.

    Hadi Hariri Spain | Reply

    Wednesday, June 10, 2009 7:49 PM

    Hadi Hariri

    You are wrong. It's an option. You can configure it. Also, R# does a hell of a lot more than just creating classes. You can also move the class with one key stroke

    Sanjeev Agarwal | Reply

    Wednesday, June 10, 2009 2:52 PM

    trackback

    Daily tech links for .net and related technologies - June 10, 2009

    Daily tech links for .net and related technologies - June 10, 2009 Web Development Introduction to StructureMap

    Troy Goode United States | Reply

    Wednesday, June 10, 2009 6:37 PM

    Troy Goode

    Much, much better than the previous functionality. I noticed that in the example you gave, DemoController.cs was placed at the root of MvcApplication1, rather than in the Controllers folder. If you typed "Controllers\DemoController.cs" into the "Generate Other" dialog, would it place it in the correct folder and namespace it correctly? (I'll check this when I get home if you don't get around to it first.)

    DotNetShoutout | Reply

    Thursday, June 11, 2009 9:44 AM

    trackback

    ASP.NET MVC TDD using Visual Studio 2010

    Thank you for submitting this cool story - Trackback from DotNetShoutout

    mantya Kyrgyzstan | Reply

    Thursday, June 11, 2009 10:29 AM

    mantya

    Many java editors implemented such things a long before. We were using Resharper for TDD.

    I am sure C# better then Java, an new features are excelent. Hope Microsoft will provide better tools, and for lower price Smile

    Thomas Eyde Norway | Reply

    Thursday, June 11, 2009 12:45 PM

    Thomas Eyde

    My preferred workflow in R#:

    Please note that even this is a long list, the only mechanical steps are writing code in the testfile, and one final cut and paste. The rest is handled automatically via painless shortcuts.

    - write my test.
    - let R# create my class + constructor. Finish constructor (R# works this way).
    - let R# create my method. Finish method with something that is clearly wrong. First test run should fail.
    - fix any remaining compilation errors.
    - run test.
    - pass test.
    - move class to new file (R# shortcut).
    - find class in solution explorer (R# shortcut).
    - cut and paste class file to where it's supposed to be.
    - fix namespace (R# shortcut).

    blog.cwa.me.uk | Reply

    Friday, June 12, 2009 11:33 AM

    pingback

    Pingback from blog.cwa.me.uk

    Reflective Perspective - Chris Alcock  » The Morning Brew #367

    vincenthomedev.wordpress.com | Reply

    Saturday, June 13, 2009 3:21 PM

    pingback

    Pingback from vincenthomedev.wordpress.com

    ASP.NET MVC Installer For Visual Studio 2010 Beta 1 Released « vincenthome’s Tech Clips

    Add comment




      Country flag

    biuquote
    • Comment
    • Preview
    Loading