Exemplo n.º 1
0
        public List <TestCaseConflict> CreateTestSuites(List <ITestSuite> testSuites, ITestManagementTeamProject selectedProject, IStaticTestSuite staticTestSuite = null, bool throwExceptionIfTestCaseConflicts = true)
        {
            List <TestCaseConflict> result = new List <TestCaseConflict>();

            ITestSuiteEntryCollection suitcollection = staticTestSuite.Entries;

            foreach (TestSuite testSuite in testSuites)
            {
                if (string.IsNullOrEmpty(testSuite.Name))
                {
                    this.CreateTestSuites(testSuite.TestSuites, selectedProject, staticTestSuite, throwExceptionIfTestCaseConflicts);
                }
                else
                {
                    ITestSuiteEntry  obj      = (from o in suitcollection where string.Compare(o.Title, testSuite.Name, true) == 0 select o).FirstOrDefault() as ITestSuiteEntry;
                    IStaticTestSuite newSuite = (IStaticTestSuite)obj.TestSuite;

                    if (newSuite == null)
                    {
                        newSuite             = selectedProject.TestSuites.CreateStatic();
                        newSuite.Title       = testSuite.Name;
                        newSuite.Description = testSuite.Description;

                        suitcollection.Add(newSuite);
                    }

                    result.AddRange(this.CreateTestSuites(testSuite.TestSuites, selectedProject, newSuite, throwExceptionIfTestCaseConflicts));

                    result.AddRange(this.CreateTestCases(selectedProject, testSuite, newSuite, throwExceptionIfTestCaseConflicts));
                }
            }

            return(result);
        }
Exemplo n.º 2
0
 public void UpdateQueryConditions(ITestPlan testPlan, string testSuiteName, string replaced, string replacing)
 {
     if (string.IsNullOrWhiteSpace(testSuiteName))
     {
         List <IDynamicTestSuite>  dynamicTestSuites = new List <IDynamicTestSuite>();
         ITestSuiteEntryCollection suiteCollection   = testPlan.RootSuite.Entries;
         GetAllQueryBasedTestSuiteFromSuiteNode(suiteCollection, dynamicTestSuites);
         foreach (IDynamicTestSuite dynamicTestSuite in dynamicTestSuites)
         {
             UpdateQueryConditionsToSuite(dynamicTestSuite, replaced, replacing);
         }
     }
     else
     {
         ITestSuiteBase testSuite = GetSuites(testPlan.Name, testSuiteName)
                                    .FirstOrDefault(
             s =>
             s.TestSuiteType.Equals(TestSuiteType.DynamicTestSuite));
         if (testSuite == null)
         {
             throw new TestObjectNotFoundException(string.Format("Query based test suite - {0} not found", testSuiteName));
         }
         var dynamicTestSuite = testSuite as IDynamicTestSuite;
         UpdateQueryConditionsToSuite(dynamicTestSuite, replaced, replacing);
     }
 }
