I need to get a list of test cases from a request to TFS.
TfsTeamProjectCollection tfsTeamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("server_address")); ITestManagementService testMangementService = (ITestManagementService)tfsTeamProjectCollection.GetService(typeof(ITestManagementService)); ITestManagementTeamProject testManagementTeamProject = testMangementService.GetTeamProject("project_name"); Next, I get a list of all requests
IList<ITestCaseQuery> testCaseQuery = testManagementTeamProject.Queries; Then I get a list of test cases in the request
List<ITestCase> testCaseList = testManagement.TestCases.Query(testCaseQuery["selected_query"].QueryText).ToList(); The problem is that if the Type of Query is Flat list of work items, then I get all the test cases in the query, and if the Type of Query is Work items and direct link or Tree of work items, it throws an exception: "TF248021: You can’t give you a list of work items. If the query type is "Flat list of work items", then the query string will be: "select [System.Id], ... from WorkItems ...", and if - "Work items and direct link" or "Tree of work items ", then this:" select [System.Id], ... from WorkItemLinks ... "This happens if I add a Product Backlog Item to the query, in addition to test cases.
About the value of the testCaseQuery field ["selected_query"]. QueryText. If the field value is:
"select [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State], [System.Tags] from WorkItems where [System.TeamProject] = @ project and ( [System.WorkItemType] = 'Test Case' and [System.Title] contains words 'new' or [System.WorkItemType] = 'Product Backlog Item') "then everything works. And if the value is:
"select [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State], [System.Tags] from WorkItemLinks where (Source. [System.TeamProject] = @ project and (Source. [System.WorkItemType] = 'Test Case' or Source. [System.WorkItemType] = 'Task' or Source. [System.WorkItemType] = 'Feature')) and ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward') and (Target. [System.TeamProject] = @ project and Target. [System.WorkItemType] <> ") mode (Recursive)" "
then throws an exception.