March 2011 - Posts

How to waste time with Lab Management – Missing the obvious that MTM points to a Team Project
Wed, Mar 30 2011 4:56

I posted a while ago about common confusion I had seen with Lab Management. We I have recently managed to get myself completely confused whilst working with Lab Management. It turns out the issue was so obvious I managed to miss it for hours, but as usual I learnt a good deal whilst trying to troubleshoot my stupidity.

I have a Lab Management system linked up to a a Team Project Collection (TPC). In this TPC there is a Team Project used for SharePoint development and on my Lab Management system I have an environment to allow testing of the SharePoint products. I setup a new Team Project in this TPC. In the new project I created a new MVC solution and created an automated build, which all worked fine.

I wanted to deploy this MVC application to a web server in an environment in my Lab Management system. So I created a basic web server environment and deployed it onto a host in my Lab. I then tried to create a Lab Management workflow build to deploy to the newly created environment. However the combo to select the environment was empty when I ran the wizard.

image

I was confused, I knew I had an environment on the Lab Management system, I had just created it in Test Manager (MTM) I could attach to it in MTM or Remote Desktop.

So I checked again

  • that the TPC was correctly registered with Lab Management
  • the environment was running in MTM
  • that all the configuration for the Team Project looked OK via TFSLABCONFIG.EXE

All to no avail. Then after far too long I realised I was not looking at the same things in MTM and Visual Studio.

When you are in the Lab Center (green border) pages of MTM there is no obvious indication of the Team Project you are using. I had forgotten this and got it into my head I was looking at all the environments and libraries for my whole TPC. THIS IS NOT THE CASE. The environments and libraries are Team Project specific and not TPC specific. I had created my new environment in my SharePoint team project not in my new MVC one.

To swap Team Project I needed to change to the Testing Centre (blue border) view and change the Test Plan (top right)

image

to get the dialog to change the Team Project.

image

Once this is done you can go to the Lab Center again and you see the environments for the selected Team Project. This was where I needed to create my environment.

At this point you will notice that all the templates and VMs you imported into the other Team project are not in this one. You have to reimport them from SCVMM and then create the environments in MTM for that Team Project

To the technical tip here is remember that Lab Center in MTM is Team Project specific – NOT Team Project Collection specific, but it does its best to not remind you of this fact so it is easy to forget.

How to expose IIS Express to external network connections and use a non-self signed certificate
Tue, Mar 22 2011 16:02

IIS Express is a great addition to the tools for .NET web developers; it allow a slightly cut down copy of IIS 7.5 to be run without administrative privileges on a developer’s PC. This means we can hopefully get away from the problems associated by either

  1. Using Cassini – which is not IIS and does not do any clever
  2. Using full IIS which means Visual Studio has to run as administrator to debug it and also causes source control issues when a project is shared between multiple developers (their IIS setup must match up)

If you install Visual Studio 2010 SP1 and IIS express you now get a new option, that is to use IIS express as your web server. This, via a few clicks, can be configured for SSL and should address 90%+ of the needs of most developers. Once a project is set to use IIS express the key properties are set via the VS Property windows

image

However you are not limited to only editing these options; but to do more you need to use some command line tools.

What I wanted to do

My problem was that I wanted to test a Windows Phone 7 application that used a WCF web service. If I switched the WCF project to use IIS Express the WP7 application could not access the web server as, for security reasons, IIS Express is by default limited to only responding to requests from the localhost. The WP7 application is on another device (or at least a VM for development), so its request are not handled.

So we need to enable remote access to the server. ScottGu said this can be done in his post about IIS Express, but not how to do it.

Also I wanted to test my WP7 application using HTTPS. This raised a second issue. By default IIS express uses a self signed certificate. When this is used the WP7 WCF client throws as error as it cannot validate the certificate. I needed to swap the certificate for a ‘real one’. Again ScottGu’s post says it can be done but not how.

How I got it working

NOTE: I think the process covers all the steps, but it took me a while to get this going so there is a chance I might have missed step. Please treat this as outline guide and not definitive way to get it going. if I find errors I will update the post and highlight them.

Step 1 – Get the right Certificate onto the Development PC

I had already installed  the wildcard SSL certificate we have on my development PC from ita .PFX file.

To confirm this was OK I load MMC (running as a local administrator). Loaded the certificates snap-in, browsed to Personal|Certificates and checked it was there. I then clicked on the certificate and made a note of its thumbprint, you need it later

image

Step 2 – List the certificates you have installed for IIS

I opened a command prompt as administrator and run the command

netsh http show sslcert

This will stream past so you probably want to pipe it into a file to look at. Anyway you should find an entry for the self sign certificate that Visual Studio created when you setup IIS Express (on port 44300 in my case). Something like

