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.

If you liked this blog post then please Subscribe to this blog.
posted on Thursday, July 31, 2008 5:04 PM | Filed Under [ ASP.NET ASP.NET MVC TDD Tips ]

Comments

Gravatar
# re: ASP.NET MVC Tip #27 – Create ASP.NET MVC Specific Visual Studio Add-Ins
Posted by http://
on 7/31/2008 8:06 PM

Where do I find the specific references for both NUnit and Rhino Mocks to my test project?<br />Thanks<br />
Gravatar
# re: ASP.NET MVC Tip #27 – Create ASP.NET MVC Specific Visual Studio Add-Ins
Posted by http://
on 7/31/2008 8:22 PM

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<br />
Gravatar
# re: ASP.NET MVC Tip #27 – Create ASP.NET MVC Specific Visual Studio Add-Ins
Posted by http://
on 7/31/2008 8:39 PM

@geek50 - You need to download both NUnit and Rhino Mocks. Get NUnit at NUnit.org and Rhino Mocks at <a rel="nofollow external" href="http://www.ayende.com/projects/rhino-mocks.aspx" title="http://www.ayende.com/projects/rhino-mocks.aspx">http://www.ayende.com/projects/rhino-mocks.aspx</a>. After you download, you'll need to add references to the DLLs to your test project.<br /><br />
Gravatar
# re: ASP.NET MVC Tip #27 – Create ASP.NET MVC Specific Visual Studio Add-Ins
Posted by http://
on 7/31/2008 9:57 PM

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<br />
Gravatar
# re: ASP.NET MVC Tip #27 – Create ASP.NET MVC Specific Visual Studio Add-Ins
Posted by Eric Hexter
on 8/1/2008 12:09 AM

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.<br /><br />for more information see my blog at <a rel="nofollow external" href="http://hex.lostechies.com/" title="http://hex.lostechies.com/">http://hex.lostechies.com/</a> <br /><br />
Gravatar
# re: ASP.NET MVC Tip #27 – Create ASP.NET MVC Specific Visual Studio Add-Ins
Posted by http://
on 8/1/2008 4:20 PM

Stephen, your Tips give me much better understanding of ASP.NET MVC capabilities, thank you.<br /><br />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.<br /><br />I'd really appreciate your explanations or ideas on that.<br />
Gravatar
# re: ASP.NET MVC Tip #27 – Create ASP.NET MVC Specific Visual Studio Add-Ins
Posted by http://
on 8/20/2008 4:07 PM

Very Good Work<br />Thanks
Gravatar
# re: ASP.NET MVC Tip #27 – Create ASP.NET MVC Specific Visual Studio Add-Ins
Posted by Vijay
on 2/10/2009 10:01 PM

Hi !<br />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 ??
Comments have been closed on this topic.