Exemplo n.º 1
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.º 2
0
        private void SaveNewTestSuitToPlan(ITestPlan testPlan, IStaticTestSuite parent, ITestSuiteBase newTestSuite)
        {
            Trace.WriteLine(
                $"       Saving {newTestSuite.TestSuiteType} : {newTestSuite.Id} - {newTestSuite.Title} ", "TestPlansAndSuites");
            try
            {
                ((IStaticTestSuite)parent).Entries.Add(newTestSuite);
            }
            catch (TestManagementServerException ex)
            {
                Telemetry.Current.TrackException(ex,
                                                 new Dictionary <string, string> {
                    { "Name", Name },
                    { "Target Project", me.Target.Name },
                    { "Target Collection", me.Target.Collection.Name },
                    { "Source Project", me.Source.Name },
                    { "Source Collection", me.Source.Collection.Name },
                    { "Status", Status.ToString() },
                    { "Task", "SaveNewTestSuitToPlan" },
                    { "Id", newTestSuite.Id.ToString() },
                    { "Title", newTestSuite.Title },
                    { "TestSuiteType", newTestSuite.TestSuiteType.ToString() }
                });
                Trace.WriteLine(string.Format("       FAILED {0} : {1} - {2} | {3}", newTestSuite.TestSuiteType.ToString(), newTestSuite.Id, newTestSuite.Title, ex.Message), "TestPlansAndSuites");
                ITestSuiteBase ErrorSuitChild = targetTestStore.Project.TestSuites.CreateStatic();
                ErrorSuitChild.TestSuiteEntry.Title = string.Format(@"BROKEN: {0} | {1}", newTestSuite.Title, ex.Message);
                ((IStaticTestSuite)parent).Entries.Add(ErrorSuitChild);
            }

            testPlan.Save();
        }
Exemplo n.º 3
0
 public void AddTestCasesToSuite(IEnumerable <ITestCase> testCases, ITestSuiteBase destinationSuite)
 {
     if (destinationSuite.TestSuiteType == TestSuiteType.StaticTestSuite)
     {
         IStaticTestSuite staticTestSuite = destinationSuite as IStaticTestSuite;
         if (staticTestSuite != null)
         {
             staticTestSuite.Entries.AddCases(testCases);
         }
     }
     else if (destinationSuite.TestSuiteType == TestSuiteType.RequirementTestSuite)
     {
         IRequirementTestSuite requirementTestSuite = destinationSuite as IRequirementTestSuite;
         if (requirementTestSuite != null)
         {
             WorkItemStore store          = requirementTestSuite.Project.WitProject.Store;
             WorkItem      tfsRequirement = store.GetWorkItem(requirementTestSuite.RequirementId);
             foreach (ITestCase testCase in testCases)
             {
                 tfsRequirement.Links.Add(new RelatedLink(store.WorkItemLinkTypes.LinkTypeEnds["Tested By"],
                                                          testCase.WorkItem.Id));
             }
             tfsRequirement.Save();
         }
     }
     destinationSuite.Plan.Save();
 }