IP:port                 : 0.0.0.0:44300
    Certificate Hash        : c3a234250edfb2adcd2b501cf4c44d0281e29476
    Application ID          : {214124cd-d05b-4309-9af9-9caa44b2b74a}
    Certificate Store Name  : MY
    Verify Client Certificate Revocation    : Enabled
    Verify Revocation Using Cached Client Certificate Only    : Disabled
    Usage Check    : Enabled
    Revocation Freshness Time : 0
    URL Retrieval Timeout   : 0
    Ctl Identifier          : (null)
    Ctl Store Name          : (null)
    DS Mapper Usage    : Disabled
    Negotiate Client Certificate    : Disabled

We need to remove this self signed certificate so we can re-assign a real one to this port. To do this use the command

netsh http delete sslcert ipport=0.0.0.0:44300

then add the new certificate association using the command

netsh http add sslcert ipport=0.0.0.0:44300 certstorename=MY certhash=<certificate hash> appid=<appid>

<certificate hash> is the thumbprint of the SSL certificate found in step 1, with the spaces removed
<appid> can be any unique GUID

if you have the command line right it should say added OK. You could then run the list command again to check it is as you want.

So where are we up to…..

So at this point we have associated a real SSL certificate with any call to the port 44300 on this PC, note any call to this port, not just for IIS Express. If we do nothing else to configure IIS Express, let Visual Studio automatically start it, and try to load the site it will work for HTTP but when you try HTTPS it will error

image

If you inspect the certificate you will see it is using the one you set, but the certificate is linked to a Url, in my case *.blackmarble.co.uk so is deemed invalid when you try to use it with localhost.

We need to set IIS Express to respond on other addresses than localhost.

Step 3 – Making IIS Express respond to requests from the network

If you wish to make IIS Express respond to calls other than for localhost you have to run it as administrator, this is by design for security. Now it is fair to say from here onwards you are at the point where you lose some of the ease of use of the product as it does not ‘just work form Visual Studio’, but needs must.

We now need to edit the bindings of IIS Express. This could be done with command

c:\program files\iis express>appcmd set site "SiteName" /+bindings.[protocol='https', bindingInformation='*:44300:']

But I found it easier just to edit the edit the file C:\Users\[user name]\Documents\IISExpress\config\applicationhost.config in notepad. I altered the bindings section as follows

<bindings>
      <binding protocol="http" bindingInformation="*:60213:" />
      <binding protocol="https" bindingInformation="*:44300:" />
</bindings>

Basically I removed the :localhost at the end of each line. This allowing IIS Express to bind any Url not just localhost

Step 4 – Running IIS Express

You now need to just start your copy of IIS Express, this again has to be done from the command prompt running with administrative privileges. However, the command line parameters are identical to those used by Visual Studio (you can check task manager if you wish by showing the command line column on the processes tab)

"c:\Program Files (x86)\IIS Express\iisexpress.exe" /config: "c:\Documents and Settings\[username]\Documents\IISExpress\config\applicationhost.config" /site:"MyServer" /apppool:"Clr4IntegratedAppPool"

When you run this you should see the IIS Express process start-up.

So what have we ended up with?

So we now have IIS Express running the a wildcard certificate and listening to requests from any source. So as long as we use a Url valid for the SSL certificate we should be be able to load an HTTPS Url and get no errors.

However, be warned, due to the way we have had to launch IIS Express we have lost the ability to launch and debug from Visual Studio when not running as administrator. So I am not sure I have addressed the problem I started out try to address, I might as well just use the full version of IIS.

But look on the bright side I learnt something.

Thanks to Andy Westgarth for his assistance in getting to the bottom of assigning the right certificate, I was going in circles

A slow experience installing VS2010 SP1, but worth it in the end
Sat, Mar 19 2011 9:10

I got round to installing Visual Studio 2010 SP1 on my laptop last night; well I started last night via the Web Platform Installer method. It downloaded the bits fast but sat for ages on the first step, installing the actual service pack. There was no obvious activity on the CPU or disk. In the end I gave waiting and went to bed. I was pleased to see it was finished this morning.

So the tip here is be patient, applying this service pack is a job you start on your desktop before you go home, not when you come into the office.

So what is the biggest benefit thus far?

I can easily use IIS Express from with Visual Studio, so no more having to run Visual Studio as administrator to us my local IIS Server for development.

Getting the WP7 SDK onto a Windows Server 2008 TFS Build Agent
Thu, Mar 17 2011 4:25

If you try to create an automated TFS build of a Windows Phone 7 Silverlight application on a ‘default installed’ build agent you will see errors along the lines of

The imported project "C:\Program Files\MSBuild\Microsoft\Silverlight for Phone\v4.0\Microsoft.Silverlight.WindowsPhone.Overrides.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

This is because the PC your build agent is running on does not have the WP7 SDK installed.

Simple you would think, lets just install the SDK. Well, if your build box is based on any Windows Server operating system you quickly hit a problem that you get the error the “Windows 7 or Windows Vista is required”

