1

我正在将测试用例从 xml 文件导入到 TFS2010 并得到一个异常。但是没有关于绝对不正确的信息。

"Work item 0 is invalid and cannot be saved. Exception: 'TF237124: Work Item is not ready to save'."

如何确定从 xml 导入的数据有什么问题?

using System.Text.RegularExpressions;
  using System.Xml;
  using Microsoft.TeamFoundation.Server;
  using Microsoft.TeamFoundation.WorkItemTracking.Client;
  using System;
  using System.Linq;

  internal class Program
  {
    // Input File
    private static TestLink testLink = new TestLink("E:\\dev\\TestLinkToTfs\\testsuites.xml");

    // Target TFS server
    private static Tfs tfs = new Tfs("http://host:8080/tfs/Test", "Test");

    private static void Main(string[] args)
    {
        var testLinkTestCase = testLink.GetTestCases().Take(1).ToList();
        var steps = testLinkTestCase.Descendants("step");
        var testCase = tfs.Project.TestCases.Create(tfs.Project.WitProject.WorkItemTypes["Test Case"]);
        testCase.Title = testLinkTestCase.Attribute("name").Value;

        var summary = testLinkTestCase.Descendants("summary").ToList();
        var issueId = TestLink.GetLinkedIssueId(summary);

        var regEx = new Regex(@"[^a-zA-Z0-9 -]");
        var grandParentName = regEx.Replace(testLinkTestCase.Parent.Parent.Attribute("name").Value, string.Empty);
        var parentName = regEx.Replace(testLinkTestCase.Parent.Attribute("name").Value, string.Empty);

        var area = string.Format(@"Test\Test Cases\{0}\{1}", grandParentName, parentName);

        testCase.CustomFields["Assigned To"].Value = string.Empty;
        testCase.Area = area;

        Tfs.AddSteps(steps, testCase);

        testCase.Save();
      }

      Console.ReadKey();
    }
  }
}
4

1 回答 1

1

当 Work Item id 为 0 时,表示这是动态创建的,并且某些字段值无效。你应该试试这个方法

workitem.validate();

在您保存工作项然后尝试调试您的代码之前。这将告诉您包含无效数据的确切字段。如果您发布用于此目的的代码和 xml,我可能会更有帮助。

于 2013-04-09T23:27:17.237 回答