I am using VSTS with git.
I have test cases with many bug work items being linked to them.
I want to specifically retrieve all bug work items linked to a particular test case using .NET Client Library or VSTS REST API. The version of the REST API can be 4.0 or later.
I could not find info pertaining to retrieving bug work items linked to a particular test case, though there is info related to retrieving all bug work items.
Here is the code I tried :
static List GetLinkedWorkItems() { int[] workitemIds = new int[] { 12697 };
//VssConnection connection = Context.Connection;
VssConnection connection = new VssConnection(new Uri(vstsCollectionUrl), new VssClientCredentials());
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
List<Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem> workitems = workItemTrackingClient.GetWorkItemsAsync(workitemIds, expand: WorkItemExpand.Links | WorkItemExpand.Relations).Result;
foreach (var workitem in workitems)
{
Console.WriteLine("Work item {0}", workitem.Id);
if (workitem.Links != null)
{
foreach (var link in workitem.Links.Links)
{
Console.WriteLine(" {0} {1}", link.Key, link.Value);
}
}
}
return workitems;
}
Note that there's no connectivity issues to VSTS. Also, I tried with query based approach as given below, but no use :
VssConnection connection = new VssConnection(new Uri(vstsCollectionUrl), new VssClientCredentials());
//create http client and query for resutls
WorkItemTrackingHttpClient witClient = connection.GetClient<WorkItemTrackingHttpClient>();
Wiql query = new Wiql() { Query = "SELECT [Id], [Title], [State] FROM workitems WHERE [Work Item Type] = 'Test Case'" };
WorkItemQueryResult queryResults = witClient.QueryByWiqlAsync(query).Result;
//Display reults in console
var l = queryResults.WorkItemRelations;
var t = queryResults.WorkItems.Skip(0).Take(100);
if (queryResults == null || queryResults.WorkItems.Count() == 0)
{
Console.WriteLine("Query did not find any results");
}
else
{
foreach (var item in queryResults.WorkItems)
{
Console.WriteLine(item.Id);
Console.WriteLine(item.Url);
}
}