image

There is no supported route around this, but there is a hack. The fix is to follow the UNSUPPORTED process on Aaron Stebner's blog. This edits the baseline.dat from the installation media to make, in my case, Windows Server 2008 a supported operating system. Once this was done the SDK could be installed and automated builds run.

As usually, as this is unsupported, it is buyer beware, try it at your own risk.

Speaking on VS 2010 ALM and Testing at events in Belfast and Dublin
Thu, Mar 10 2011 10:20

At the end of the month I will be speaking at a series of free Microsoft events in Belfast and Dublin. There going to be two session at each location

Managing application lifecycle “From requirements to retirement” with Team Foundation Server 2010

Better testing with lower costs - Saving your teams time and resources using Visual Studio 2010 and Microsoft Test Manager

So if you are in the area why not pop by?

Install order guidance for VS2010 SP1
Wed, Mar 9 2011 15:54

Further to yesterdays post on new bits for VS and TFS 2010, there is now some guidance to what order to apply SP1 to server and clients.

by But it works on my PC!
Filed under:
Fixed numerous issues with VS2008 using a /resetskippkgs
Wed, Mar 9 2011 15:50

I am doing some work on VS2008 at present and I when I started my VS2008, which I had not used for a while, I was plagued by errors along the lines of "The operation could not be completed". These occurred when running major features such as:

  • Loading LINQ to SQL Designer
  • Running the SQL 2008 Project Wizard

The fix turned out to be resetting the package skip loading flag. It seems a number of add-ins were not being loaded on startup. This command is run from the "Visual Studio 2008 Command Prompt" by typing

devenv /resetskippkgs

I also had problems trying to run tests using the standard Microsoft Test tools within Visual Studio. I got the error “Exception has been thrown by the target of an invocation”, but running tests using TestDriven.NET worked fine. This problem was not fixed with the /resetskippkgs. However, turns out it is a known issues if VS2008 SP1 and TFS, KB980216. The quick fix is to make sure I was connected to a TFS server. Once this was done the test could be run. There is a hotfix, but I can live without I think for now.

So the moral is, even if you don’t use an IDE everyday you can still break it with all the patching you do around it for other IDEs and underlying frameworks. A reset to defaults can often by just the kick it needs to get it working.

A day of new releases and announcements in Visual Studio 2010 land
Tue, Mar 8 2011 11:20

Today we have seen the release of the Visual Studio 2010 SP1 and the TFS-Project Server Integration Feature Pack. Both are available on the MSDN download site.

As well was the new downloads they have announced a change to licensing over Load Test Agent. This gives Visual Studio Ultimate with MSDN users the ability to do unlimited load testing. No longer do you need to purchase Load Test Packs, thus making load testing an option for more teams.

For more details see Brian Harry’s blog post on the new downloads and load testing

by But it works on my PC!
Filed under:
What to do with project dependencies?
Thu, Mar 3 2011 19:36

Many development teams hit the problem that they have dependencies on libraries that they do not want to have as part of their solutions. If these dependencies are open source projects then there are options using technologies like NuGet or OpenWrap. However, in many cases the dependency is to an internal project, such as the company standard logging library, which it is never going to put up into a centralised repository. So normally you end up with either:

  1. Adding the project for the shared assembly to the solution and rebuilding with the solution, probably via some branching model in source control to allow fixes to be merged between projects.
  2. Adding the assembly from a known location (maybe under source control)  that the team responsible for then shared library publish the current version to.

Both solutions can work, but they both have their pros and cons.

A different and interesting approach has been proposed in Sven Hubert’s post “Extended Dependency Management with Team Foundation Server” on http://www.TFSBlog.de. He suggests using a custom MSBuild task and .Targets files that allows you to cause an external project to be rebuild from source control (addressing option 1 without the need to add the actual VS project to the solutions) or to pick the built assemblies from the a given Team Build (addressing option 2).

If this problem is one you have come across this post makes for interesting reading.

by But it works on my PC!
Filed under: ,
The March 2011 version of the TFS Power Tools have been released
Thu, Mar 3 2011 18:37

The March 2011 version of the TFS Power Tools has been released. There are plenty of fixes and enhancements, especially to the TFS backup tool.

For more details have a look at Brian Harry’s blog.

by But it works on my PC!
Filed under:
Mocking out calls in unit tests to a TFS Server using Typemock
Thu, Mar 3 2011 18:06

If you are developing custom application using the TFS API then there is a good chance you will want to mock out the calls to your TFS server to enable better testing of the business logic in your application. The architecture of the TFS API does not lend itself to mocking using the standard means provided in most auto-mocking frameworks i.e there is not an interface for all the objects you care about. However, with Typemock Isolator you can fake the classes required, as Isolator can fake an instance of virtually any class.

