ASP.NET MVC Tip #27 – Create ASP.NET MVC Specific Visual Studio Add-Ins

In this tip, I discuss Eric Hexter’s TDD Class Generator Add-In for Visual Studio. This Add-In enables you to generate a class, an interface, and a test class by entering a single keyboard shortcut.

Eric Hexter — who has done valuable work on the MvcContrib project — visited Microsoft last week and showed me one of his current projects. He has started a project for building ASP.NET MVC specific Add-Ins for Visual Studio. In particular, he has created an Add-In for generating testable classes automatically.

You can learn more about the project, and download the binaries and source code, from the following website:

http://erichexter.googlecode.com/svn/trunk/TestFirstGenerator/

You also can view a quick video walk-through of the Add-In at:

http://erichexter.googlecode.com/svn/trunk/TestFirstGenerator/docs/ScreenCast.htm

Download the LatestVersion.zip file and unzip the archive. After unzipping the archive, make sure that you right-click the file, select Properties, and click the Unblock button (see Figure 1). If you forget to unblock the archive, then you’ll encounter security issues when attempting to use the Add-In.

Figure 1 – Unblocking the Archive

image

After you unzip the Add-In, you must install the Add-In in Visual Studio. The download includes an Install.cmd batch file for installing the Add-In. Unfortunately, however, the installer did not work on my machine because of path issues. Therefore, I followed these steps to install the Add-In:

1. Create a new folder named AddIns in your Documents\Visual Studio 2008 folder.

2. Copy all of the unzipped files from the download into the new AddIns folder

3. After launching Visual Studio, select the menu option Tools, Add-In Manager and enable the TDD Class Generator Add-In (see Figure 2).

Figure 2 – Enabling the TDD Class Generator Add-In

image

Admittedly, the project is very much in the infant stage. Don’t expect a fancy interface.

Before you can use the TDD Class Generator, you first must create a new C# ASP.NET MVC Web Application. Make sure that you create a test project. Also, you need to add references to both NUnit and Rhino Mocks to your test project.

After you create a new project, you use the TDD Class Generator Add-In by selecting the menu option Tools, Generate Class Under Test. Alternatively, you can just entry the keyboard combination Ctrl-Alt-Enter. Either method of launching the Add-In displays the dialog in Figure 4.

Figure 3 – Using the TDD Class Generator

image

Figure 4 – TDD Class Generator Dialog

image

Select the name of your application project and the name of your test project from the dropdown lists. If you complete the dialog by entering the value Models for Folder location and Movie for Class name and click the Generate button (well, the Generat button on my machine) then the following files are generated in the application project automatically:

\Models\Impl\Movie.cs

\Models\IMovie.cs

And, the following file is generated in the test project automatically:

\Models\MovieTester.cs

The goal of the tool is to set you on the right path. It doesn’t just create a Movie class. Instead, it creates a Movie class that implements an interface. It also assumes that you will need to mock the class. Therefore, the TDD Class Generator adds the mocking logic to the MovieTester.cs class automatically.

I think Eric Hexter’s approach is a great approach for making it easier to build ASP.NET MVC applications. Right now, there is a lot of repetitive file creation tasks involved when getting a new ASP.NET MVC application off the ground (Especially if you want to do things the right way). By building a library of ASP.NET MVC specific Add-Ins, you can eliminate these brainless, tedious tasks.

Discussion

  1. http:// says:

    Where do I find the specific references for both NUnit and Rhino Mocks to my test project?
    Thanks

  2. http:// says:

    Error 1 The type or namespace name ‘IDependency’ could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Dale Stewart\My Documents\Visual Studio 2008\Projects\MvcApplication6\MvcApplication6\Models\MoviesTester.cs 16 13 MvcApplication6

  3. http:// says:

    @geek50 – You need to download both NUnit and Rhino Mocks. Get NUnit at NUnit.org and Rhino Mocks at http://www.ayende.com/projects/rhino-mocks.aspx. After you download, you’ll need to add references to the DLLs to your test project.

  4. http:// says:

    Error 1 The type or namespace name ‘IDependency’ could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Dale Stewart\My Documents\Visual Studio 2008\Projects\MvcApplication6\MvcApplication6\Models\MoviesTester.cs 17 13 MvcApplication6

  5. Eric Hexter says:

    The project utilizes VS item templates, which are zip files with .cs files inside. You can modify those to meet your exact need and preference of the specific template. The IDependency does not exist and I utilize the Resharper Ad-in to make additional dependencies. I will monitor this post for more comments and respond.

    for more information see my blog at http://hex.lostechies.com/

  6. http:// says:

    Stephen, your Tips give me much better understanding of ASP.NET MVC capabilities, thank you.

    However I am still curious about one thing (outside current topic, sorry): how much ASP.NET MVC depends on RESTful routes? Or in other words: can I use ASP.NET MVC with old good “~/MyDirectory/Default.aspx?id=333″ mapped directly to file system? It might be useful for step-by-step migration from WebForms.

    I’d really appreciate your explanations or ideas on that.

  7. http:// says:

    Very Good Work
    Thanks

  8. Vijay says:

    Hi !
    i have downloaded the “LatestVersion.zip” and right click on it and select the properties but the “unblock” button is not in display ! what to do further ??

  9. MOV to DVD says:

    i have to go back to school to understand this….i hope i still have a time for that. TQ

  10. i really like the info at this post thanks!!!

  11. Quitting Smoking Side Effects
    Are you interested in getting rid of smoking side effects? In this article you will find some fascinating tips. It is often seen that some people start smoking to get relieved from the stress. They start using it for several occasions and soon they get trapped into its addiction

  12. I really love to go across these blogs because they are very helpful and gets easier to handle all type of issues with your projects. Thanks Stephen!

  13. I REALLY LIKE THE COMENTS VERY NICE POST

  14. wow.. great post

    i really like it thanks!

  15. great post Stephen Walther ! Your are the best !

  16. Hi I need to download both NUnit and Rhino Mocks. Help please.

  17. Infections says:

    Hi served me well through the information, thanks

  18. Flu says:

    Hi
    thanks for the tips have helped me a lot.

  19. Hello
    cool this blog is great very good my friend keep it go

  20. Hi
    I really appreciate this info, please keep me inform
    very interesting website, congratulations.

  21. Hello
    I really appreciate this info, please keep me inform.

  22. Hello
    I would be visiting this blog regularly. Thanks for sharing good information.

  23. f3w43 It looks like DataContextExtensions.cs line 45 of the Save method should pass the primaryKeyName through to Update.

  24. hey buddy! your doing some great stuff! keep it going!

  25. Can you explain me which could be the effects for an adult to buy Viagra Online and have heart problems?

  26. klip izle says:

    Where do I find the specific references for both NUnit and Rhino Mocks to my test project?
    Thanks

  27. HD Video Converter says:

    As the users of HD Camcorders like Sony, Canon, Panasonic, this HD Video Converter is necessary to help us convert hd Video easily and quickly. The Converter for HD provides several practical editing functions to help you achieve ideal output effect. Trim function is to cut videos into clips which you can just convert and transfer to your player. Crop function helps you remove black bars around the movie. You could use Effect function to adjust video brightness, contrast, saturation and more parameters. More powerful and considerate functions are waiting for you to explore.

    Mac Video Converter l Rip Blu Ray l VOB Converter