Пример #1
0
        /// <summary>
        /// Get ID on an existing test suite by path in test plan
        /// </summary>
        /// <param name="TeamProjectName"></param>
        /// <param name="TestPlanId"></param>
        /// <param name="SuitePath"></param>
        /// <returns></returns>
        static int GetSuiteId(string TeamProjectName, int TestPlanId, string SuitePath)
        {
            TestPlan testPlan = TestManagementClient.GetPlanByIdAsync(TeamProjectName, TestPlanId).Result;

            int parentSuiteId = 0;

            if (int.TryParse(testPlan.RootSuite.Id, out parentSuiteId))
            {
                if (SuitePath == "")
                {
                    return(parentSuiteId);
                }

                string[] pathArray = SuitePath.Split(new char[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);

                for (int i = 0; i < pathArray.Length; i++)
                {
                    TestSuite testSuite = TestManagementClient.GetTestSuiteByIdAsync(TeamProjectName, TestPlanId, parentSuiteId, 1).Result;

                    string parentSuiteIdStr = (from ts in testSuite.Suites where ts.Name == pathArray[i] select ts.Id).FirstOrDefault();

                    if (!int.TryParse(parentSuiteIdStr, out parentSuiteId))
                    {
                        break;
                    }

                    if (i == pathArray.Length - 1)
                    {
                        return(parentSuiteId);
                    }
                }
            }

            return(0);
        }