How to run and debug silverlight unittests inside Microsoft Visual Studio 2010

The Microsoft Test project template in Microsoft Visual Studio 2010 does not support adding a reference to a Silverlight class library. To unittest a function in a Silverlight class library you can follow the steps below:

 

– Install the Microsoft Silverlight Toolkit April 2010 (http://silverlight.codeplex.com/releases/view/43528)

– After installing the Microsoft Silverlight Toolkit April 2010, you can find a [Silverlight Unit Test Application] project template, under Installed Templates > Visual C# > Silverlight in the Add New Project wizard in Microsoft Visual Studio 2010.

image

 

– This will add 2 projects to your solution, a [test project] and a [test application] to run the Silverlight unittests in the browser.

– Add a reference in the [test project] to the Silverlight class library to test.

– Now you can run the unittest in a browser by starting the [test application]:

image

 

 

If you don’t want to run the silverlight unittests in the browser, but directly in Microsoft Visual Studio 2010, like normal unittests, follow the steps below:

 

– Install Jetbrains resharper

– Download the JetBrains Resharper plugin agunit [http://agunit.codeplex.com/]

– Create the folder [C:\Program Files (x86)\JetBrains\ReSharper\v6.0\Bin\Plugins\AgUnit] if it does not exist.

– Extract the agunit zip and add the contents to the folder: [C:\Program Files (x86)\JetBrains\ReSharper\v6.0\Bin\Plugins\AgUnit].

– Open your solution containing the Silverlight test project in Microsoft Visual Studio 2010 and click on the green circle next to your silverlight unittest:

 

image

 

You can now run your Silverlight unittest directly from Microsoft Visual Studio 2010

 

You can add only a Silverlight [test project], without the [test application] to a solution by unchecking the [Host the Silverlight application in a new or existing Web site in the solution] checkbox:

image

How to boot from an VHD without host OS

You can format the drive of you’re laptop, copy a VHD file to the laptop, by using the Windows 7 installation DVD and than boot from the VHD file.

The hard drive will contain only one file: C:\VHD\MyVritualMachine.vhd

 

This post is just a summary of the post: https://www.roelvanlisdonk.nl/?p=1530 it will describe the steps, how to copy a working VHD image to an “empty” laptop and boot from the VHD file.

Notes

– VHD should run Windows 2008 R2 or Windows 7

 

1. Boot into you’re VHD on machine A

2. execute C:\Windows\System32\sysprep\sysprep.exe

[Out-of-Box Experience (OOBE) and check the Generalize checkbox]

3. Boot from the Windows 7 DVD on Machine B

4. Run the installation of Windows 7 only to the step where you can format the hard drive

5. Format the hard drive (now 2 partitions will be created, one 100MB and one the rest of you’re hard drive)

6. Press SHIFT F10 to open a command window during installation

7. Edit the boot manager by using the bcdedit.exe tool:

    • bcdedit /copy {current} /d “MyMachine Description

    • The previous statement returns a GUID like: {aa2e3972-7a31-11df-987b-b52175dc348f}

    • bcdedit /set {aa2e3972-7a31-11df-987b-b52175dc348f} device vhd=[C:]\VHD\MyVritualMachine.vhd

    • bcdedit /set {aa2e3972-7a31-11df-987b-b52175dc348f} osdevice vhd=[C:]\VHD\MyVritualMachine.vhd

    • bcdedit /set {aa2e3972-7a31-11df-987b-b52175dc348f} detecthal on

    • bcdedit /set hypervisorlaunchtype auto

    • The previous statement is only needed when the virtual machine is running Microsoft Windows 2008 R2 with the hyper-v role enabled.

  • Reboot Machine B

  • After rebooting you should see two entries one with the description “Windows 7” and an other with the description “MyMachine Description

If you laptop requires SATA III drivers just copy these drivers to a USB stick, so it can be used in the mini setup run on every syspreped machine.