【发布时间】:2019-09-10 22:34:27
【问题描述】:
我在打印 TFS 中的查询结果时需要帮助。
我正在运行代码以从 TFS 获取测试用例和测试执行记录。 提取有效,我得到了所有工作项的列表,以及所有相关信息。
我想出了如何打印出标准 TFS 字段。但是我找不到如何打印出自定义字段(也就是说,我们将它们添加到 TFS 测试用例记录中;它们不是开箱即用的)。
有没有办法运行查询,而不是获取记录集合,只需获取 SQL 查询将打印到屏幕上的原始输出字符串,我是否直接在数据库上运行它?
下面是我现在使用的代码。要让它运行,您需要将“我的数据库路径”替换为正确的路径,并将 [A custom field] 替换为相关路径。我正在努力解决的问题是如何打印出我的自定义字段的值,希望不必弄清楚它在工作项中的位置。
我确实发现这里有我的自定义字段的值(从“watch”字段复制的路径):
(new System.Collections.Generic.Mscorlib_DictionaryDebugView<int, object>(workitem.FieldData.m_latestData).Items[78]).Value
但是:对于每个自定义字段,我不想弄清楚它在哪个 items[] 位置;同样,当尝试将上述内容放在 Console.Writeline 语句中(或先将其分配给变量)时,它也不会编译。
using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
namespace tfs_api_starter
{
class Program
{
static void Main()
{
// connect to a tfs collection
var collectionUri = new Uri("https://path to my DB");
var tfsCollection = new TfsTeamProjectCollection(collectionUri);
// workitemStore object is used to query and update workitems
var workitemStore = tfsCollection.GetService<WorkItemStore>();
// query workitems
var queryText = "SELECT [System.Id], [System.WorkItemType], [System.Title], [System.State], [System.CreatedBy], [System.AreaPath], [System.IterationPath], [My Custom field] FROM WorkItemLinks WHERE Source.[System.WorkItemType] = 'Test Case' and (Target.[System.WorkItemType] = 'Test Execution' and Target.[System.CreatedDate] >= '2019-04-01T00:00:00.0000000') ";
var workitemCollection = new Query(workitemStore, queryText).RunLinkQuery();
foreach (var link in workitemCollection)
{
var workitem = workitemStore.GetWorkItem(link.TargetId);
if (workitem.Type.Name == "Test Case")
{
Console.WriteLine("{0}|{1}|{2}",
workitem.Id,
workitem.Title,
<my custom field value>);
}
if (workitem.Type.Name == "Test Execution")
{
Console.WriteLine("{0}|{1}|{2}", workitem.Id, workitem.Type.Name, workitem.State);
}
}
}
}
}
【问题讨论】:
-
你在寻找什么结果?
-
查询得到的实际数据。我现在得到的是一个包含大量信息的记录列表。对于所有符合查询条件的记录,我只需要我查询的字段的值。
-
能否请您提供一张图片,其中包含您获得的数据和您正在寻找的数据。
-
查看详细解释,附图片,这里:dropbox.com/s/0q5lric3lfwum5y/…