Monday, April 19, 2010

Setting up a new ASP.NET MVC project NUnit testing template

In this blog, I'm going to outline the steps necessary to setup a skeleton project that can be used by the ASP.NET MVC 2 framework that uses NUnit as the testing framework by default. These steps were originally described for MVC version 1 in the book by Palermo - ASP.NET MVC in Action.

  • Download and install the MVC2 framework from http://www.asp.net/downloads/
  • Download and install the latest NUnit framework from http://www.nunit.org/index.php?p=download
  • Download and uncompress the Rhino Mock framework from http://www.ayende.com/projects/rhino-mocks.aspx
  • Download and uncompress the Windsor 2.1 framework from http://www.castleproject.org/castle/download.html
  • Open Visual Studio and create a new ASP.NET MVC 2 Web Application Project within Visual Studio 2008 (change the names to suit your template, location does not matter since we'll be exporting as a template)
  • Change the name of the Test project to suit your needs and make sure that the Visual Studio Unit Test test framework is selected.
  • In the Test project remove the reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework and add references to the project for the following dlls and verify that all of their properties are set to Copy Local (make sure to either add these to the GAC or a semi-permanent location or network share or you will end up breaking the template if that directory changes). I also, decided that in order to be able to immediately compile when a new project is created with this template, I removed the reference to the base project from the test project and removed all code that referenced the VS Unit Testing framework.
    1. Castle.Core
    2. Castle.DynamicProxy2
    3. Castle.MicroKernel
    4. Castle.Windsor
    5. nunit.framework
    6. Rhino.Mocks
  • Save all changes and go to File > Export Template
  • Select the Project template option and verify that the MvcApplication.NUnitTests is selected as the project from which to create a template
  • Click Next
  • Change the template name to MvcApplication.NUnitTests.cs
  • Change the template description to something meaningful, such as - ASP.NET MVC Web Application NUnit project template
  • Keep both the Automatically import the template into Visual Studio as well as the Display an explorer window on the output files folder options selected - the end result should be a single zip file that will be displayed when in explorer when we're finished.
  • Click Finish and Windows Explorer popups up with the output zip file (it should default to \Visual Studio 2008\My Exported Templates). Copy this file to C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplates\CSharp\Test (assuming you're running the 64-bit version of Windows 7, adjust this path according to your environment)
  • Close all open instances of Visual Studio
  • Open the Visual Studio 2008 Command Prompt (as Administrator) and run the following command to install the template (the command prompt can be found under Start > All Programs > Microsoft Visual Studio 2008 > Visual Studio Tools > Visual Studio 2008 Command Prompt) - Note: this may take a couple of minutes depending on your computer and templates available
    • devenv /installvstemplates
  • Close the command prompt
  • Create a new file with the following contents (editing the paths to match your environment)
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\9.0\MVC2\TestProjectTemplates\NUnit]
"Template"="MvcApplication.NUnitTests.cs.zip"
"Path"="CSharp\\Test"
"TestFrameworkName"="NUnit Test"
"AdditionalInfo"="http://www.nunit.org/index.php?p=home"
"Package"=""
  • Choose a file name (such as - NUnit Test template Example.reg) and save the file to a location that you can navigate to easily
  • Open a normal command prompt (with adminstrative priviledges) and navigate to where you saved the file created in the previous step
  • Run the following - regedit.exe /s "[path to file]\NUnit Test template Example.reg"
  • Open Visual Studio and Create a new MVC project with the new template for NUnit 

Setting up a Remote Desktop Connection from Windows to Mac

This issue has been plaguing me for a while now. I have two computers, two monitors, two keyboards, two mice and a very cool antique desk that is big enough for one of each (except, of course, for the two monitors which are staying). The Screen Sharing technology utilized by OS X is very slick and I use it between my laptop and desktop all of the time, but how do you remote desktop from a PC to a Mac? I'm a little embarrassed that this didn't occur to me earlier since I already knew that VNC was the underlying technology used by OS X. That being said, I finally came across a mac forum post that reminded me of this fact.

The Problem
I work in Windows, but I have all of my music and other "good" stuff on the Mac, so what to do?

My two options to clear the clutter on my desktop are the following:
  1. Plug both monitors into the Mac and remote desktop to the PC
  2. Plug both monitors into the PC and remote desktop to the Mac
Option one works, and quite well in most circumstances using the Microsoft Remote Desktop Connection Client, but it is plagued by a few oddities in its behavior. The two most annoying of these are that I can't use both monitors for the PC (i.e., can't spread the remote desktop to fill both monitors) and certain things, such as video playback, are really ugly over the remote desktop client.

So option two it is! I've been searching for solutions to this problem for a while now and think I've finally come across one that is acceptable. The following details the procedure I followed that appears to work in my environment. This setup, of course, is dependent upon access limitations of your specific environment - sub-nets, VPNs (virtual private networks), etc.

Download and install UltraVNC (freeware)
    1. http://www.uvnc.com/download/index.html

    2. Select the latest version for download (1.0.8.2 as of this writing)


    3. On the next page I selected the full version to download since I haven't previously installed any version of VNC on this PC - 1.0.8.2 Full


    4. On the final page I selected the 64-bit version of the full download - X64 1.0.8.2 Full

    5. I saved the file to my desktop and then ran it like a normal installer





    6. I clicked through the wizard, accepted the license agreement, etc. The only modification I made from the default values provided for the installation was in what was finally installed. To keep as much processing power as possible, I like minimal services running on my computer and so I only wanted the minimal installation for my setup. As one of the last steps, I was given the option of what to install to which I selected the UltraVNC Viewer Only option.

    7. Click Next three more times and then Install & the installer goes through its process.


    Enabling Mac to Accept Incoming VNC Connection

    First, you must enable remote administration within OS X

    1. Select the Apple menu in the top left of your menu bar. Select System Preferences... on the menu that drops down.


    2. On the Internet & Wireless (third) row of items in the System Preferences dialog that pops up select the folder that is titled Sharing



    3. In the Sharing dialog window, make sure that the Screen Sharing option is selected in the left section of the window.



    4. Tighten security so that it is not open to everyone. First select the "Computer Settings..." button in the upper right area of the dialog box. In the drop down window that appears, check the box that says "VNC viewers may control screen with password" and then enter a password that you will remember.



    5. Limit the users that can access your computer in the bottom right section that starts with the "Allow access for:" label.



    Determining the IP of your Mac

    1. You can discover the current IP assigned to your Mac by again selecting System Preferences from the Apple menu and then selecting Network



    2. Select the connection that is active in the list on the left of the dialog window (in my case it is the AirPort connection).



    3. When this is selected, the content area (the right side of the window) will update with the current state of that connection. Next to the Status label you should see the word Connected and then below that should be listed the current IP assigned to your Mac. This IP address will be used later when connecting from your PC.



    Connecting to your Mac

    You will start up the VNC viewer client as you normally would any other application. I plan to use this on a daily basis, so I placed it as a "pinned" shortcut on my Start menu (you pin any application to the Start menu by right-clicking on the .exe and selecting the Pin to Start Menu option).

    The option dialog box that displays next allows you to configure how the connection will behave. Since mine will be going over very strong wireless connection, there should be little to no lag and so I've set the highest settings for connecting to the remote computer. You'll need to configure this based on your specific network conditions. However, the "auto" selection for quick options works really well for most situations.

    I clicked the "Save connection settings as default" since I will be using this connection over and over. I clicked Connect and was immediately prompted for a password (remember the password you set on the Mac machine to allow users to control that box?). 
     

    I entered the password and viola!!