Exemplo n.º 3
0
        //Drill down and Copy all subTest suites from source root test suite to destination plan's root test suites.
        private void CopySubTestSuites(IStaticTestSuite parentsourceSuite, IStaticTestSuite parentdestinationSuite)
        {
            ITestSuiteEntryCollection suitcollection = parentsourceSuite.Entries;

            foreach (ITestSuiteEntry suite_entry in suitcollection)
            {
                IStaticTestSuite suite = suite_entry.TestSuite as IStaticTestSuite;
                if (suite != null)
                {
                    IStaticTestSuite subSuite;
                    subSuite = destinationproj.TestSuites.CreateStatic();


                    subSuite.Title = suite.Title;
                    parentdestinationSuite.Entries.Add(subSuite);

                    CopyTestCases(suite, subSuite);

                    if (suite.Entries.Count > 0)
                    {
                        CopySubTestSuites(suite, subSuite);
                    }
                }
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            string serverUrl = "http://tfs2013:8080/tfs/defaultcollection";
            string project   = "MyProject";

            TfsTeamProjectCollection   tfs  = new TfsTeamProjectCollection(new Uri(serverUrl));
            ITestManagementService     tms  = tfs.GetService <ITestManagementService>();
            ITestManagementTeamProject proj = tms.GetTeamProject(project);

            // List all Test Plans
            foreach (ITestPlan p in proj.TestPlans.Query("Select * From TestPlan"))
            {
                Console.WriteLine("------------------------------------------------");

                Console.WriteLine("Test Plan - {0} : {1}", p.Id, p.Name);
                Console.WriteLine("------------------------------------------------");

                foreach (ITestSuiteBase suite in p.RootSuite.SubSuites)
                {
                    Console.WriteLine("\tTest Suite: {0}", suite.Title);

                    IStaticTestSuite          staticSuite = suite as IStaticTestSuite;
                    ITestSuiteEntryCollection suiteentrys = suite.TestCases;

                    foreach (ITestSuiteEntry testcase in suiteentrys)
                    {
                        Console.WriteLine("\t\tTest Case - {0} : {1}", testcase.Id, testcase.Title);
                    }
                    Console.WriteLine("");
                }

                Console.WriteLine("");
            }
        }
Exemplo n.º 5
0
        //Drill down and Copy all subTest suites from source root test suite to destination plan's root test suites.
        private void CopySubTestSuites(IStaticTestSuite parentsourceSuite, IStaticTestSuite parentdestinationSuite)
        {
            ITestSuiteEntryCollection suitcollection = parentsourceSuite.Entries;

            foreach (ITestSuiteEntry suite_entry in suitcollection)
            {
                IStaticTestSuite suite = suite_entry.TestSuite as IStaticTestSuite;
                if (suite != null)
                {
                    IStaticTestSuite subSuite = destinationproj.TestSuites.CreateStatic();
                    subSuite.Title = suite.Title;
                    parentdestinationSuite.Entries.Add(subSuite);

                    CopyTestCases(suite, subSuite);

                    if (suite.Entries.Count > 0)
                    {
                        CopySubTestSuites(suite, subSuite);
                    }
                }
                else if (suite_entry.TestSuite != null)
                {
                    logger.Info("RK: subtestsuite " + suite.Title + " from parent " + parentsourceSuite.Title + " is not a static suite");
                }
            }
        }
Exemplo n.º 6
0
        //Copy all Test suites from source plan to destination plan.
        private void CopyTestSuites(ITestPlan sourceplan, ITestPlan destinationplan)
        {
            ITestSuiteEntryCollection suites = sourceplan.RootSuite.Entries;

            CopyTestCases(sourceplan.RootSuite, destinationplan.RootSuite);

            foreach (ITestSuiteEntry suite_entry in suites)
            {
                IStaticTestSuite suite = suite_entry.TestSuite as IStaticTestSuite;
                if (suite != null)
                {
                    IStaticTestSuite newSuite = destinationproj.TestSuites.CreateStatic();
                    newSuite.Title = suite.Title;
                    //foreach (var tpoint in newSuite.TestSuiteEntry.PointAssignments)
                    //{
                    //    tpoint.AssignedTo = UserID;
                    //}
                    destinationplan.RootSuite.Entries.Add(newSuite);
                    destinationplan.Save();
                    CopyTestCases(suite, newSuite);
                    if (suite.Entries.Count > 0)
                    {
                        CopySubTestSuites(suite, newSuite);
                    }
                }
            }
        }
Exemplo n.º 7
0
        //Copy all Test suites from source plan to destination plan.
        private void CopyTestSuites(ITestPlan sourceplan, ITestPlan destinationplan)
        {
            ITestSuiteEntryCollection suites = sourceplan.RootSuite.Entries;

            logger.Info("RK: found " + suites.Count + " in test plan " + sourceplan.Name);

            CopyTestCases(sourceplan.RootSuite, destinationplan.RootSuite);

            foreach (ITestSuiteEntry suite_entry in suites)
            {
                IStaticTestSuite suite = suite_entry.TestSuite as IStaticTestSuite;
                if (suite != null)
                {
                    IStaticTestSuite newSuite = destinationproj.TestSuites.CreateStatic();
                    newSuite.Title = suite.Title;
                    destinationplan.RootSuite.Entries.Add(newSuite);
                    destinationplan.Save();

                    CopyTestCases(suite, newSuite);
                    if (suite.Entries.Count > 0)
                    {
                        CopySubTestSuites(suite, newSuite);
                    }
                }
                else if (suite_entry.TestSuite != null)
                {
                    logger.Info("RK: suite entry is not static suite " + suite_entry.Title);
                }
            }
        }
Exemplo n.º 8
0
 private void Get_TestSuites(ITestSuiteEntryCollection Suites)
 {
     foreach (ITestSuiteEntry suite_entry in Suites)
     {
         this.suite = suite_entry;
         IStaticTestSuite newSuite = suite_entry.TestSuite as IStaticTestSuite;
         comBoxTestSuite.Items.Add(newSuite.Title);
     }
 }
Exemplo n.º 9
0
        //Copy all subTest suites from source root test suite to destination plan's root test suites.
        private void CopyTestCases(IStaticTestSuite sourcesuite, IStaticTestSuite destinationsuite)
        {
            ITestSuiteEntryCollection suiteentrys = sourcesuite.TestCases;

            foreach (ITestSuiteEntry testcase in suiteentrys)
            {
                try
                {   //check whether testcase exists in new work items(closed work items may not be created again).
                    if (!workItemMap.ContainsKey(testcase.TestCase.WorkItem.Id))
                    {
                        logger.Info("RK: could not find test case with id " + testcase.TestCase.WorkItem.Id);
                        continue;
                    }

                    int       newWorkItemID = (int)workItemMap[testcase.TestCase.WorkItem.Id];
                    ITestCase tc            = destinationproj.TestCases.Find(newWorkItemID);
                    destinationsuite.Entries.Add(tc);

                    bool updateTestCase = false;
                    TestActionCollection testActionCollection = tc.Actions;
                    foreach (var item in testActionCollection)
                    {
                        var sharedStepRef = item as ISharedStepReference;
                        if (sharedStepRef != null)
                        {
                            int newSharedStepId = (int)workItemMap[sharedStepRef.SharedStepId];
                            //GetNewSharedStepId(testCase.Id, sharedStepRef.SharedStepId);
                            if (0 != newSharedStepId)
                            {
                                sharedStepRef.SharedStepId = newSharedStepId;
                                updateTestCase             = true;
                            }
                            else
                            {
                                logger.Info("RK: could not find new shared step for " + sharedStepRef.SharedStepId);
                            }
                        }
                    }
                    if (updateTestCase)
                    {
                        logger.InfoFormat("Test case with Id: {0} updated", tc.Id);
                        tc.Save();
                    }
                    else
                    {
                        logger.Info("RK: Test case " + tc.Id + " saved.");
                        tc.Save();
                    }
                }
                catch (Exception)
                {
                    logger.Info("Error retrieving Test case  " + testcase.TestCase.WorkItem.Id + ": " + testcase.Title);
                }
            }
        }
Exemplo n.º 10
0
        public static IOrderedEnumerable <TestCase> getTestCases(TestSuite testSuite)
        {
            ITestSuiteEntryCollection testSuiteEntries = testSuite.TFSTestSuiteBase.TestCases;

            TestCase[] testCases = new TestCase[testSuiteEntries.Count];

            for (int i = 0; i < testSuiteEntries.Count; i++)
            {
                testCases[i] = new TestCase(testSuiteEntries[i]);
            }

            return(testCases.OrderBy(tc => tc.TFSTestSuiteEntry.Title));
        }
Exemplo n.º 11
0
        //Following method is invoked whenever a Test Plan is selected in the dropdown list.
        //Acording to the selected Test Plan in the dropdown list the Test Suites present in the selected Test Plan are populated in the Test Suite selection dropdown.
        private void comBoxTestPlan_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            comBoxTestSuite.Items.Clear();
            int i = -1;

            if (comBoxTestPlan.SelectedIndex >= 0)
            {
                i = comBoxTestPlan.SelectedIndex;
                this.testSuites = plans[i].RootSuite.Entries;
                Get_TestSuites(testSuites);
                this.Cursor = Cursors.Arrow;
                flag2       = 1;
            }
        }