Exemplo n.º 4
0
        /// <summary>
        ///     Recursively searches for a suite with given id and returns the suite
        /// </summary>
        /// <param name="rootsuite">The root suite to search</param>
        /// <param name="suiteid">Suite id to search for</param>
        /// <returns>Static suite which matches the suiteid within the rootsuite</returns>
        private static IStaticTestSuite FindSuitebySuiteId(IStaticTestSuite rootsuite, int suiteid)
        {
            foreach (ITestSuiteBase t in rootsuite.SubSuites)
            {
                if (!t.GetType().Name.Equals("StaticTestSuite"))
                {
                    continue;
                }
                var subsuite = (IStaticTestSuite)t;
                if (subsuite.Id.Equals(suiteid))
                {
                    return(subsuite);
                }

                if (subsuite.SubSuites.Count > 0)
                {
                    var retsuite = FindSuitebySuiteId(subsuite, suiteid);
                    if (retsuite != null)
                    {
                        return(retsuite);
                    }
                }
            }
            return(null);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Returns the list of all subsuites under the given suiteId
        /// </summary>
        /// <param name="suiteid"></param>
        /// <returns>List of all suiteids under the given suite</returns>
        private static string FindSuiteAndGetAllChildSuites(int suiteid)
        {
            var suitelist = suiteid.ToString() + "','";
            IStaticTestSuite selectedSuite = null;


            //Traverse the test suite tree to get the suite referenced by suiteId.

            foreach (var subsuite in _testPlan.RootSuite.SubSuites.Where(t => t.GetType().Name.Equals("StaticTestSuite")).Cast <IStaticTestSuite>())
            {
                if (subsuite.Id.Equals(suiteid))
                {
                    selectedSuite = subsuite;
                    suitelist     = GetChildSuiteIds(selectedSuite, suitelist);
                }
                if (subsuite.SubSuites.Count > 0)
                {
                    var retsuite = FindSuitebySuiteId(subsuite, suiteid);
                    if (retsuite != null)
                    {
                        selectedSuite = retsuite;
                        suitelist     = GetChildSuiteIds(selectedSuite, suitelist);
                    }
                }
            }


            return(suitelist);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Removes the test case internal.
 /// </summary>
 /// <param name="testCaseToRemove">The test case to be removed.</param>
 /// <param name="suitesToSearch">The suites which will be searched.</param>
 private static void RemoveTestCaseInternal(ITestCase testCaseToRemove, ITestSuiteCollection suitesToSearch)
 {
     foreach (ITestSuiteBase currentSuite in suitesToSearch)
     {
         if (currentSuite != null)
         {
             if (currentSuite is IRequirementTestSuite)
             {
                 IRequirementTestSuite suite = currentSuite as IRequirementTestSuite;
                 if (suite.TestCases.Where(x => x.Id.Equals(testCaseToRemove.Id)).ToList().Count == 0)
                 {
                     suite.TestCases.RemoveEntries(new List <ITestSuiteEntry>()
                     {
                         testCaseToRemove.TestSuiteEntry
                     });
                 }
             }
             else if (currentSuite is IStaticTestSuite)
             {
                 foreach (var currentTestCase in currentSuite.TestCases)
                 {
                     if (currentTestCase.Id.Equals(testCaseToRemove.Id))
                     {
                         ((IStaticTestSuite)currentSuite).Entries.Remove(testCaseToRemove);
                     }
                 }
                 IStaticTestSuite suite1 = currentSuite as IStaticTestSuite;
                 if (suite1 != null && (suite1.SubSuites.Count > 0))
                 {
                     RemoveTestCaseInternal(testCaseToRemove, suite1.SubSuites);
                 }
             }
         }
     }
 }
Exemplo n.º 7
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.º 8
0
        /// <summary>
        /// Copies test suites that are children of another test suite.
        /// </summary>
        /// <param name="parentSourceTestSuite">The parent source test suite.</param>
        /// <param name="parentDestinationTestSuite">The parent destination test suite.</param>
        private static string CopyTestSuites(IStaticTestSuite parentSourceTestSuite, IStaticTestSuite parentDestinationTestSuite)
        {
            string results = string.Empty;

            foreach (IStaticTestSuite sourceTestSuite in parentSourceTestSuite.SubSuites)
            {
                IStaticTestSuite destinationTestSuite = parentDestinationTestSuite.Project.TestSuites.CreateStatic();

                destinationTestSuite.Title = sourceTestSuite.Title;
                destinationTestSuite.SetDefaultConfigurations(GetDefaultConfigurationCollection(parentDestinationTestSuite.Project));
                parentDestinationTestSuite.Entries.Add(destinationTestSuite);

                parentDestinationTestSuite.Plan.Save();

                results = "Copying Test Suite: " + sourceTestSuite.Title + Environment.NewLine;

                results += CopyTestCases(sourceTestSuite, destinationTestSuite);

                if (sourceTestSuite.Entries.Count > 0)
                {
                    results += CopyTestSuites(sourceTestSuite, destinationTestSuite);
                }
            }
            return(results);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Returns all suites in current suite collection
        /// </summary>
        /// <param name="suites">The suites.</param>
        /// <returns>list of all suites</returns>
        private static List <ITestSuiteBase> GetAllTestSuites(ITestSuiteCollection suites)
        {
            List <ITestSuiteBase> testSuites = new List <ITestSuiteBase>();

            foreach (ITestSuiteBase currentSuite in suites)
            {
                if (currentSuite != null)
                {
                    currentSuite.Refresh();
                    if (!testSuites.Contains(currentSuite))
                    {
                        testSuites.Add(currentSuite);
                    }

                    if (currentSuite is IStaticTestSuite)
                    {
                        IStaticTestSuite suite1 = currentSuite as IStaticTestSuite;
                        if (suite1 != null && (suite1.SubSuites.Count > 0))
                        {
                            testSuites.AddRange(GetAllTestSuites(suite1.SubSuites));
                        }
                    }
                }
            }

            return(testSuites);
        }
Exemplo n.º 10
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.º 11
0
        /// <summary>
        /// Adds the child suite.
        /// </summary>
        /// <param name="parentSuiteId">The parent suite unique identifier.</param>
        /// <param name="title">The title.</param>
        /// <param name="canBeAdded">if set to <c>true</c> [can be added].</param>
        /// <returns>
        /// new suite unique identifier.
        /// </returns>
        public static int AddChildSuite(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, int parentSuiteId, string title, out bool canBeAdded)
        {
            ITestSuiteBase parentSuite = null;

            if (parentSuiteId != -1)
            {
                parentSuite = testManagementTeamProject.TestSuites.Find(parentSuiteId);
            }

            if (parentSuite is IRequirementTestSuite)
            {
                canBeAdded = false;
                return(0);
            }
            IStaticTestSuite staticSuite = testManagementTeamProject.TestSuites.CreateStatic();

            canBeAdded        = true;
            staticSuite.Title = title;

            if (parentSuite != null && parentSuite is IStaticTestSuite && parentSuiteId != -1)
            {
                IStaticTestSuite parentSuiteStatic = parentSuite as IStaticTestSuite;
                parentSuiteStatic.Entries.Add(staticSuite);
                log.InfoFormat("Add child suite to suite with Title= {0}, Id = {1}, child suite title= {2}", parentSuite.Title, parentSuite.Id, title);
            }
            else
            {
                testPlan.RootSuite.Entries.Add(staticSuite);
                log.InfoFormat("Add child suite with title= {0} to test plan", title);
            }
            testPlan.Save();

            return(staticSuite.Id);
        }
Exemplo n.º 12
0
        /// <summary>
        ///     Returns all the child suite ids under the selected suite. It will recurse if the child suite has children.
        /// </summary>
        /// <param name="suite">Root suite</param>
        /// <param name="suiteList">List of suiteids under this suite</param>
        /// <returns>List of child suite ids</returns>
        public static string GetChildSuiteIds(IStaticTestSuite suite, string suiteList)
        {
            suiteList = suiteList + suite.Id + "','";
            foreach (ITestSuiteBase t in suite.SubSuites)
            {
//need to check for suite type as static suites have children and others dont
                if (t.GetType().Name.Equals("StaticTestSuite"))
                {
                    var subsuite = (IStaticTestSuite)t;
                    if (subsuite.SubSuites.Count > 0)
                    {
                        suiteList = suiteList + subsuite.Id + "','";
                        suiteList = suiteList + GetChildSuiteIds(subsuite, suiteList);
                    }
                    else
                    {
                        suiteList = suiteList + subsuite.Id + "','";
                    }
                }
                else if (t.GetType().Name.Equals("DynamicTestSuite"))
                {
                    var dynsuite = (IDynamicTestSuite)t;

                    suiteList = suiteList + dynsuite.Id + "','";
                }

                else if (t.GetType().Name.Equals("RequirementTestSuite"))
                {
                    var reqsuite = (IRequirementTestSuite)t;

                    suiteList = suiteList + reqsuite.Id + "','";
                }
            }
            return(suiteList);
        }
Exemplo n.º 13
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.º 14
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.º 15
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.º 16
0
        private void GetTestSuites(IStaticTestSuite staticTestSuite, ExcelWorksheet worksheet, ExcelPackage xlpackage, ITestManagementTeamProject _testProject)
        {
            foreach (var suiteEntry in staticTestSuite.Entries.Where(suiteEntry => suiteEntry.EntryType == TestSuiteEntryType.TestCase))
            {
                WriteTestCaseToExcel(suiteEntry.TestCase, worksheet, _testProject);
                _i++;
            }

            foreach (var suiteEntry in staticTestSuite.Entries.Where(suiteEntry => suiteEntry.EntryType == TestSuiteEntryType.StaticTestSuite ||
                                                                     suiteEntry.EntryType == TestSuiteEntryType.RequirementTestSuite))
            {
                if (suiteEntry.EntryType == TestSuiteEntryType.StaticTestSuite)
                {
                    var suite = suiteEntry.TestSuite as IStaticTestSuite;
                    WriteSuiteToExcel(suiteEntry, worksheet);
                    _i++;
                    if (suite.Entries.Count > 0)
                    {
                        GetTestSuites(suite, worksheet, xlpackage, _testProject);
                    }
                }
                else
                {
                    var suite = suiteEntry.TestSuite as IRequirementTestSuite;
                    GetTestCases(suite, worksheet);
                }
            }
            xlpackage.Save();
        }
Exemplo n.º 17
0
        // copied from http://automatetheplanet.com/manage-tfs-test-suites-csharp-code/
        public void DeleteSuite(ITestPlan testPlan, int suiteToBeRemovedId, IStaticTestSuite parent = null)
        {
            ITestSuiteBase currentSuite = _client.TeamProject.TestSuites.Find(suiteToBeRemovedId);

            if (currentSuite == null)
            {
                throw new TestObjectNotFoundException(string.Format("Suite can't be found"));
            }
            // Remove the parent child relation. This is the only way to delete the suite.
            if (parent != null)
            {
                parent.Entries.Remove(currentSuite);
            }
            else if (currentSuite.Parent != null)
            {
                currentSuite.Parent.Entries.Remove(currentSuite);
            }
            else
            {
                // If it's initial suite, remove it from the test plan.
                testPlan.RootSuite.Entries.Remove(currentSuite);
            }

            // Apply changes to the suites
            testPlan.Save();
        }
Exemplo n.º 18
0
        private void GetAllTestSuitesFromSuiteNode(
            int rootSuiteId,
            ICollection <ITestSuiteBase> testSuites)
        {
            ITestSuiteBase suite = GetSuiteById(rootSuiteId);

            if (suite == null)
            {
                return;
            }

            testSuites.Add(suite);

            if (suite.TestSuiteType.Equals(TestSuiteType.StaticTestSuite))
            {
                IStaticTestSuite staticSuite = suite as IStaticTestSuite;
                if (staticSuite != null)
                {
                    foreach (ITestSuiteEntry testSuiteEntry in staticSuite.Entries)
                    {
                        GetAllTestSuitesFromSuiteNode(testSuiteEntry.Id, testSuites);
                    }
                }
            }
        }
Exemplo n.º 19
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);
        }
        private IStaticTestSuite CreateSuite(string name)
        {
            IStaticTestSuite newSuite = m_project.TestSuites.CreateStatic();

            newSuite.Title       = name;
            newSuite.Description = string.Empty;
            return(newSuite);
        }
Exemplo n.º 21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TfsTestSuite"/> class.
 /// </summary>
 /// <param name="testSuite">Original test suite - <see cref="IStaticTestSuite"/>.</param>
 public TfsTestSuite(IStaticTestSuite testSuite, ITfsTestPlan associatedTestPlan)
 {
     AssociatedTestPlan      = associatedTestPlan;
     OriginalStaticTestSuite = testSuite;
     Id    = OriginalStaticTestSuite.Id;
     Title = OriginalStaticTestSuite.Title;
     InitializeChildSuites();
 }
Exemplo n.º 22
0
        private static IStaticTestSuite CreateTestSuite(ITestManagementTeamProject project)
        {
            // Create a static test suite.
            IStaticTestSuite testSuite = project.TestSuites.CreateStatic();

            testSuite.Title = "Static Suite";
            return(testSuite);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Pastes the test cases to suite.
        /// </summary>
        /// <param name="testManagementTeamProject">The test management team project.</param>
        /// <param name="testPlan">The test plan.</param>
        /// <param name="suiteToAddInId">The suite automatic add information unique identifier.</param>
        /// <param name="clipBoardTestCase">The clip board test case.</param>
        /// <exception cref="System.ArgumentException">New test cases cannot be added to requirement based suites!</exception>
        public static void PasteTestCasesToSuite(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, int suiteToAddInId, ClipBoardTestCase clipBoardTestCase)
        {
            ITestSuiteBase suiteToAddIn = testManagementTeamProject.TestSuites.Find(suiteToAddInId);

            if (suiteToAddIn is IRequirementTestSuite)
            {
                throw new ArgumentException("New test cases cannot be added to requirement based suites!");
            }
            IStaticTestSuite suiteToAddInStatic = suiteToAddIn as IStaticTestSuite;
            ITestSuiteBase   oldSuite;
            List <TestCase>  allTestCasesInPlan = null;

            if (clipBoardTestCase.TestCases[0].TestSuiteId != null)
            {
                oldSuite = testManagementTeamProject.TestSuites.Find((int)clipBoardTestCase.TestCases[0].TestSuiteId);
            }
            else
            {
                oldSuite = null;
            }

            foreach (TestCase currentTestCase in clipBoardTestCase.TestCases)
            {
                ITestCase testCaseCore = null;
                if (oldSuite is IRequirementTestSuite)
                {
                    IRequirementTestSuite suite = oldSuite as IRequirementTestSuite;
                    testCaseCore = suite.TestCases.Where(x => x.TestCase != null && x.TestCase.Id.Equals(currentTestCase.TestCaseId)).FirstOrDefault().TestCase;
                }
                else if (oldSuite is IStaticTestSuite)
                {
                    IStaticTestSuite suite = oldSuite as IStaticTestSuite;
                    testCaseCore = suite.Entries.Where(x => x.TestCase != null && x.TestCase.Id.Equals(currentTestCase.TestCaseId)).FirstOrDefault().TestCase;
                }
                else if (oldSuite == null)
                {
                    if (allTestCasesInPlan == null)
                    {
                        allTestCasesInPlan = TestCaseManager.GetAllTestCasesInTestPlan(testManagementTeamProject, testPlan);
                    }
                    testCaseCore = allTestCasesInPlan.Where(t => t.TestCaseId.Equals(currentTestCase.TestCaseId)).FirstOrDefault().ITestCase;
                }
                if (!suiteToAddInStatic.Entries.Contains(testCaseCore))
                {
                    suiteToAddInStatic.Entries.Add(testCaseCore);
                }
                if (clipBoardTestCase.ClipBoardCommand.Equals(ClipBoardCommand.Cut))
                {
                    if (oldSuite is IStaticTestSuite)
                    {
                        IStaticTestSuite suite = oldSuite as IStaticTestSuite;
                        suite.Entries.Remove(testCaseCore);
                    }
                }
            }

            testPlan.Save();
        }
Exemplo n.º 24
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.º 25
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.º 26
0
        public void CreateTestCasesFromAutomatedTests(string tfsURL, string tfsProjectName, int generalAutomationPlanID)
        {
            //Connect to Project by name
            TfsTeamProjectCollection   projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(tfsURL));
            ITestManagementTeamProject teamProject       = projectCollection.GetService <ITestManagementService>().GetTeamProject(tfsProjectName);
            //Connect to Plan by ID
            ITestPlan        foundPlan = teamProject.TestPlans.Find(generalAutomationPlanID);
            IStaticTestSuite newSuite  = teamProject.TestSuites.CreateStatic();

            newSuite.Title = "My Suite";
        }
        private static ITestSuiteBase FindSuite(IStaticTestSuite parentTestSuite, string name)
        {
            parentTestSuite.Refresh();
            foreach (ITestSuiteEntry testSuite in parentTestSuite.Entries)
            {
                if (string.Equals(name, testSuite.Title, StringComparison.CurrentCultureIgnoreCase))
                {
                    return(testSuite.TestSuite);
                }
            }

            return(null);
        }
Exemplo n.º 28
0
        /// <summary>
        /// Copies test cases associated with a test suite (also work for test plan rooted test cases using Plan.RootSuite).
        /// </summary>
        /// <param name="sourceTestSuite">The source test suite.</param>
        /// <param name="destinationTestSuite">The destination test suite.</param>
        private static string CopyTestCases(IStaticTestSuite sourceTestSuite, IStaticTestSuite destinationTestSuite)
        {
            string results = string.Empty;

            foreach (ITestSuiteEntry sourceTestCaseEntry in sourceTestSuite.TestCases)
            {
                ITestCase sourceTestCase = sourceTestCaseEntry.TestCase;

                results += CopyTestCase(sourceTestCase, destinationTestSuite);
            }

            return(results);
        }
Exemplo n.º 29
0
        public static IList <ITestPoint> CreateTestPoints(ITestManagementTeamProject project, ITestPlan testPlan, IList <ITestCase> testCases, IList <IdAndName> testConfigs)
        {
            IStaticTestSuite testSuite = CreateTestSuite(project);

            testPlan.RootSuite.Entries.Add(testSuite);
            testPlan.Save();
            testSuite.Entries.AddCases(testCases);
            testPlan.Save();
            testSuite.SetEntryConfigurations(testSuite.Entries, testConfigs);
            testPlan.Save();
            ITestPointCollection tpc = testPlan.QueryTestPoints("SELECT * FROM TestPoint WHERE SuiteId = " + testSuite.Id);

            return(new List <ITestPoint>(tpc));
        }
Exemplo n.º 30
0
        private void comBoxTestSuite_SelectedIndexChanged(object sender, EventArgs e)
        {
            int j = -1;

            if (comBoxTestPlan.SelectedIndex >= 0)
            {
                j          = comBoxTestSuite.SelectedIndex;
                this.suite = testSuites[j].TestSuite.TestSuiteEntry;
                IStaticTestSuite suite1 = suite.TestSuite as IStaticTestSuite;
                Get_TestCases(suite1);
                flag3 = 1;
                grpResultFilter.Enabled = true;
            }
        }
 private void AddTestToSuite(int tfsId, IStaticTestSuite parentTestSuite)
 {
     if (parentTestSuite != null)
     {
         ITestCase testCase = m_project.TestCases.Find(tfsId);
         if ((testCase != null) && !parentTestSuite.TestCases.Contains(testCase))
         {
             parentTestSuite.Entries.AddCases(new List <ITestCase>()
             {
                 testCase
             }, false);
         }
     }
 }
        //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);
                }
            }
        }
        //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 = 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;
                            }
                        }
                    }
                    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);
                }
            }
        }
        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.º 35
