TFS SDK 2010 – Part 4 - Create a new User Story, with the implementation (Tasks) and test scenarios (Test Case)

by Ewald Hofman 10. December 2009 17:31

In Part 1 I have described how to access the Application Instance of the TFS server. This post describes how you can create new work items, including a new linked work item. The new link makes use of the new link type in TFS 2010, so it shows up on the correct tab page. In this example a new User Story is created with one Task as its implementation and one Test Case which tests the User Story:

In order to get access to the work items, add a reference to:

  • Microsoft.TeamFoundation.WorkItemTracking.Client.dll

You can find the dll’s in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0

Then you have to add the following using statements:

using Microsoft.TeamFoundation.WorkItemTracking.Client;

You can now create the work items with the following code:

// Get the work item store
WorkItemStore wiStore = tfai.GetTeamFoundationServer(tpc.Id).GetService<WorkItemStore>();

// Get the team project
var project = wiStore.Projects["Agile"];

// Create a new User Story
var wiUserStory = new WorkItem(project.WorkItemTypes["User Story"])
{
    Title = string.Format("New User Story, created at {0:g}", DateTime.Now),
    Description = "This is an example how you create a new work item with the SDK"
};
wiUserStory.Save();

// Create a new Task
var wiTask = new WorkItem(project.WorkItemTypes["Task"])
{
    Title = "Create a very secure design"
};
wiTask.Save();

// Add a parent-child link between User Story and Task
var hierarchicalLink = wiStore.WorkItemLinkTypes["System.LinkTypes.Hierarchy"];
wiUserStory.WorkItemLinks.Add(new WorkItemLink(hierarchicalLink.ForwardEnd, wiTask.Id));
wiUserStory.Save();

// Create a new Test Case
var wiTestCase = new WorkItem(project.WorkItemTypes["Test Case"])
{
    Title = "Test on security",
};
wiTestCase.Fields["Steps"].Value = "<steps id=\"0\" last=\"2\"><step id=\"1\" type=\"ActionStep\"><parameterizedString>" + 
                                   "<text>Go to the correct url</text></parameterizedString><parameterizedString /><description />" + 
                                   "</step><step id=\"2\" type=\"ActionStep\"><parameterizedString><text>Hack the site</text>" + 
                                   "</parameterizedString><parameterizedString /><description /></step></steps>";
wiTestCase.Save();

// Add a tested by link between User Story and Test Case
var testedByLink = wiStore.WorkItemLinkTypes["Microsoft.VSTS.Common.TestedBy"];
wiUserStory.WorkItemLinks.Add(new WorkItemLink(testedByLink.ForwardEnd, wiTestCase.Id));
wiUserStory.Save();

Tags:

TFS SDK | VSTS 2010

Comments

12/11/2009 10:13:49 AM #

Clemens Reijnen

Ewald,  in the namespace Microsoft.TeamFoundation.TestManagement.Client you can find more testcase / teststep related functionality, wil make the creation of testcase and teststeps easier [not that xml]. I think you can cast the wi to Itestcase... Used it for the testcase generation www.clemensreijnen.nl/.../...-ActivityDiagram.aspx

Clemens Reijnen Netherlands | Reply

12/11/2009 11:18:23 AM #

Ewald Hofman

Clemens,
I will create a seperate blog post on this topic soon then. Thanks for the notification!

Ewald Hofman Netherlands | Reply

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.6.1.0
Theme by Mads Kristensen

About the author

 

Ewald Hofman is MVP VS ALM and consultant at Avanade. His specialization is Application Lifecycle Management solutions based on Visual Studio ALM.

 

 

ClusterMap

Statistics

Statistics created at 09 Sep 2009

105 posts
129 comments
73 raters
124043 visit (345 per day)
13 users online

Recent comments

Comment RSS