Visual Studio

Creating backlog items for your scrum project in TFS 2012

In my last post, I showed how to programmatically create areas for a scrum team project in TFS 2012. In this post, I’m going to show how to add product backlog items.

Once you understand how retrieve services from a TfsTeamProjectCollection object, interacting with TFS is just a matter of knowing which services to use.  For adding work items into TFS this can be accessed through the WorkItemStore service.  This service gives you access to any work items in a team project and the ability to manipulate them.

In order to create a work item, it’s required to know what type of item it is.  In the scrum process template, items in the backlog are work items of the “Product Backlog Item” type.  It’s possible to also iterate through the work item types to see what’s available in your process as well.  If you’re working with a  different process template, there could be any variety of work item types.  After retrieving the type, it’s possible to finally create the product backlog item.

Now, in this example, I did not go through the work of actually validating the work item.  However, there is a Validate method.  When using the Validate method, if there is any validation problem with the WorkItem, it will return an error for exactly which field in the work item failed to validate.  Of course, the Save method will throw an exception if the WorkItem is invalid as well.

Here’s a sample set of code to add items to the product backlog.

public static void AddProductBacklog(TfsTeamProjectCollection projectCollection, 
    string projectName, string title, 
    string description, string areaPath=null)
{
    if (projectCollection == null)
        throw new ArgumentNullException("projectCollection");

    if (projectName == null)
        throw new ArgumentNullException("projectName");

    if (title == null)
        throw new ArgumentNullException("title");

    if (description == null)
        throw new ArgumentNullException("description");

    var collectionStores = projectCollection.GetService<WorkItemStore>();
    var store = collectionStores.Projects[projectName];

    if (!store.WorkItemTypes.Contains("Product Backlog Item"))
        throw new InvalidOperationException("The project " 
            + projectName + " does not support product backlog items.");

    WorkItem item = new WorkItem(store.WorkItemTypes["Product Backlog Item"]);
    item.Title = title;
    item.Description = description;

    if (areaPath != null)
        item.AreaPath = areaPath;

    item.Save();
}

I hope this helps, and get’s you a step closer to being able to use the scrum template in TFS.

Visual Studio 2012 Release Candidate – Review #1

I’ve been using Visual Studio 2012 (previously named Visual Studio 11) since the first preview. Here are some of my impressions from it. So far I’ve heard a lot of fluff from the Microsoft people, and it the IDE does live up to some of it.  However, there are also shortcomings to the IDE.

I should give you a disclaimer. I do not use many of the fancy bells and whistles in the IDE. I’m primary a middle-ware .NET/SQL Server developer. While I’ll build a WPF or MVC application occasionally, I mainly spend my time writing plain old code in the C# editor for windows services.

I’m sure there are plenty of additional features that can be blogged about, but these are the main things I’ve noticed.

Favorite Feature #1: Better Diff and Merge Support

My favorite feature are the enhancements to the diff and merge tooling for source control. My office uses TFS and the out of box version of the diff tool hadn’t been improved much since the days of Visual SourceSafe. The new tooling has syntax coloring, and better visualization of where diffs apply across the files. This was a great step forward, and I won’t need to install CodeCompare to be able to use TFS. Unfortunately, this feels like functionality that should have always been there, but kudus to the VS team for FINALLY getting it in.

Favorite Feature #2: The preview pane

Select a file in the solution explorer, it pops up on the document pane of visual studio and is show in a tab on the right side of the tab well.  As you continue to click around, the same tab is used to preview different files.  The tab can be promoted by editing or by opening it like normal at which point the file is opened as a normal tab.

Favorite Feature #3: Faster code editor

In the code editor itself, Intellisense seems to display fast.

Favorite Feature #4: TFS pending changes

In the past, I had a pending change list that could at times have a 20-30 files in it.  Most of the time, I did not want to check those files in and would have to deselect them in what seemed like every check in.  In VS 2012, it’s possible to exclude items from the check in list.  Once they are excluded, they won’t be included in the list to check in unless it is explicitly done so.  Now if I have 20-30 files open for editing I’m not going to check in anytime soon, I can just exclude them and go about other work when the need arises.

Gripe #1: Unit testing is a horrible step backwards from Visual Studio 2010

I’ve seen a lot of posts by Microsoft people toting the new unit testing functionality. If anyone has tried this in the real world against a complex pre-exisitng project, you’ll notice it’s practically unusable.

First, the test viewer is gone. It’s been replaced by the Unit Test explorer. That in and of itself is not so bad, but the lack of responsiveness in the UI is horrible. It can take up to a minute after the build for the IDE just to discover my tests. After that it can take up to a minute just to get a test to run. Anything more than a second or so is pretty bad when a lot of my workload consists of edit-compile-rerun unit tests.

The unit test explorer also lacks good searching capabilities. There are very few filters on the tests to be able to search on. You can search on things like fully qualified name, but beyond that the filters are useless. This makes it extremely difficult to locate tests to run.

Overall, the UI in the unit test explorer is a major step backwards. I would much prefer they would have kept the Test Viewer from Visual Studio 2010 rather than re-implementing it with only a handful of features that were in it before.

Microsoft totes #2 major features it added to unit testing.

The first is enabling unit tests across platforms. For example, NUnit tests can be run as first class citizens in the IDE with the installation of an extension. So far, this feature has been great, and being able to leverage NUnit rather than being tied down to the MSTest framework (which feels like it’s many years old now) is great.  Javascript unit tests can be run, other language tests can be run, etc…

The second is the continuous run of unit tests. This feature is a non-starter for me, and I’ll likely never be able to use it. The idea is that you can hit a button to cause tests to be continuously run (automatically run after every build). However, since this list cannot be restricted by a category or something similar, it would be impossible to use. Our company has unit tests that aren’t pure unit tests that access the DB, etc and cause them to run longer. These tests simply cannot be completed very quickly. So, when I have a unit test suite that can take 2 hours to run on a whole, it just is not possible to run it in that way.  NCrunch is a solution that is much more robust, and for the time being is free. Although, I have not be able to get it to work with Moles.

In retrospect, the changes in unit testing have been so bad I’ve heard of developers not adopting the beta/release candidate because of them.  If this isn’t seriously improved by the release, I’ll likely not be able to use the VS 2012 functionality for unit testing out of the box.  I’m very skeptical that it will change before release since it really hasn’t changed noticeably since the first preview, and the product is already in the release candidate stage.

Thankfully, there are alternatives that can be purchased that should make up the gap for the unit testing problems in VS 2012.  However, it’s sad that I can’t get a better experience for unit testing out of the box with Visual Studio as unit testing is integral to produce quality code.

Gripe #2: Who cares how this looks, just give me more functionality!

A lot has been made of the new look of the IDE. Honestly I really don’t care what it looks like as long as I can get my job done efficiently. Some improvements have been made here, but some other parts of the product are seriously lacking that I wish they would have spent more time on rather than spending so much energy on how the UI looks.

Gripe #3: Moles and PEX name change

I had left the Moles framework for dead as no updates had been released for over a year and the project site had seemed to be abandoned. The good news Moles has become a first class tool in VS 2012.  The bad news is it’s being replaced by “The Fakes” framework which is very similar, but with moles classes being renamed. It’s going to be a pain to go through and change any tests based on Moles tests just for an unnecessary naming change.

To recap, there are some very good things that have been added to the IDE for Visual Studio 2012.  However, there definitely are setbacks in the release candidate of Visual Studio.  I hope Microsoft will work out the kinks before the final release.