0
        private static void ShallowCopy(ITestSuiteEntry sourceEntry, IStaticTestSuite targetParenTestSuite, int nodeLevel = 0)
        {
            var indent = string.Join("", Enumerable.Repeat('\t', nodeLevel));

            if (sourceEntry.EntryType == TestSuiteEntryType.StaticTestSuite)
            {
                IStaticTestSuite copiedTestSuite = (IStaticTestSuite)targetParenTestSuite.SubSuites.FirstOrDefault(s => s.Title == sourceEntry.Title);

                if (copiedTestSuite != null)
                {
                    WriteSkipped("{0}- SUITE: \"{1}\"", indent, sourceEntry.Title);
                }
                else
                {
                    copiedTestSuite = _connectProject.TestSuites.CreateStatic();

                    // copy all useful infomation
                    copiedTestSuite.Title = sourceEntry.Title;

                    // add new test suite to an appropriate parent Test Suite
                    targetParenTestSuite.Entries.Add(copiedTestSuite);

                    Console.WriteLine("{0}- SUITE: \"{1}\"", indent, copiedTestSuite.Title);
                }

                // go through children
                var sourceTestSuite = (IStaticTestSuite)sourceEntry.TestSuite;
                foreach (var entry in sourceTestSuite.Entries)
                {
                    ShallowCopy(entry, copiedTestSuite, nodeLevel + 1);
                }
            }
            else if (sourceEntry.EntryType == TestSuiteEntryType.TestCase)
            {
                var targetTestCase = sourceEntry.TestCase;

                if (targetParenTestSuite.TestCases.Any(s => s.Title == sourceEntry.Title))
                {
                    WriteSkipped("{0}- {1}", indent, targetTestCase.Title);
                }
                else
                {
                    targetParenTestSuite.Entries.Add(targetTestCase);
                    Console.WriteLine("{0}- {1}", indent, targetTestCase.Title);
                }
            }
        }
        /// <summary>
        /// Deletes the suite.
        /// </summary>
        /// <param name="suiteToBeRemovedId">The suite to be removed unique identifier.</param>
        /// <param name="parent">The parent.</param>
        /// <exception cref="System.ArgumentException">The root suite cannot be deleted!</exception>
        public static void DeleteSuite(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, int suiteToBeRemovedId, IStaticTestSuite parent = null)
        {
            // If it's root suite throw exception
            if (suiteToBeRemovedId == -1)
            {
                throw new ArgumentException("The root suite cannot be deleted!");
            }
            ITestSuiteBase currentSuite = testManagementTeamProject.TestSuites.Find(suiteToBeRemovedId);
       
            // Remove the parent child relation. This is the only way to delete the suite.
            if (parent != null)
            {
                log.InfoFormat("Remove suite Title= \"{0}\", id= \"{1}\" from suite Title= \"{2}\", id= \"{3}\"", currentSuite.Title, currentSuite.Id, parent.Title, parent.Id);
                parent.Entries.Remove(currentSuite);
            }
            else if (currentSuite.Parent != null)
            {
                log.InfoFormat("Remove suite Title= \"{0}\", id= \"{1}\" from suite Title= \"{2}\", id= \"{3}\"", currentSuite.Title, currentSuite.Id, currentSuite.Parent.Title, currentSuite.Parent.Id);
                currentSuite.Parent.Entries.Remove(currentSuite);
            }
            else
            {
                // If it's initial suite, remove it from the test plan.
                testPlan.RootSuite.Entries.Remove(currentSuite);
                log.Info("Remove suite Title= \"{0}\", id= \"{1}\" from test plan.");
            }

            // Apply changes to the suites
            testPlan.Save();
        }
        /// <summary>
        /// Copies test suites that are children of another test suite.
        /// </summary>
        /// <param name="parentSourceTestSuite">The parent source test suite.</param>
        /// <param name="parentDestinationTestSuite">The parent destination test suite.</param>
        private static string CopyTestSuites(IStaticTestSuite parentSourceTestSuite, IStaticTestSuite parentDestinationTestSuite)
        {
            string results = string.Empty;

            foreach (IStaticTestSuite sourceTestSuite in parentSourceTestSuite.SubSuites)
            {
                IStaticTestSuite destinationTestSuite = parentDestinationTestSuite.Project.TestSuites.CreateStatic();

                destinationTestSuite.Title = sourceTestSuite.Title;
                destinationTestSuite.SetDefaultConfigurations(GetDefaultConfigurationCollection(parentDestinationTestSuite.Project));
                parentDestinationTestSuite.Entries.Add(destinationTestSuite);

                parentDestinationTestSuite.Plan.Save();

                results = "Copying Test Suite: " + sourceTestSuite.Title + Environment.NewLine;

                results += CopyTestCases(sourceTestSuite, destinationTestSuite);

                if (sourceTestSuite.Entries.Count > 0)
                {
                    results += CopyTestSuites(sourceTestSuite, destinationTestSuite);
                }
            }
            return results;
        }
        /// <summary>
        /// Copies a test case.
        /// </summary>
        /// <param name="sourceTestCase">The source test case.</param>
        /// <param name="destinationTestSuite">The destination test suite.</param>
        private static string CopyTestCase(ITestCase sourceTestCase, IStaticTestSuite destinationTestSuite)
        {
            string results = string.Empty;

            ITestCase destinationTestCase = destinationTestSuite.Project.TestCases.Create();

            destinationTestCase.Title = sourceTestCase.Title;
            destinationTestCase.Description = sourceTestCase.Description;
            destinationTestCase.Priority = sourceTestCase.Priority;

            Debug.WriteLine("Test Case: " + sourceTestCase.Title);
            foreach (Field aField in sourceTestCase.CustomFields)
            {
                Debug.WriteLine(string.Format("Field Name: '{0}', Value: '{1}'", aField.Name, aField.Value));
            }

            List<Field> trueCustomFields = (from aField in destinationTestCase.CustomFields.Cast<Field>()
                                            where !aField.ReferenceName.StartsWith("Microsoft") &&
                                            !aField.ReferenceName.StartsWith("System")
                                            select aField).ToList();

            foreach (Field destField in trueCustomFields)
            {
                Field sourceField = (from aField in sourceTestCase.CustomFields.Cast<Field>()
                                     where aField.ReferenceName == destField.ReferenceName
                                     select aField).FirstOrDefault();

                if (sourceField != null)
                {
                    destField.Value = sourceField.Value;
                }
            }

            // Set Area and Iteration Paths
            string areaPath = sourceTestCase.CustomFields["Area Path"].Value.ToString();
            if (areaPath.Contains("\\"))
            {
                areaPath = areaPath.Replace(sourceTestCase.Project.TeamProjectName, destinationTestSuite.Project.TeamProjectName);  // replace the project name

                int areaId = (from node in _destinationAreaNodes
                              where node.Path == areaPath
                              select node.Id).FirstOrDefault();

                destinationTestCase.CustomFields["Area Path"].Value = areaPath;
                destinationTestCase.CustomFields["Area ID"].Value = areaId;
            }

            string iterationPath = sourceTestCase.CustomFields["Iteration Path"].Value.ToString();
            if (iterationPath.Contains("\\"))
            {
                iterationPath = iterationPath.Replace(sourceTestCase.Project.TeamProjectName, destinationTestSuite.Project.TeamProjectName);  // replace the project name

                int iterationId = (from node in _destinationIterationNodes
                                   where node.Path == iterationPath
                                   select node.Id).FirstOrDefault();

                destinationTestCase.CustomFields["Iteration Path"].Value = iterationPath;
                destinationTestCase.CustomFields["Iteration ID"].Value = iterationId;
            }

            #region Attachments

            foreach (ITestAttachment sourceAttachment in sourceTestCase.Attachments)
            {
                string filePath = Path.Combine(Path.GetTempPath(), sourceAttachment.Name);

                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }

                sourceAttachment.DownloadToFile(filePath);

                ITestAttachment destinationAttachment = destinationTestCase.CreateAttachment(filePath);
                destinationAttachment.AttachmentType = sourceAttachment.AttachmentType;
                destinationAttachment.Comment = sourceAttachment.Comment;

                destinationTestCase.Attachments.Add(destinationAttachment);

                destinationTestCase.Save();

                File.Delete(filePath);
            }

            #endregion

            #region Test Steps/Parameters

            foreach (ITestParameter sourceParameter in sourceTestCase.TestParameters)
            {
                destinationTestCase.ReplaceParameter(sourceParameter.Name, sourceParameter.Value);
            }

            foreach (ITestStep sourceAction in sourceTestCase.Actions)
            {
                ITestStep destinationTestStep = destinationTestCase.CreateTestStep();

                destinationTestStep.Title = sourceAction.Title;
                destinationTestStep.Description = sourceAction.Description;
                destinationTestStep.TestStepType = sourceAction.TestStepType;
                destinationTestStep.ExpectedResult = sourceAction.ExpectedResult;
                destinationTestCase.Actions.Add(destinationTestStep);

                // Test Step Attachments
                foreach (ITestAttachment sourceAttachment in sourceAction.Attachments)
                {
                    string filePath = Path.Combine(Path.GetTempPath(), sourceAttachment.Name);

                    if (File.Exists(filePath))
                    {
                        File.Delete(filePath);
                    }

                    sourceAttachment.DownloadToFile(filePath);

                    ITestAttachment destinationAttachment = destinationTestStep.CreateAttachment(filePath);
                    destinationAttachment.AttachmentType = sourceAttachment.AttachmentType;
                    destinationAttachment.Comment = sourceAttachment.Comment;

                    destinationTestStep.Attachments.Add(destinationAttachment);

                    try
                    {
                        destinationTestCase.Save();
                    }
                    catch (FileAttachmentException fileException)
                    {
                        destinationTestStep.Attachments.Remove(destinationAttachment);
                        results += string.Format(" - Suite: '{0}', Test Case: '{1}', Could not added attachment '{2}' due to '{3}'" + Environment.NewLine, destinationTestSuite.Title, destinationTestCase.Title, sourceAttachment.Name, fileException.Message);
                    }

                    File.Delete(filePath);
                }
            }

            #endregion

            destinationTestCase.Save();

            destinationTestCase.State = sourceTestCase.State;

            TeamFoundationIdentity sourceIdentity = sourceTestCase.Owner;

            if (sourceIdentity == null)
            {
                results += string.Format(" - Suite: '{0}', Test Case: '{1}', Could not set Assigned To user, not setup as a TFS user." + Environment.NewLine, destinationTestSuite.Title, destinationTestCase.Title);
            }
            else
            {

                TeamFoundationIdentity destinationIdentity = null;
                try
                {
                    destinationIdentity = destinationTestCase.Project.TfsIdentityStore.FindByAccountName(sourceIdentity.UniqueName);
                }
                catch (Exception e) { }

                if (destinationIdentity != null && destinationIdentity.IsActive)
                {
                    destinationTestCase.Owner = destinationIdentity;
                }
                else
                {
                    results += string.Format(" - Suite: '{0}', Test Case: '{1}', Could not set Assigned To user to '{2}'" + Environment.NewLine, destinationTestSuite.Title, destinationTestCase.Title, sourceIdentity.UniqueName);
                }
            }

            destinationTestCase.Save();

            destinationTestSuite.Entries.Add(destinationTestCase);
            destinationTestSuite.Plan.Save();

            return results;
        }
        /// <summary>
        /// Copies test cases associated with a test suite (also work for test plan rooted test cases using Plan.RootSuite).
        /// </summary>
        /// <param name="sourceTestSuite">The source test suite.</param>
        /// <param name="destinationTestSuite">The destination test suite.</param>
        private static string CopyTestCases(IStaticTestSuite sourceTestSuite, IStaticTestSuite destinationTestSuite)
        {
            string results = string.Empty;

            foreach (ITestSuiteEntry sourceTestCaseEntry in sourceTestSuite.TestCases)
            {
                ITestCase sourceTestCase = sourceTestCaseEntry.TestCase;

                results += CopyTestCase(sourceTestCase, destinationTestSuite);
            }

            return results;
        }
