Subscribe to this Blog

Subscribe to this Blog

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

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

clip_image002

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

clip_image004

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

clip_image006

Figure 4 – TDD Class Generator Dialog

clip_image008

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.

Published Thursday, July 31, 2008 10:04 AM by swalther
Filed under: , , ,

Comments

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

Thursday, July 31, 2008 4:06 PM by geek50

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

Thanks

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

Thursday, July 31, 2008 4:22 PM by geek50

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

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

Thursday, July 31, 2008 4:39 PM by swalther

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

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

Thursday, July 31, 2008 5:57 PM by geek50

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

# Create ASP.nET MVC Specific Visual Studio Add-Ins

Thursday, July 31, 2008 6:38 PM by 拝啓、サカモトと申します。

Create ASP.nET MVC Specific Visual Studio Add-Ins

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

Thursday, July 31, 2008 8:09 PM by Eric Hexter

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/

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

Friday, August 01, 2008 12:20 PM by ILog

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.

# » ASP.NET MVC Tip #27 ??? Create ASP.NET MVC Specific Visual Studio …

Pingback from  » ASP.NET MVC Tip #27 ??? Create ASP.NET MVC Specific Visual Studio …

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

Wednesday, August 20, 2008 12:07 PM by Nabil

Very Good Work

Thanks

Leave a Comment

(required) 
(required) 
(optional)
(required)