Thursday, February 21, 2008

Integration Testing Woes with TFS WorkItemStore

Working with YakShaver I've been worried about how I was going to test without setting up a full Team Foundation environment (which is a challenge sometimes in itself, well, it's just a tedious job). Also if I make a mistake, I'm looking at quite a bit of time to rebuild my environment.

This was a challenge until I realized that Microsoft has released VPC images of TFS for download that is the full environment all setup and ready to go. Yes, the image expires on April 1, but they will release more images after that. And I'm not as worried about keeping code there as I'm' testing against working with the TFS API.

Add in the fact that Virtual PC 2007 is now a free download and we have an instant environment for testing. The machine name stays the same (TFSRTM08) so I can just setup simple constants in my unit tests for connectivity. However, this isn't what this entry is about. Just letting people know its useful.

In working with this image I ran into an issue where I would create an area and want to instantly use it. I know from experience with the Team Explorer that if you create a new work item, then add an area or iteration and want to use that in the work item you created previously you must refresh the work item page so the new Area's and Iterations show up.

However, there seems to be a bit of delay with using the VPC (at least I think so). Using the .RefreshCache() or .SyncToCache() methods on the WorkItemStore class seem a bit sketchy. They would work 1/3 times in my testing.

I didn't want my implementation to constantly check for an area because that could get it caught in an infinite loop. So in my testing class I create the area, and then wait until the workItemStore.Projects[ProjectName].AreaRootNodes[areaName] is available (you have to wrap in a try catch because if you try to get it and it doesn't exist you will get a ClientDeniedOrNotFoundException.

Here is an example:




bool areaFound = false;
while (!areaFound)
{
try
{
System.Threading.Thread.Sleep(3000);
tfsWorkItemStore.RefreshCache();
string tempArea = tfsWorkItemStore.Projects[currentProject.Name].AreaRootNodes[area].Path;
areaFound = true; // iif it isn't found an exception is thrown never getting to this.

} catch (Exception ex) {
areaFound = false;
}
}


I could use the contains method, but it looks for an instance of a Node and not just a string representation. This just seemed easier at the time to solve my problem without causing huge issues.

No comments:

Post a Comment