Exemplo n.º 40
0
 public static ITestCaseCollection GetTestCases(IStaticTestSuite suite)
 {
     //AllTestCases - Will show all the Test Cases under that Suite even in sub suites.
        return suite.AllTestCases;
 }
Exemplo n.º 41
0
        private List<ITestSuiteBase> GetTestSuiteRecursive(IStaticTestSuite staticTestSuite)
        {
            // 1. Store results in the IStaticTestSuit list.
            var result = new List<ITestSuiteBase>();

            // 2. Store a stack of our TestSuite.
            var stack = new Stack<ITestSuiteBase>();

            // 3. Add Root Test Suite
            stack.Push(staticTestSuite);

            // 4. Continue while there are TestSuites to Process
            while (stack.Count > 0)
            {
                // A. Get top Suite
                var dir = stack.Pop();

                try
                {
                    // B. Add all TestSuite at this directory to the result List.
                    result.Add(dir);

                    // only static suites can contain subsuites
                    var staticDir = dir as IStaticTestSuite;
                    if (staticDir != null)
                    {
                        // C. Add all SubSuite at this TestSuite.
                        foreach (ITestSuiteBase ss in staticDir.SubSuites)
                        {
                            stack.Push(ss);
                        }
                    }
                }
                // ReSharper disable once EmptyGeneralCatchClause
                catch
                {
                    // D. Fails to open the test suite
                }
            }

            return result;
        }
Exemplo n.º 42
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;
        }