So say we wanted to write a simple build monitor application for TFS Team Build system, we need to connect to a TFS server, get a list of historic builds, then select the last successful one. So our business logic method is as follows

/// <summary>
///  Gets the last successful build
/// </summary>
public static IBuildDetail GetLastNonFailingBuildDetails(string url, string projectName, string buildName)
{
    using (TeamFoundationServer tfs = new TeamFoundationServer(url))
    {
        IBuildServer buildServer = (IBuildServer)tfs.GetService(typeof(IBuildServer));
        return buildServer.QueryBuilds(projectName, buildName).Last(b => b.Status == BuildStatus.Succeeded || b.Status == BuildStatus.PartiallySucceeded);
    }
}

To test this, you would usually need a TFS server, with a set of historic build data already on it, but with Typemock you can avoid this requirement. OK we have to write bit of supporting code, but most of it would be common to a suite of tests, so the effort will not be too high overall and by doing it you get a test that can be run as part of the build process.

To be able to unit test our business logic (the last line of code in reality in this sample) we need to mock the call to the TeamFoundationServer (which is usually the blocking point for most mocking frameworks) and then mock the call to get the IBuildServer and return a set of data (which is usually possible with mocking frameworks).

Using Typemock we can get around these problems, the comments for each step are inline with the code.

[TestClass]
public class TFSTests
{
    [TestMethod]
    public void The_last_completed_and_non_failed_build_can_be_found()
    {
        // Arrange
        // Create the fake TFS server
        var fakeTfsServer = Isolate.Fake.Instance<TeamFoundationServer>();
        // Swap it in the next time the constructor is run
        Isolate.Swap.NextInstance<TeamFoundationServer>().With(fakeTfsServer);
 
        // Create a fake build server instance
        var fakeBuildServer = Isolate.Fake.Instance<IBuildServer>();
        // Set the behaviour on the TFS server to return the build server
        Isolate.WhenCalled(() => fakeTfsServer.GetService(typeof(IBuildServer))).WillReturn(fakeBuildServer);
        
        // Create some test data for the build server to return
        var fakeBuildDetails = CreateResultSet(new List<BuildTestData>() {
              new BuildTestData() {BuildName ="Build1", BuildStatus = BuildStatus.Failed},
              new BuildTestData() {BuildName ="Build2", BuildStatus = BuildStatus.PartiallySucceeded},
              new BuildTestData() {BuildName ="Build3", BuildStatus = BuildStatus.Failed},
              new BuildTestData() {BuildName ="Build4", BuildStatus = BuildStatus.Succeeded},
              new BuildTestData() {BuildName ="Build5", BuildStatus = BuildStatus.PartiallySucceeded},
              new BuildTestData() {BuildName ="Build6", BuildStatus = BuildStatus.Failed}
        });
        // Set the behaviour on the build server to return the test data, the nulls mean we don’t care about parameters passed
        Isolate.WhenCalled(() => fakeBuildServer.QueryBuilds(null, null)).WillReturn(fakeBuildDetails);
        
        // Act
        // Call the method we want to test, as we are using a fake server the parameters are actually ignored
        var actual = TFSMocking.BuildDetails.GetLastNonFailingBuildDetails("http://FakeURL:8080/tfs", "FakeTeamProject", "FakeBuildName");
 
        // Assert
        Assert.AreEqual("Build5", actual.BuildNumber);
    }
 
    /// <summary>
    /// A helper method to hide the Typemock code used to create each build results set
    /// </summary>
    /// <param name="builds">The parameters to populate into the build results</param>
    /// <returns>A set of build results</returns>
    private IBuildDetail[] CreateResultSet(List<BuildTestData> builds)
    {
        var fakeBuilds = new List<IBuildDetail>();
        foreach (var build in builds)
        {
            // Create a fake build result instance
            var fakeBuildDetails = Isolate.Fake.Instance<IBuildDetail>();
            // Set the properties, in this sample we only set a couple of properties, but this can be extended
            fakeBuildDetails.BuildNumber = build.BuildName;
            fakeBuildDetails.Status = build.BuildStatus;
            fakeBuilds.Add(fakeBuildDetails);
        }
        return fakeBuilds.ToArray();
    }
}
 
/// <summary>
/// A holding class for the build data we are interested in faking
/// </summary>
public class BuildTestData
{
    public string BuildName {get;set;}
    public BuildStatus BuildStatus {get;set;}
}

This sample is obviously fairly simple, but not that unrealistic. I have certainly written simple logic like this for build status applications. You could of course use some different architecture to make the business logic a bit more testable, but for such as basic requirement it is very tempting to keep it simple.

What I hope this post shows is that there is a way to test this type of logic without the need for a TFS server that has a suitable set of pre-created data and that the basic technique can be extended as much as is required to provide a mocked framework to allow unit testing of more complicated business logic.