Exemplo n.º 12
0
        void GetTestCases(IStaticTestSuite suite, TreeViewItem tree_item)
        {
            //AllTestCases - Will show all the Test Cases under that Suite even in sub suites.
            //ITestCaseCollection testcases = suite.AllTestCases;

            //Will bring only the Test Case under a specific Test Suite.
            ITestSuiteEntryCollection suiteentrys = suite.TestCases;

            foreach (ITestSuiteEntry testcase in suiteentrys)
            {
                TreeViewItem test = new TreeViewItem();
                test.Header = ImageHelpers.CreateHeader(testcase.Title, ItemTypes.TestCase);
                tree_item.Items.Add(test);
            }
        }
Exemplo n.º 13
0
        //Copy all subTest suites from source root test suite to destination plan's root test suites.
        private void CopyTestCases(IStaticTestSuite sourcesuite, IStaticTestSuite destinationsuite)
        {
            ITestSuiteEntryCollection suiteentrys = sourcesuite.TestCases;

            destinationsuite.Entries.RemoveCases(destinationsuite.Entries.OfType <ITestCase>());

            foreach (ITestSuiteEntry testcase in suiteentrys)
            {
                try
                {   //check whether testcase exists in new work items(closed work items may not be created again).
                    if (!WorkItemIdMap.Contains(testcase.TestCase.WorkItem.Id))
                    {
                        continue;
                    }

                    int       newWorkItemID = WorkItemIdMap[testcase.TestCase.WorkItem.Id];
                    ITestCase tc            = destinationproj.TestCases.Find(newWorkItemID);
                    destinationsuite.Entries.Add(tc);

                    bool updateTestCase = false;
                    TestActionCollection testActionCollection = tc.Actions;
                    foreach (var item in testActionCollection)
                    {
                        var sharedStepRef = item as ISharedStepReference;
                        if (sharedStepRef != null)
                        {
                            int newSharedStepId = (int)WorkItemIdMap[sharedStepRef.SharedStepId];
                            //GetNewSharedStepId(testCase.Id, sharedStepRef.SharedStepId);
                            if (0 != newSharedStepId)
                            {
                                sharedStepRef.SharedStepId = newSharedStepId;
                                updateTestCase             = true;
                            }
                        }
                    }
                    if (updateTestCase)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Test case with Id: {0} updated", tc.Id);
                        tc.Save();
                    }
                }
                catch (Exception)
                {
                    logger.Info("Error retrieving Test case  " + testcase.TestCase.WorkItem.Id + ": " + testcase.Title);
                }
            }
        }
