Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在TFS中查找给定ITestCase对象的所有共享步骤引用_C#_Tfs_Tfs 2015_Tfs Sdk - Fatal编程技术网

C# 如何在TFS中查找给定ITestCase对象的所有共享步骤引用

C# 如何在TFS中查找给定ITestCase对象的所有共享步骤引用,c#,tfs,tfs-2015,tfs-sdk,C#,Tfs,Tfs 2015,Tfs Sdk,假设我有一个ITestCase对象 ITestCase tc = project.TestCases.Find(2034); 其中,project是通过以下方式获得的类型为ITestManagementTeamProject的对象: TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(tfsLocation)); ITestManagementServic

假设我有一个
ITestCase
对象

ITestCase tc = project.TestCases.Find(2034);
其中,
project
是通过以下方式获得的类型为
ITestManagementTeamProject
的对象:

TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(tfsLocation));
ITestManagementService testService = tfs.GetService<ITestManagementService>();
return testService.GetTeamProject(projectName);
tfstreamprojectcollection tfs=tfstreamprojectcollectionfactory.GetTeamProjectCollection(新Uri(tfsLocation));
ITestManagementService testService=tfs.GetService();
返回testService.GetTeamProject(projectName);
考虑到我之前没有关于该测试用例的任何状态知识,我如何获得该特定测试用例的所有共享步骤引用(甚至不知道是否有一个)

请提供帮助。

有一个从测试用例调用共享步骤的。您只需要使用FindSharedStep方法从服务器返回共享步骤定义。示例代码供您参考:

public ISharedStep tstSharedStep { get; private set; }

public ISharedStepReference tstSharedStepRef { get; private set; }

    foreach (ITestAction tstAction in tstCase.Actions)
            {
                tstSharedStep = null; 
                tstSharedStepRef = tstAction as ISharedStepReference;
                    if (tstSharedStepRef != null)
                    {
                        tstSharedStep = tstSharedStepRef.FindSharedStep();
                        foreach (ITestAction tstSharedAction in tstSharedStep.Actions)
                        {
                            ITestStep tstSharedTestStep = tstSharedAction as ITestStep;
                            resultData.Step = Regex.Replace(tstSharedTestStep.Title, @"<[^>]+>|&nbsp;", "").Trim();
                            resultData.ExpectedResult = Regex.Replace(tstSharedTestStep.ExpectedResult, @"<[^>]+>|&nbsp;", "").Trim();

                        }
                    }
                    else {
                     // regular step action
                    }

}
public ISharedStep tstSharedStep{get;private set;}
public ISharedStepReference tstSharedStepRef{get;private set;}
foreach(tstCase.Actions中的ITESTATION tstAction)
{
tsharedstep=null;
tstSharedStepRef=tstAction作为ISharedStepReference;
if(tstSharedStepRef!=null)
{
tstSharedStep=tststsharedstepref.FindSharedStep();
foreach(tstSharedStep.Actions中的iTestation tsharedAction)
{
ITestStep tstSharedTestStep=tstSharedAction作为ITestStep;
resultData.Step=Regex.Replace(tstSharedTestStep.Title,@“]+>|“,”).Trim();
resultData.ExpectedResult=Regex.Replace(tstSharedTestStep.ExpectedResult,@“]+>|“,”).Trim();
}
}
否则{
//规则步进动作
}
}

太棒了。谢谢最后一个问题是,如果我需要删除共享步骤引用,那么删除该测试用例的所有操作是否可以完成此任务?@SohamDasgupta是的,您可以使用
TestCase.Actions.remove(xx)
。下面是一个相关的线程和一些代码示例: