再会!
我尝试在测试计划 tfs 2010 上解析树。
所以,我可以得到测试计划:
var planOld = helperOldProject.GetTestPlan("TestProject", 10); // 10- id of test plan
ITestManagementTeamProject project1 = helperNewProject.GetProject(sourceserverurl, sourceproject);
然后我以编程方式创建新的测试计划:
//Create a Test Plan Programmatically
ITestPlan planNew = project1.TestPlans.Create();
planNew.Name = planOld.Name;
planNew.StartDate = DateTime.Now;
planNew.EndDate = DateTime.Now.AddMonths(2);
planNew.AreaPath = "TestArea";
planNew.Description = planOld.Description;
planNew.State = planOld.State;
// other attributes: plan.AreaPath, plan.Description,plan.State
planNew.Save();
And then i need to parse RootSuite tree:
var suiteOld = planOld.RootSuite;
// Parse Root:
IStaticTestSuite suiteNew = project1.TestSuites.CreateStatic();
suiteNew.Title = suiteOld.Title;
planNew.RootSuite.Entries.Add(suiteNew);
foreach (var tcc in suiteOld.TestCases)
{
var tc = helperOldProject.teamProject.TestCases.Find(tcc.Id);
var tc2 = helperNewProject.teamProject.TestCases.Create();
tc2.Description = tc.Description;
tc2.Owner = tc.Owner;
tc2.Title = tc.Title;
tc2.Save();
suiteNew0.Entries.Add(tc2);
planNew.Save();
}
然后我需要解析子树:
CreateSubTree(ref project1,ref planOld,ref planNew,ref helperOldProject,ref helperNewProject);
public static void CreateSubTree(ref ITestManagementTeamProject project1,ref ITestPlan planOld,
ref ITestPlan planNew,ref Helper helperOldProject,ref Helper helperNewProject)
{
Console.WriteLine("SubSuites.Count: " + planOld.RootSuite.SubSuites.Count);
foreach (ITestSuiteBase suiteOld in planOld.RootSuite.SubSuites)
{
IStaticTestSuite suiteNew = project1.TestSuites.CreateStatic();
// planNew.RootSuite.SubSuites.Add(suiteNew);
IStaticTestSuite staticSuiteOld = suiteOld as IStaticTestSuite;
foreach (ITestSuiteEntry tccOld in staticSuiteOld.TestCases)
{
suiteNew.Title = suiteOld.Title;
planNew.RootSuite.Entries.Add(suiteNew);
//planNew.RootSuite.SubSuites.Add(suiteNew);
var tc = helperOldProject.teamProject.TestCases.Find(tccOld.Id);
var tc2 = helperNewProject.teamProject.TestCases.Create();
tc2.Description = tc.Description;
tc2.Owner = tc.Owner;
tc2.Title = tc.Title;
tc2.Save();
suiteNew.Entries.Add(tc2);
}
Console.WriteLine(suiteOld.TestSuiteEntry);
}
}
所以,我解析了一个新的子树元素,但我知道,在那个节点之后我还有另一个节点。像这样:
根:元素1,元素2,元素3 ...
--- 节点 1:元素 1,元素 2....
-------- 节点2:元素1,元素2...
但是 planOld.RootSuite.SubSuites.Count==1; 我只看到 Root 和 Node1 的元素。
另一个问题是创建新的子树:此代码不起作用:
planNew.RootSuite.SubSuites.Add(suiteNew); // cannot add,remove item error.
请帮我解析一下!为什么我不能在树上添加子节点?
谢谢!