private void AddChildTestCases(ITestSuiteBase source, ITestSuiteBase target, ITestPlan targetPlan)
        {
            target.Refresh();
            targetPlan.Refresh();
            targetPlan.RefreshRootSuite();

            if (CanSkipElementBecauseOfTags(source.Id))
            {
                return;
            }

            Trace.WriteLine(string.Format("            Suite has {0} test cases", source.TestCases.Count), "TestPlansAndSuites");
            List <ITestCase> tcs = new List <ITestCase>();

            foreach (ITestSuiteEntry sourceTestCaseEntry in source.TestCases)
            {
                Trace.WriteLine($"Work item: {sourceTestCaseEntry.Id}");

                if (CanSkipElementBecauseOfTags(sourceTestCaseEntry.Id))
                {
                    return;
                }

                Trace.WriteLine(string.Format("    Processing {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites");
                WorkItem wi = targetWitStore.FindReflectedWorkItem(sourceTestCaseEntry.TestCase.WorkItem, me.ReflectedWorkItemIdFieldName, false);
                if (wi == null)
                {
                    Trace.WriteLine(string.Format("    Can't find work item for Test Case. Has it been migrated? {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites");
                    break;
                }
                var exists = (from tc in target.TestCases
                              where tc.TestCase.WorkItem.Id == wi.Id
                              select tc).SingleOrDefault();

                if (exists != null)
                {
                    Trace.WriteLine(string.Format("    Test case already in suite {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites");
                }
                else
                {
                    ITestCase targetTestCase = targetTestStore.Project.TestCases.Find(wi.Id);
                    if (targetTestCase == null)
                    {
                        Trace.WriteLine(string.Format("    ERROR: Test case not found {0} : {1} - {2} ", sourceTestCaseEntry.EntryType, sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites");
                    }
                    else
                    {
                        tcs.Add(targetTestCase);
                        Trace.WriteLine(string.Format("    Adding {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites");
                    }
                }
            }

            target.TestCases.AddCases(tcs);

            targetPlan.Save();
            Trace.WriteLine(string.Format("    SAVED {0} : {1} - {2} ", target.TestSuiteType.ToString(), target.Id, target.Title), "TestPlansAndSuites");
        }
コード例 #2
0
        /// <summary>
        /// Adds the test cases without suites.
        /// </summary>
        /// <param name="testCasesList">The test cases list.</param>
        public static void AddTestCasesWithoutSuites(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, List <TestCase> testCasesList)
        {
            testPlan.Refresh();
            string fullQuery = string.Format(AllTestCasesInTeamProjectQueryExpression, testManagementTeamProject.TeamProjectName);
            IEnumerable <ITestCase> allTestCases = testManagementTeamProject.TestCases.Query(fullQuery);

            foreach (var currentTestCase in allTestCases)
            {
                TestCase testCaseToAdd = new TestCase(currentTestCase, null, ExecutionContext.Preferences.TestPlan);
                if (!testCasesList.Contains(testCaseToAdd))
                {
                    testCasesList.Add(testCaseToAdd);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Gets all test case from suite.
        /// </summary>
        /// <param name="testPlan">The test plan.</param>
        /// <param name="suiteId">The suite unique identifier.</param>
        /// <param name="includeExecutionStatus">if set to <c>true</c> [include execution status].</param>
        /// <returns>
        /// list of all test cases in the list
        /// </returns>
        public static List <TestCase> GetAllTestCaseFromSuite(ITestPlan testPlan, int suiteId, bool includeExecutionStatus = true)
        {
            List <TestCase> testCases = new List <TestCase>();

            testPlan.Refresh();
            ITestSuiteBase currentSuite = testPlan.Project.TestSuites.Find(suiteId);

            currentSuite.Refresh();
            foreach (var currentTestCase in currentSuite.TestCases)
            {
                TestCase testCaseToAdd = new TestCase(currentTestCase.TestCase, currentSuite, testPlan, includeExecutionStatus);
                if (!testCases.Contains(testCaseToAdd))
                {
                    testCases.Add(testCaseToAdd);
                }
            }
            log.InfoFormat("Load all test cases in the suite with Title= \"{0}\" id = \"{1}\"", currentSuite.Title, currentSuite.Id);
            return(testCases);
        }
コード例 #4
0
        /// <summary>
        /// Gets all test cases in current test plan.
        /// </summary>
        /// <param name="initializeTestCaseStatus">if set to <c>true</c> [initialize test case status].</param>
        /// <returns>
        /// list of all test cases
        /// </returns>
        public static List <TestCase> GetAllTestCasesInTestPlan(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, bool initializeTestCaseStatus = true)
        {
            testPlan.Refresh();
            List <TestCase> testCasesList;

            testCasesList = new List <TestCase>();
            string fullQuery = string.Format(AllTestCasesInTeamProjectQueryExpression, testManagementTeamProject.TeamProjectName);
            IEnumerable <ITestCase> allTestCases = testManagementTeamProject.TestCases.Query(fullQuery);

            foreach (var currentTestCase in allTestCases)
            {
                TestCase testCaseToAdd = new TestCase(currentTestCase, currentTestCase.TestSuiteEntry.ParentTestSuite, testPlan, initializeTestCaseStatus);
                if (!testCasesList.Contains(testCaseToAdd))
                {
                    testCasesList.Add(testCaseToAdd);
                }
            }

            return(testCasesList);
        }
コード例 #5
0
 /// <summary>
 /// Adds the test cases without suites.
 /// </summary>
 /// <param name="testCasesList">The test cases list.</param>
 public static void AddTestCasesWithoutSuites(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, List<TestCase> testCasesList)
 {
     testPlan.Refresh();
     string fullQuery = String.Format(AllTestCasesInTeamProjectQueryExpression, testManagementTeamProject.TeamProjectName);
     IEnumerable<ITestCase> allTestCases = testManagementTeamProject.TestCases.Query(fullQuery);
     foreach (var currentTestCase in allTestCases)
     {
         TestCase testCaseToAdd = new TestCase(currentTestCase, null, ExecutionContext.Preferences.TestPlan);
         if (!testCasesList.Contains(testCaseToAdd))
         {
             testCasesList.Add(testCaseToAdd);
         }
     }
 }
コード例 #6
0
        /// <summary>
        /// Gets all test cases in current test plan.
        /// </summary>
        /// <param name="initializeTestCaseStatus">if set to <c>true</c> [initialize test case status].</param>
        /// <returns>
        /// list of all test cases
        /// </returns>
        public static List<TestCase> GetAllTestCasesInTestPlan(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, bool initializeTestCaseStatus = true)
        {
            testPlan.Refresh();
            List<TestCase> testCasesList;
            testCasesList = new List<TestCase>();
            string fullQuery = String.Format(AllTestCasesInTeamProjectQueryExpression, testManagementTeamProject.TeamProjectName);
            IEnumerable<ITestCase> allTestCases = testManagementTeamProject.TestCases.Query(fullQuery);
            foreach (var currentTestCase in allTestCases)
            {
                TestCase testCaseToAdd = new TestCase(currentTestCase, currentTestCase.TestSuiteEntry.ParentTestSuite, testPlan, initializeTestCaseStatus);
                if (!testCasesList.Contains(testCaseToAdd))
                {
                    testCasesList.Add(testCaseToAdd);
                }
            }

            return testCasesList;
        }
コード例 #7
0
 /// <summary>
 /// Gets all test case from suite.
 /// </summary>
 /// <param name="testPlan">The test plan.</param>
 /// <param name="suiteId">The suite unique identifier.</param>
 /// <param name="includeExecutionStatus">if set to <c>true</c> [include execution status].</param>
 /// <returns>
 /// list of all test cases in the list
 /// </returns>
 public static List<TestCase> GetAllTestCaseFromSuite(ITestPlan testPlan, int suiteId, bool includeExecutionStatus = true)
 {
     List<TestCase> testCases = new List<TestCase>();
     testPlan.Refresh();
     ITestSuiteBase currentSuite = testPlan.Project.TestSuites.Find(suiteId);
     currentSuite.Refresh();
     foreach (var currentTestCase in currentSuite.TestCases)
     {
         TestCase testCaseToAdd = new TestCase(currentTestCase.TestCase, currentSuite, testPlan, includeExecutionStatus);
         if (!testCases.Contains(testCaseToAdd))
         {
             testCases.Add(testCaseToAdd);
         }
     }
     log.InfoFormat("Load all test cases in the suite with Title= \"{0}\" id = \"{1}\"", currentSuite.Title, currentSuite.Id);
     return testCases;
 }
コード例 #8
0
 /// <summary>
 /// Retrieves all the test cases in a given test plan
 /// </summary>
 /// <param name="testPlan">The test plan with test cases we wish to retrieve</param>
 /// <returns>a list of type ITestCase containing all test cases in testPlan</returns>
 private static List<ITestCase> GetTestCases(ITestPlan testPlan)
 {
     List<ITestCase> testCases = new List<ITestCase>();
     testPlan.Refresh();
     Trace.WriteLine("\nGetting all Test Cases in Test Plan \"" + testPlan.Name + " (" + testPlan.Id + ")\"...\n\t");
     int i = 1;
     int numTestCases = testPlan.RootSuite.AllTestCases.Count;
     using (var progress = new ProgressBar())
     {
         foreach (ITestCase x in testPlan.RootSuite.AllTestCases)
         {
             progress.Report((double)i / numTestCases);
             testCases.Add(x);
             i++; 
         }
     }
     return testCases;
 }