我正在尝试以编程方式更新测试用例的区域。
我的代码似乎合乎逻辑,但失败了:
Microsoft.TeamFoundation.WorkItemTracking.Client.dll
中发生未处理的“Microsoft.TeamFoundation.WorkItemTracking.Client.ValidationException”类型异常其他信息:TF400276:您试图为未打开或部分打开的工作项的字段设置值。您无法为未打开或部分打开的工作项的字段设置值。
以下是代码:
private static void Main(string[] args)
{
TeamProjectPicker tpp = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, false);
tpp.ShowDialog();
var tc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(
tfsUri,
new UICredentialsProvider());
tc.EnsureAuthenticated();
var wiStore = tc.GetService<TestManagementService>();
var project = wiStore.GetTeamProject(tpp.SelectedProjects[0].Name);
SetAreaPathByTestSuiteID(project, 501);
}
private static void SetAreaPathByTestSuiteID(ITestManagementTeamProject project, int testSuiteID)
{
var testSuite = project.TestSuites.Find(testSuiteID).TestCases;
foreach (ITestSuiteEntry entry in testSuite)
{
ITestCase theCase = entry.TestCase;
theCase.Area = "NewAreaPath"; //Error thrown here
theCase.Save();
}
}
答案 0 :(得分:4)
我知道这个帖子已经过时了,但无论如何我会回答它,以防有人遇到同样的问题。为了能够编辑测试用例,您应该像这样调用Open():
theCase.WorkItem.Open();
就是这样。
答案 1 :(得分:0)
您应该只调用一个WorkItem。
testCase.WorkItem.PartialOpen();
如果您致电
testCase.WorkItem.Open();
然后保存,您将覆盖步骤和参数值