Search code examples
visual-studio-2010tfsmicrosoft-test-managertfs-sdk

how to link a workitem which is task/testcase to another workitem/task using TFS API and C#.Net code?


I could get a test case object using TFS API.Now i want to link a task id(e.g. 435567) to this Test Case object's "Affected By" link type. Any sample code available to do this ?

I could see there is an add method for the testcase like below , but it doesnt task id as the parameter.

 testCase.WorkItem.WorkItemLinks.Add(<Microsoft.TeamFoundation.WorkItemTracking.Client.workitemlink.link >)

any idea how to link the taskid here ?


Solution

  • This blog post will help you. It creates a new user story with some test cases.

    var testedByLink = wiStore.WorkItemLinkTypes["Microsoft.VSTS.Common.TestedBy"];
    wiUserStory.WorkItemLinks.Add(new WorkItemLink(testedByLink.ForwardEnd, wiTestCase.Id));
    wiUserStory.Save();