Exemplo n.º 14
0
        //Copy all subTest suites from source root test suite to destination plan's root test suites.
        private void CopyTestCases(IStaticTestSuite sourcesuite, IStaticTestSuite destinationsuite)
        {
            ITestSuiteEntryCollection suiteentrys = sourcesuite.TestCases;

            foreach (ITestSuiteEntry testcase in suiteentrys)
            {
                try
                {   //check whether testcase exists in new work items(closed work items may not be created again).
                    if (!WorkItemMap.ContainsKey(testcase.TestCase.WorkItem.Id))
                    {
                        continue;
                    }

                    int       newWorkItemID = (int)WorkItemMap[testcase.TestCase.WorkItem.Id];
                    ITestCase tc            = targetTestMgmtProj.TestCases.Find(newWorkItemID);
                    destinationsuite.Entries.Add(tc);

                    bool updateTestCase = false;
                    TestActionCollection testActionCollection = tc.Actions;
                    foreach (var item in testActionCollection)
                    {
                        if (item is ISharedStepReference sharedStepRef)
                        {
                            int newSharedStepId = (int)WorkItemMap[sharedStepRef.SharedStepId];
                            //GetNewSharedStepId(testCase.Id, sharedStepRef.SharedStepId);
                            if (0 != newSharedStepId)
                            {
                                sharedStepRef.SharedStepId = newSharedStepId;
                                updateTestCase             = true;
                            }
                        }
                    }
                    if (updateTestCase)
                    {
                        Console.WriteLine();
                        Console.WriteLine($"Test case with Id: {tc.Id} updated");
                        tc.Save();
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine($"Error retrieving Test case {testcase.TestCase.WorkItem.Id}: {testcase.Title}");
                }
            }
        }
        private void GetPlanSuites(ITestSuiteEntryCollection suites, TreeViewItem tree_item)
        {
            foreach (ITestSuiteEntry suite_entry in suites)
            {
                IStaticTestSuite suite = suite_entry.TestSuite as IStaticTestSuite;
                if (suite != null)
                {
                    TreeViewItem suite_tree = new TreeViewItem();
                    suite_tree.Header = ImageHelpers.CreateHeader(suite.Title, ItemTypes.TestSuite);

                    GetTestCases(suite, suite_tree);

                    tree_item.Items.Add(suite_tree);

                    if (suite.Entries.Count > 0)
                        GetPlanSuites(suite.Entries, suite_tree);
                }
            }
        }
Exemplo n.º 16
0
        //Copy all Test suites from source plan to destination plan.
        private void CopyTestSuites(ITestPlan sourceplan, ITestPlan destinationplan)
        {
            ITestSuiteEntryCollection suites = sourceplan.RootSuite.Entries;

            CopyTestCases(sourceplan.RootSuite, destinationplan.RootSuite);

            foreach (ITestSuiteEntry suite_entry in suites)
            {
                if (suite_entry.TestSuite is IStaticTestSuite suite)
                {
                    IStaticTestSuite newSuite = targetTestMgmtProj.TestSuites.CreateStatic();
                    newSuite.Title = suite.Title;
                    destinationplan.RootSuite.Entries.Add(newSuite);
                    destinationplan.Save();

                    CopyTestCases(suite, newSuite);
                    if (suite.Entries.Count > 0)
                    {
                        CopySubTestSuites(suite, newSuite);
                    }
                }
                else
                {
                    if (suite_entry.TestSuite is IDynamicTestSuite dynamicSuite)
                    {
                        IDynamicTestSuite newDynamicSuit = targetTestMgmtProj.TestSuites.CreateDynamic();
                        newDynamicSuit.Title = dynamicSuite.Title;
                        //newDynamicSuit.Query = dynamicSuite.Query;

                        var text = ReplaceAreaPath(dynamicSuite.Query.QueryText);
                        text = ReplaceIterationPath(text);

                        var newQuery = targetTestMgmtProj.CreateTestQuery(text);

                        newDynamicSuit.Query = newQuery;

                        destinationplan.RootSuite.Entries.Add(newDynamicSuit);
                        destinationplan.Save();
                    }
                }
            }
        }
Exemplo n.º 17
0
        void GetPlanSuites(ITestSuiteEntryCollection suites, TreeViewItem tree_item)
        {
            foreach (ITestSuiteEntry suite_entry in suites)
            {
                IStaticTestSuite suite = suite_entry.TestSuite as IStaticTestSuite;
                if (suite != null)
                {
                    TreeViewItem suite_tree = new TreeViewItem();
                    suite_tree.Header = ImageHelpers.CreateHeader(suite.Title, ItemTypes.TestSuite);

                    GetTestCases(suite, suite_tree);

                    tree_item.Items.Add(suite_tree);

                    if (suite.Entries.Count > 0)
                    {
                        GetPlanSuites(suite.Entries, suite_tree);
                    }
                }
            }
        }
Exemplo n.º 18
0
        private static List <TestSuite> GetPlanSuites(ITestSuiteEntryCollection suites, int parentSuiteId = -1)
        {
            List <TestSuite> Suites = new List <TestSuite>();

            foreach (ITestSuiteEntry suite_entry in suites)
            {
                var _newSuite = new TestSuite();
                _newSuite.SuiteName   = suite_entry.Title;
                _newSuite.SuiteId     = suite_entry.Id;
                _newSuite.ParentSuite = parentSuiteId;

                IStaticTestSuite suite = suite_entry.TestSuite as IStaticTestSuite;
                if (suite != null)
                {
                    _newSuite.TotalTests = suite.AllTestCases.Count;
                    int AutomatedTests = 0;
                    foreach (var test in suite.AllTestCases)
                    {
                        var Fields = test.CustomFields;
                        if (Fields["Automation status"].Value.ToString().Equals("Automated", StringComparison.CurrentCultureIgnoreCase))
                        {
                            AutomatedTests++;
                        }
                    }
                    _newSuite.TotalAutomatedTests = AutomatedTests;

                    Suites.Add(_newSuite);

                    if (suite.Entries.Count > 0)
                    {
                        var subSuites = GetPlanSuites(suite.Entries, _newSuite.SuiteId);
                        foreach (var subSuiteEntry in subSuites)
                        {
                            Suites.Add(subSuiteEntry);
                        }
                    }
                }
            }
            return(Suites);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Проходит по всем тестовым ситуациям тестового плана и заполняет Excel таблицу,
        /// указывая подзаголовком категорию теста - наименования тестовой ситуации.
        /// </summary>
        private void ByTestSuites()
        {
            try
            {
                this.plans = teamProject.TestPlans.Query("Select * From TestPlan");
                foreach (ITestPlan plan in plans)
                {
                    if (plan.Name == testPlanName)
                    {
                        this.testSuites = plan.RootSuite.Entries;
                    }
                }
                foreach (ITestSuiteEntry suite_entry in testSuites)
                {
                    this.suite = suite_entry;
                    IStaticTestSuite newSuite = suite_entry.TestSuite as IStaticTestSuite;
                    if (newSuite != null)
                    {
                        xlWorkSheet.get_Range("a" + row, "d" + row).Merge(true);
                        xlWorkSheet.Cells[row, 1]                     = newSuite.Title;
                        xlWorkSheet.Cells[row, 1].Font.Bold           = true;
                        xlWorkSheet.Cells[row, 1].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;

                        row = row + 1;
                        ITestCaseCollection cases = newSuite.AllTestCases;
                        ByTestCases(cases);
                    }
                    else
                    {
                        ITestCase test = suite_entry.TestCase as ITestCase;
                        if (test != null)
                        {
                            ByTest(test);
                        }
                    }
                }
            }
            catch { }
        }
Exemplo n.º 20
0
 private void GetAllQueryBasedTestSuiteFromSuiteNode(ITestSuiteEntryCollection suiteCollection, List <IDynamicTestSuite> dynamicTestSuites)
 {
     foreach (var suiteEntry in suiteCollection)
     {
         if (suiteEntry.TestSuite != null)
         {
             if (suiteEntry.TestSuite.TestSuiteType == TestSuiteType.DynamicTestSuite)
             {
                 IDynamicTestSuite suite = suiteEntry.TestSuite as IDynamicTestSuite;
                 dynamicTestSuites.Add(suite);
             }
             else if (suiteEntry.TestSuite.TestSuiteType == TestSuiteType.StaticTestSuite)
             {
                 IStaticTestSuite parentStaticSuite = suiteEntry.TestSuite as IStaticTestSuite;
                 if (parentStaticSuite != null)
                 {
                     GetAllQueryBasedTestSuiteFromSuiteNode(parentStaticSuite.Entries, dynamicTestSuites);
                 }
             }
         }
     }
 }
Exemplo n.º 21
0
        //Copy all Test suites from source plan to destination plan.
        private void CopyTestSuites(ITestPlan sourceplan, ITestPlan destinationplan)
        {
            ITestSuiteEntryCollection suites = sourceplan.RootSuite.Entries;

            CopyTestCases(sourceplan.RootSuite, destinationplan.RootSuite);

            foreach (ITestSuiteEntry suite_entry in suites)
            {
                IStaticTestSuite suite = suite_entry.TestSuite as IStaticTestSuite;
                if (suite != null)
                {
                    IStaticTestSuite newSuite = null;
                    if (WorkItemIdMap.Contains(suite.Id))
                    {
                        var newId = WorkItemIdMap[suite.Id];
                        newSuite = (IStaticTestSuite)destinationproj.TestSuites.Find(newId);
                    }

                    if (newSuite == null)
                    {
                        newSuite       = destinationproj.TestSuites.CreateStatic();
                        newSuite.Title = suite.Title;

                        destinationplan.RootSuite.Entries.Add(newSuite);
                        destinationplan.Save();

                        WorkItemIdMap.Map(suite.Id, newSuite.Id);
                    }

                    CopyTestCases(suite, newSuite);
                    if (suite.Entries.Count > 0)
                    {
                        CopySubTestSuites(suite, newSuite);
                    }
                }
            }
        }
Exemplo n.º 22
0
        //Drill down and Copy all subTest suites from source root test suite to destination plan's root test suites.
        private void CopySubTestSuites(IStaticTestSuite parentsourceSuite, IStaticTestSuite parentdestinationSuite)
        {
            ITestSuiteEntryCollection suitcollection = parentsourceSuite.Entries;

            foreach (ITestSuiteEntry suite_entry in suitcollection)
            {
                if (suite_entry.TestSuite is IStaticTestSuite suite)
                {
                    IStaticTestSuite subSuite = targetTestMgmtProj.TestSuites.CreateStatic();
                    subSuite.Title = suite.Title;
                    parentdestinationSuite.Entries.Add(subSuite);

                    CopyTestCases(suite, subSuite);

                    if (suite.Entries.Count > 0)
                    {
                        CopySubTestSuites(suite, subSuite);
                    }
                }
                else
                {
                    if (suite_entry.TestSuite is IDynamicTestSuite dynamicSuite)
                    {
                        IDynamicTestSuite newDynamicSuit = targetTestMgmtProj.TestSuites.CreateDynamic();
                        newDynamicSuit.Title = dynamicSuite.Title;

                        var text = ReplaceAreaPath(dynamicSuite.Query.QueryText);
                        text = ReplaceIterationPath(text);

                        var newQuery = targetTestMgmtProj.CreateTestQuery(text);

                        newDynamicSuit.Query = newQuery;
                    }
                }
            }
        }
Exemplo n.º 23
0
        //Copy all Test suites from source plan to destination plan.
        private void CopyTestSuites(ITestPlan sourceplan, ITestPlan destinationplan)
        {
            ITestSuiteEntryCollection suites = sourceplan.RootSuite.Entries;

            CopyTestCases(sourceplan.RootSuite, destinationplan.RootSuite);

            foreach (ITestSuiteEntry suite_entry in suites)
            {
                IStaticTestSuite suite = suite_entry.TestSuite as IStaticTestSuite;
                if (suite != null)
                {
                    IStaticTestSuite newSuite = destinationproj.TestSuites.CreateStatic();
                    newSuite.Title = suite.Title;
                    destinationplan.RootSuite.Entries.Add(newSuite);
                    destinationplan.Save();

                    CopyTestCases(suite, newSuite);
                    if (suite.Entries.Count > 0)
                    {
                        CopySubTestSuites(suite, newSuite);
                    }
                }
            }
        }
Exemplo n.º 24
0
        //Copy all subTest suites from source root test suite to destination plan's root test suites.
        private void CopyTestCases(IStaticTestSuite sourcesuite, IStaticTestSuite destinationsuite)
        {
            ITestSuiteEntryCollection suiteentrys = sourcesuite.TestCases;

            foreach (ITestSuiteEntry testcase in suiteentrys)
            {
                try
                {   //check whether testcase exists in new work items(closed work items may not be created again).
                    WorkItem  newWorkItem = null;
                    Hashtable fieldMap    = ListToTable((List <object>)workItemMap[testcase.TestCase.WorkItem.Type.Name]);
                    newWorkItem = new WorkItem(workItemTypes["Test Case"]);
                    foreach (Field field in testcase.TestCase.WorkItem.Fields)
                    {
                        if (field.Name.Contains("ID") || field.Name.Contains("Reason"))
                        {
                            continue;
                        }
                        if (field.Name == "Assigned To" || field.Name == "Activated By")
                        {
                            testcase.TestCase.WorkItem.Open();
                            testcase.TestCase.WorkItem.Fields[field.Name].Value = "*****@*****.**";
                        }
                        if (newWorkItem.Fields.Contains(field.Name) && newWorkItem.Fields[field.Name].IsEditable)
                        {
                            newWorkItem.Fields[field.Name].Value = field.Value;
                            if (field.Name == "Iteration Path" || field.Name == "Area Path" || field.Name == "Node Name" || field.Name == "Team Project")
                            {
                                try
                                {
                                    string itPath    = (string)field.Value;
                                    int    length    = sourceproj.TeamProjectName.Length;
                                    string itPathNew = destinationproj.TeamProjectName + itPath.Substring(length);
                                    newWorkItem.Fields[field.Name].Value = itPathNew;
                                }
                                catch (Exception)
                                {
                                }
                            }
                        }
                        //Add values to mapped fields
                        else if (fieldMap.ContainsKey(field.Name))
                        {
                            try
                            {
                                newWorkItem.Fields[(string)fieldMap[field.Name]].Value = field.Value;
                            }
                            catch (Exception ex)
                            {
                                continue;
                            }
                        }
                    }
                    ArrayList array = newWorkItem.Validate();
                    foreach (Field item in array)
                    {
                        logger.Info(String.Format("Work item {0} Validation Error in field: {1}  : {2}", item.Name, newWorkItem.Fields[item.Name].Value));
                    }
                    if (array.Count == 0)
                    {
                        SaveAttachments(testcase.TestCase.WorkItem);
                        UploadAttachments(newWorkItem, testcase.TestCase.WorkItem);
                        newWorkItem.Save();
                        ITestCase tc = destinationproj.TestCases.Find(newWorkItem.Id);
                        destinationsuite.Entries.Add(tc);
                        TestActionCollection testActionCollection = testcase.TestCase.Actions;
                        foreach (var item in testActionCollection)
                        {
                            item.CopyToNewOwner(tc);
                        }
                        tc.Save();
                    }
                }
                catch (Exception ex)
                {
                    logger.Info("Error retrieving Test case  " + testcase.TestCase.WorkItem.Id + ": " + testcase.Title + ex.Message);
                }
            }
        }
Exemplo n.º 25
0
        private List <TestCaseConflict> CreateTestCases(ITestManagementTeamProject selectedProject, TestSuite testSuite, IStaticTestSuite newSuite, bool throwExceptionIfTestCaseConflicts)
        {
            List <TestCaseConflict> result = new List <TestCaseConflict>();

            ITestSuiteEntryCollection suitcollection = newSuite.Entries;

            foreach (ITestCase testCase in testSuite.TestCases)
            {
                ITestSuiteEntry obj = (from o in suitcollection where string.Compare(o.Title, testCase.Name, true) == 0 select o).FirstOrDefault() as ITestSuiteEntry;
                Microsoft.TeamFoundation.TestManagement.Client.ITestCase newTestCase = obj.TestCase;

                if (newTestCase == null)
                {
                    newTestCase             = selectedProject.TestCases.Create();
                    newTestCase.Title       = testCase.Name;
                    newTestCase.Description = "<p><strong>Summary</strong></p>" + testCase.Description + "<p><strong>Pre Conditions</strong></p>" + testCase.PreConditions;
                    var link = new Hyperlink(testCase.LinkInTestLink);
                    newTestCase.Links.Add(link);
                    newTestCase.Priority = testCase.Importance;
                    newTestCase.CustomFields["Assigned To"].Value = string.Empty;

                    LoadTestSteps(testCase, newTestCase);

                    newTestCase.Save();

                    suitcollection.Add(newTestCase);
                }
                else
                {
                    if (newTestCase.Actions.Count != testCase.Steps.Count)
                    {
                        TestCaseConflict tcc = new TestCaseConflict();
                        tcc.Message     = testCase.Name + " (-:-) already exists and has a different step count" + Environment.NewLine + "(" + testCase.LinkInTestLink + ")";
                        tcc.TestCase    = testCase;
                        tcc.TfsTestCase = newTestCase;
                        if (throwExceptionIfTestCaseConflicts)
                        {
                            throw new TestCaseConflictException(tcc);
                        }
                        result.Add(tcc);
                    }
                    else
                    {
                        string differntFields = string.Empty;
                        for (int pos = 0; pos < testCase.Steps.Count; pos++)
                        {
                            if (HtmlRemovalUtility.StripTagsCharArrayWithExtraParsing(((ITestStep)newTestCase.Actions[pos]).Description) != HtmlRemovalUtility.StripTagsCharArrayWithExtraParsing(testCase.Steps[pos].Actions))
                            {
                                differntFields += "\t[" + pos + "] Description : " + testCase.Steps[pos].Actions + Environment.NewLine;
                            }
                            if (HtmlRemovalUtility.StripTagsCharArrayWithExtraParsing(((ITestStep)newTestCase.Actions[pos]).ExpectedResult) != HtmlRemovalUtility.StripTagsCharArrayWithExtraParsing(testCase.Steps[pos].ExpectedResults))
                            {
                                differntFields += "\t[" + pos + "] ExpectedResults : " + testCase.Steps[pos].ExpectedResults + Environment.NewLine;
                            }
                        }
                        if (differntFields.Length > 0)
                        {
                            TestCaseConflict tcc = new TestCaseConflict();
                            tcc.Message     = testCase.Name + " (-:-) already exists and is different" + Environment.NewLine + "(" + testCase.LinkInTestLink + ")" + Environment.NewLine + differntFields;
                            tcc.TestCase    = testCase;
                            tcc.TfsTestCase = newTestCase;
                            if (throwExceptionIfTestCaseConflicts)
                            {
                                throw new TestCaseConflictException(tcc);
                            }
                            result.Add(tcc);
                        }
                    }
                }
            }

            return(result);
        }