Example #1
0
        public IEnumerable<TestResultView> GetTestCaseResults(ITestSuiteEntry testCase)
        {
            if (testCase == null) return null;
            var testResults = TfsShared.Instance.SourceTestProject.TestResults.ByTestId(testCase.Id);

            List<TestResultView> testcaseResults = new List<TestResultView>();

            foreach (var result in testResults)
            {
                ITestCaseResult tr = (ITestCaseResult)result;

                testcaseResults.Add(new TestResultView()
                {
                    Outcome = tr.Outcome,
                    Duration = tr.Duration,
                    Comment = tr.Comment,
                    LastUpdated = tr.LastUpdated,
                    LastUpdatedByName = tr.LastUpdatedByName,
                    TestConfigurationName = tr.TestConfigurationName,
                    ComputerName = tr.ComputerName,
                    ErrorMessage = tr.ErrorMessage,
                    BuildNumber = tr.BuildNumber
                });
            }

            return testcaseResults.OrderByDescending(a => a.LastUpdated);
        }
Example #2
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);
        }
Example #3
0
 private void ApplyConfigurations(ITestSuiteEntry sourceEntry, ITestSuiteEntry targetEntry)
 {
     if (sourceEntry.Configurations != null)
     {
         if (sourceEntry.Configurations.Count != targetEntry.Configurations.Count)
         {
             Trace.WriteLine(string.Format("   CONFIG MNISSMATCH FOUND --- FIX AATTEMPTING"), "TestPlansAndSuites");
             targetEntry.Configurations.Clear();
             IList <IdAndName> targetConfigs = new List <IdAndName>();
             foreach (var config in sourceEntry.Configurations)
             {
                 var targetFound = (from tc in targetTestConfigs
                                    where tc.Name == config.Name
                                    select tc).SingleOrDefault();
                 if (!(targetFound == null))
                 {
                     targetConfigs.Add(new IdAndName(targetFound.Id, targetFound.Name));
                 }
             }
             try
             {
                 targetEntry.SetConfigurations(targetConfigs);
             }
             catch (Exception)
             {
                 // SOmetimes this will error out for no reason.
             }
         }
     }
 }
        /// <summary>
        /// Apply configurations to a single test case entry on the target, by copying from the source
        /// </summary>
        /// <param name="sourceEntry"></param>
        /// <param name="targetEntry"></param>
        private void ApplyConfigurations(ITestSuiteEntry sourceEntry, ITestSuiteEntry targetEntry)
        {
            int sourceConfigCount = sourceEntry.Configurations != null ? sourceEntry.Configurations.Count : 0;
            int targetConfigCount = targetEntry.Configurations != null ? targetEntry.Configurations.Count : 0;
            var deviations        = sourceConfigCount > 0 && targetConfigCount > 0 && sourceEntry.Configurations.Select(x => x.Name).Intersect(targetEntry.Configurations.Select(x => x.Name)).Count() < sourceConfigCount;

            if ((sourceConfigCount != targetConfigCount) || deviations)
            {
                Trace.WriteLine(string.Format("   CONFIG MISMATCH FOUND --- FIX ATTEMPTING"), "TestPlansAndSuites");
                IList <IdAndName> targetConfigs = new List <IdAndName>();
                foreach (var config in sourceEntry.Configurations)
                {
                    var targetFound = (from tc in targetTestConfigs
                                       where tc.Name == config.Name
                                       select tc).SingleOrDefault();
                    if (targetFound != null)
                    {
                        targetConfigs.Add(new IdAndName(targetFound.Id, targetFound.Name));
                    }
                }
                try
                {
                    targetEntry.SetConfigurations(targetConfigs);
                }
                catch (Exception ex)
                {
                    // SOmetimes this will error out for no reason.
                    Telemetry.Current.TrackException(ex);
                }
            }
        }
Example #5
0
        public IEnumerable <TestResultView> GetTestCaseResults(ITestSuiteEntry testCase)
        {
            if (testCase == null)
            {
                return(null);
            }
            var testResults = TfsShared.Instance.SourceTestProject.TestResults.ByTestId(testCase.Id);

            List <TestResultView> testcaseResults = new List <TestResultView>();

            foreach (var result in testResults)
            {
                ITestCaseResult tr = (ITestCaseResult)result;

                testcaseResults.Add(new TestResultView()
                {
                    Outcome               = tr.Outcome,
                    Duration              = tr.Duration,
                    Comment               = tr.Comment,
                    LastUpdated           = tr.LastUpdated,
                    LastUpdatedByName     = tr.LastUpdatedByName,
                    TestConfigurationName = tr.TestConfigurationName,
                    ComputerName          = tr.ComputerName,
                    ErrorMessage          = tr.ErrorMessage,
                    BuildNumber           = tr.BuildNumber
                });
            }

            return(testcaseResults.OrderByDescending(a => a.LastUpdated));
        }
Example #6
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);
     }
 }
        private int GenerateTestCaseHeader(int row, ITestSuiteEntry testCaseEntry)
        {
            string arg = RefinementWindow.createComments ? "E" : "D";

            WriteRange("B" + row, arg + row, "ID: " + testCaseEntry.Id.ToString(), null, null, false, true, TextAlignment.TopRight, true);
            int num = row + 1;

            WriteRange("B" + num, arg + num, testCaseEntry.Title, null, 35.0, false, false, TextAlignment.CenterMiddle, true);

            num++;

            if (RefinementWindow.includeDescription && !string.IsNullOrEmpty(testCaseEntry.TestCase.Description))
            {
                string description = HtmlToPlainText(testCaseEntry.TestCase.Description);

                WriteRange("B" + num, arg + num, description, null, 60.0, false, false, TextAlignment.CenterMiddle, true);
                _range = this._worksheet.get_Range("B" + num, arg + num);
                DrawSolidBorders(this._range, 0);
                num++;
            }

            var array = new []
            {
                new { cell = "B" + num, title = "#", columnWidth = 2.86 },
                new { cell = "C" + num, title = "Action", columnWidth = 70.0 },
                new { cell = "D" + num, title = "Expected Result", columnWidth = 70.0 },
                new { cell = "E" + num, title = "Comments", columnWidth = 40.0 }
            };

            _range = this._worksheet.get_Range("B" + row, arg + num);
            _range.Interior.Color = 13037518;
            DrawSolidBorders(this._range, 0);
            int num2;
            int num3;

            if (RefinementWindow.createComments)
            {
                num2 = 4;
                num3 = 1;
            }
            else
            {
                num2 = 3;
                num3 = 2;
            }

            for (int i = 0; i < num2; i++)
            {
                this.WriteRange(array[i].cell, array[i].cell, array[i].title, array[i].columnWidth, null, false, true, TextAlignment.Center, null);
            }

            _range = this._worksheet.get_Range(array[0].cell, array[array.Length - num3].cell);
            _range.Interior.Color = 13037518;
            DrawAllSolidBorders(this._range, 0);

            return(num + 1);
        }
 public TestObjectViewModel(ITestSuiteEntry test)
     : base(null, true)
 {
     _testObject = new TestObject(test.Title, test.Id, TestObjectType.Test);
     CanChecked = true;
     _testObject.TestPlanID = test.ParentTestSuite.Plan.Id;
     _testObject.Configurations = test.Configurations;
     _testObject.TestSuite = test;
 }
 public TestObjectViewModel(ITestSuiteEntry test)
     : base(null, true)
 {
     _testObject                = new TestObject(test.Title, test.Id, TestObjectType.Test);
     CanChecked                 = true;
     _testObject.TestPlanID     = test.ParentTestSuite.Plan.Id;
     _testObject.Configurations = test.Configurations;
     _testObject.TestSuite      = test;
 }
Example #10
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;
            }
        }
        void WriteSuiteToExcel(ITestSuiteEntry testSuite, ExcelWorksheet worksheet)
        {
            worksheet.Cells[_i, 1].Style.Fill.PatternType = ExcelFillStyle.Solid;
            worksheet.Cells[_i, 1].Style.Fill.BackgroundColor.SetColor(Color.CornflowerBlue);
            worksheet.Cells[_i, 1].Style.Font.Bold        = true;
            worksheet.Cells[_i, 2].Style.Fill.PatternType = ExcelFillStyle.Solid;
            worksheet.Cells[_i, 2].Style.Fill.BackgroundColor.SetColor(Color.CornflowerBlue);
            worksheet.Cells[_i, 3].Style.Fill.PatternType = ExcelFillStyle.Solid;
            worksheet.Cells[_i, 3].Style.Fill.BackgroundColor.SetColor(Color.CornflowerBlue);
            worksheet.Cells[_i, 4].Style.Fill.PatternType = ExcelFillStyle.Solid;
            worksheet.Cells[_i, 4].Style.Fill.BackgroundColor.SetColor(Color.CornflowerBlue);
            worksheet.Cells[_i, 5].Style.Fill.PatternType = ExcelFillStyle.Solid;
            worksheet.Cells[_i, 5].Style.Fill.BackgroundColor.SetColor(Color.CornflowerBlue);

            worksheet.Cells[_i, 1].Value = FindRootSuite(testSuite.TestSuite as IStaticTestSuite, testSuite.Title);
        }
Example #12
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 { }
        }
Example #13
0
        public TestCaseViewModel(ITestSuiteEntry testcase, IdAndName configuration, bool Async = true)
        {
            this.ConfigurationId   = configuration.Id;
            this.ConfigurationName = configuration.Name;

            this.TestCase        = testcase;
            this._testCaseObject = testcase.TestCase ?? TfsShared.Instance.SourceTestProject.TestCases.Find(testcase.Id);

            this.Owner = _testCaseObject.OwnerName;
            this.State = _testCaseObject.State;

            this.Title = testcase.Title;
            this.Id    = testcase.Id;

            if (Async)
            {
                Thread t = new Thread(new ThreadStart(CollectTestCaseDetails));
                t.Start();
            }
            else
            {
                CollectTestCaseDetails();
            }
        }
        private int GenerateTestCase(ITestSuiteEntry testCaseEntry, int startRow)
        {
            int currentRowNumber  = this.GenerateTestCaseHeader(startRow, testCaseEntry);
            int startingRowNumber = currentRowNumber;
            int stepNumber        = 1;

            foreach (ITestAction action in testCaseEntry.TestCase.Actions)
            {
                if (action is ISharedStepReference)
                {
                    ISharedStepReference isr           = (ISharedStepReference)action;
                    ISharedStep          ss            = isr.FindSharedStep();
                    TestActionCollection sharedActions = ss.Actions;

                    foreach (ITestAction sharedAction in sharedActions)
                    {
                        GenereateTestStepRow(currentRowNumber, stepNumber, (ITestStep)sharedAction);
                        stepNumber++;
                        currentRowNumber++;
                    }
                }
                else
                {
                    GenereateTestStepRow(currentRowNumber, stepNumber, (ITestStep)action);
                    stepNumber++;
                    currentRowNumber++;
                }
            }

            int endingRowNumber = currentRowNumber - 1;

            _range = _worksheet.get_Range("B" + startingRowNumber, (RefinementWindow.createComments ? "E" : "D") + endingRowNumber);
            DrawAllSolidBorders(_range, 0);

            return(currentRowNumber + 1);
        }
        public TestCaseViewModel(ITestSuiteEntry testcase, IdAndName configuration, bool Async = true)
        {
            this.ConfigurationId = configuration.Id;
            this.ConfigurationName = configuration.Name;

            this.TestCase = testcase;
            this._testCaseObject = testcase.TestCase ?? TfsShared.Instance.SourceTestProject.TestCases.Find(testcase.Id);

            this.Owner = _testCaseObject.OwnerName;
            this.State = _testCaseObject.State;

            this.Title = testcase.Title;
            this.Id = testcase.Id;

            if (Async)
            {
                Thread t = new Thread(new ThreadStart(CollectTestCaseDetails));
                t.Start();
            }
            else
            {
                CollectTestCaseDetails();
            }
        }
Example #16
0
        private async Task DuplicateTestCases(List <TestObjectViewModel> selectedItems, bool duplicate)
        {
            await Task.Factory.StartNew(() =>
            {
                TestObjectViewModel selectedSuite = null;
                selectedSuite = HasSelectedItem(_mappingViewModel.TestPlans, selectedSuite);

                ITestPlan plan =
                    TfsShared.Instance.TargetTestProject.TestPlans.Find(selectedSuite._testObject.TestPlanID);

                try
                {
                    foreach (TestObjectViewModel test in selectedItems)
                    {
                        var parentTestSuites       = new Stack();
                        ITestSuiteBase sourceSuite =
                            TfsShared.Instance.SourceTestProject.TestSuites.Find(test.TestSuiteId);

                        ITestCase testCase      = TfsShared.Instance.SourceTestProject.TestCases.Find(test.ID);
                        WorkItem targetWorkItem = null;
                        #region Create duplicate test cases
                        if (duplicate)
                        {
                            WorkItem duplicateWorkItem = null;
                            //if (!DuplicatedTestCase.Any(t => t.OldID.Equals(test.ID)))
                            //{
                            if ((sourceSuite.TestSuiteType != TestSuiteType.RequirementTestSuite) && (sourceSuite.TestSuiteType != TestSuiteType.DynamicTestSuite))
                            {
                                duplicateWorkItem = testCase.WorkItem.Copy(TfsShared.Instance.TargetProjectWorkItemType,
                                                                           WorkItemCopyFlags.CopyFiles);
                                //duplicateWorkItem.WorkItemLinks.Clear();

                                if (!duplicateWorkItem.IsValid())
                                {
                                    Logger = "Cannot Save Work Item - Stoping Migration\n" + Logger;
                                    ArrayList badFields = duplicateWorkItem.Validate();
                                    foreach (Field field in badFields)
                                    {
                                        Logger =
                                            string.Format("Name: {0}, Reference Name: {1},  Invalid Value: {2}\n",
                                                          field.Name, field.ReferenceName, field.Value) + Logger;
                                    }

                                    break;
                                }
                                else
                                {
                                    duplicateWorkItem.Save();

                                    //App.Current.Dispatcher.Invoke(() =>
                                    //{
                                    //    DuplicatedTestCase.Add(new TestCaseOldNewMapping()
                                    //    {
                                    //        OldID = testCase.Id,
                                    //        NewID = duplicateWorkItem.Id
                                    //    });
                                    //});

                                    Logger =
                                        string.Format("Duplicate Test Case: {0} completed, new Test Case ID: {1}\n",
                                                      test.ID,
                                                      duplicateWorkItem.Id) + Logger;
                                }
                            }
                            //}
                            //else
                            //{
                            //    TestCaseOldNewMapping mapping =
                            //        DuplicatedTestCase.FirstOrDefault(t => t.OldID.Equals(test.ID));
                            //    if (mapping == null) throw new NullReferenceException("Cannot locate new id");
                            //    duplicateWorkItem =
                            //        TfsShared.Instance.TargetTestProject.TestCases.Find(mapping.NewID).WorkItem;

                            //    Logger =
                            //        string.Format("Test Case: {0} already exists, Test Case ID: {1}\n", test.ID,
                            //            duplicateWorkItem.Id) + Logger;
                            //}

                            targetWorkItem = duplicateWorkItem;
                        }
                        else
                        {
                            targetWorkItem = testCase.WorkItem;
                        }
                        #endregion
                        ITestSuiteBase suite = sourceSuite;
                        while (suite != null)
                        {
                            parentTestSuites.Push(suite);
                            suite = suite.TestSuiteEntry.ParentTestSuite;
                        }

                        parentTestSuites.Pop();                                                      //Source tree parent suites

                        var parentSuite = (IStaticTestSuite)selectedSuite._testObject.TestSuiteBase; //Selected target suite
                        bool isTestCaseParentRequirementTestSuite = false;
                        bool isTestCaseParentDynamicTestSuite     = false;
                        foreach (ITestSuiteBase testSuite in parentTestSuites)
                        {
                            ITestSuiteBase existingSuite         = null;
                            isTestCaseParentRequirementTestSuite = false;
                            isTestCaseParentDynamicTestSuite     = false;
                            if (testSuite.TestSuiteType == TestSuiteType.RequirementTestSuite)
                            {
                                isTestCaseParentRequirementTestSuite = true;
                            }
                            if (testSuite.TestSuiteType == TestSuiteType.DynamicTestSuite)
                            {
                                isTestCaseParentDynamicTestSuite = true;
                            }

                            if (parentSuite.Title.Equals(testSuite.Title))
                            {
                                existingSuite = parentSuite;
                            }
                            else if (parentSuite.SubSuites.FirstOrDefault(t => t.Title.Equals(testSuite.Title)) != null)
                            {
                                var subSuite = parentSuite.SubSuites.FirstOrDefault(t => t.Title.Equals(testSuite.Title));

                                if (subSuite.TestSuiteType == TestSuiteType.StaticTestSuite)
                                {
                                    parentSuite = (IStaticTestSuite)parentSuite.SubSuites.FirstOrDefault(t => t.Title.Equals(testSuite.Title));
                                }
                                continue;
                            }
                            if (existingSuite == null)
                            {
                                Logger = "Creating new suite called - " + testSuite.Title + "\n" + Logger;


                                #region New Feature
                                switch (testSuite.TestSuiteType)
                                {
                                case TestSuiteType.RequirementTestSuite:
                                    var store          = ((IRequirementTestSuite)testSuite).Project.WitProject.Store;
                                    var tfsRequirement = store.GetWorkItem(((IRequirementTestSuite)testSuite).RequirementId);
                                    IRequirementTestSuite newRequirementSuite = TfsShared.Instance.TargetTestProject.TestSuites.CreateRequirement(tfsRequirement);


                                    newRequirementSuite.Title       = testSuite.Title;
                                    newRequirementSuite.Description = testSuite.Description;
                                    newRequirementSuite.State       = testSuite.State;
                                    tfsRequirement.Save();
                                    parentSuite.Entries.Add(newRequirementSuite);
                                    break;

                                case TestSuiteType.StaticTestSuite:
                                    IStaticTestSuite newStaticSuite = TfsShared.Instance.TargetTestProject.TestSuites.CreateStatic();
                                    newStaticSuite.Title            = testSuite.Title;
                                    newStaticSuite.State            = testSuite.State;
                                    newStaticSuite.Description      = testSuite.Description;

                                    parentSuite.Entries.Add(newStaticSuite);
                                    parentSuite = newStaticSuite;
                                    break;

                                case TestSuiteType.DynamicTestSuite:
                                    IDynamicTestSuite newDynamicSuite = TfsShared.Instance.TargetTestProject.TestSuites.CreateDynamic();
                                    newDynamicSuite.Query             = TfsShared.Instance.TargetTestProject.CreateTestQuery(((IDynamicTestSuite)testSuite).Query.QueryText);
                                    newDynamicSuite.Title             = testSuite.Title;
                                    newDynamicSuite.State             = testSuite.State;
                                    newDynamicSuite.Description       = testSuite.Description;
                                    parentSuite.Entries.Add(newDynamicSuite);
                                    break;
                                }
                                #endregion
                            }
                            else
                            {
                                Logger = string.Format("Suite '{0}' already exists.\n{1}", existingSuite.Title, Logger);
                            }

                            plan.Save();
                        }
                        if ((parentSuite.TestSuiteType == TestSuiteType.StaticTestSuite) && (isTestCaseParentRequirementTestSuite == false) && (isTestCaseParentDynamicTestSuite == false))
                        {
                            ITestCase targetTestCase =
                                TfsShared.Instance.TargetTestProject.TestCases.Find(targetWorkItem.Id);
                            if (!parentSuite.Entries.Contains(targetTestCase))
                            {
                                ITestSuiteEntry entry = parentSuite.Entries.Add(targetTestCase);
                                entry.Configurations.Add(test.Configuration);
                                Logger = "Adding duplicated test case completed.\n" + Logger;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger = string.Format("** ERROR ** : {0}\n", ex.Message) + Logger;
                }
            });
        }
        private void ApplyConfigurationsAndAssignTesters(ITestSuiteBase sourceSuite, ITestSuiteBase targetSuite)
        {
            Trace.Write($"Applying configurations for test cases in source suite {sourceSuite.Title}");
            foreach (ITestSuiteEntry sourceTce in sourceSuite.TestCases)
            {
                WorkItem        wi = targetWitStore.FindReflectedWorkItem(sourceTce.TestCase.WorkItem, me.ReflectedWorkItemIdFieldName, false);
                ITestSuiteEntry targetTce;
                if (wi != null)
                {
                    targetTce = (from tc in targetSuite.TestCases
                                 where tc.TestCase.WorkItem.Id == wi.Id
                                 select tc).SingleOrDefault();
                    if (targetTce != null)
                    {
                        ApplyConfigurations(sourceTce, targetTce);
                    }
                    else
                    {
                        Trace.Write($"Test Case ${sourceTce.Title} from source is not included in target. Cannot apply configuration for it.",
                                    "TestPlansAndSuites");
                    }
                }
                else
                {
                    Trace.Write($"Work Item for Test Case {sourceTce.Title} cannot be found in target. Has it been migrated?", "TestPlansAndSuites");
                }
            }

            AssignTesters(sourceSuite, targetSuite);

            //Loop over child suites and set configurations for test case entries there
            if (HasChildSuites(sourceSuite))
            {
                foreach (ITestSuiteEntry sourceSuiteChild in ((IStaticTestSuite)sourceSuite).Entries.Where(
                             e => e.EntryType == TestSuiteEntryType.DynamicTestSuite ||
                             e.EntryType == TestSuiteEntryType.RequirementTestSuite ||
                             e.EntryType == TestSuiteEntryType.StaticTestSuite))
                {
                    //Find migrated suite in target
                    WorkItem sourceSuiteWi = sourceWitStore.Store.GetWorkItem(sourceSuiteChild.Id);
                    WorkItem targetSuiteWi = targetWitStore.FindReflectedWorkItem(sourceSuiteWi, me.ReflectedWorkItemIdFieldName, false);
                    if (targetSuiteWi != null)
                    {
                        ITestSuiteEntry targetSuiteChild = (from tc in ((IStaticTestSuite)targetSuite).Entries
                                                            where tc.Id == targetSuiteWi.Id
                                                            select tc).FirstOrDefault();
                        if (targetSuiteChild != null)
                        {
                            ApplyConfigurationsAndAssignTesters(sourceSuiteChild.TestSuite, targetSuiteChild.TestSuite);
                        }
                        else
                        {
                            Trace.Write($"Test Suite {sourceSuiteChild.Title} from source cannot be found in target. Has it been migrated?", "TestPlansAndSuites");
                        }
                    }
                    else
                    {
                        Trace.Write($"Test Suite {sourceSuiteChild.Title} from source cannot be found in target. Has it been migrated?", "TestPlansAndSuites");
                    }
                }
            }
        }
Example #18
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);
                }
            }
        }
Example #19
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);
        }
Example #20
0
 public TestCase(ITestSuiteEntry TFSTestSuiteEntry)
 {
     this.TFSTestSuiteEntry = TFSTestSuiteEntry;
 }
        private void CopyEntry(ITestSuiteEntry sourceEntry, Dictionary<int, IStaticTestSuite> map, int nodeLevel = 0)
        {
            var copiedParrentTestSuite = map[sourceEntry.ParentTestSuite.Id];
            var indent = string.Join("", Enumerable.Repeat('\t', nodeLevel));

            if (sourceEntry.EntryType == TestSuiteEntryType.StaticTestSuite)
            {
                var copiedTestSuite = _connectProject.TestSuites.CreateStatic();

                // copy all useful infomation
                copiedTestSuite.Title = sourceEntry.Title;
                if (sourceEntry.Configurations != null && sourceEntry.Configurations.Count > 0)
                {
                    var mappedConfings = sourceEntry.Configurations.Select(c => ConfigMap[c.Id]);
                    copiedTestSuite.SetDefaultConfigurations(mappedConfings);
                }

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

                // update map
                map.Add(sourceEntry.Id, copiedTestSuite);

                // go through children
                var sourceTestSuite = (IStaticTestSuite)sourceEntry.TestSuite;

                Console.WriteLine("{0}- SUITE: \"{1}\" ({2} items)", indent, copiedTestSuite.Title, sourceTestSuite.Entries.Count);

                foreach (var entry in sourceTestSuite.Entries)
                {
                    CopyEntry(entry, map, nodeLevel + 1);
                }
            }
            else if (sourceEntry.EntryType == TestSuiteEntryType.TestCase)
            {
                var links = sourceEntry.TestCase.WorkItem.Links;
                var link = links.OfType<RelatedLink>().Single(l => l.Comment == "History Ref");
                var targetTestCaseId = link.RelatedWorkItemId;

                var targetTestCase = _connectProject.TestCases.Find(targetTestCaseId);
                copiedParrentTestSuite.Entries.Add(targetTestCase);

                Console.WriteLine("{0}- {1}", indent, targetTestCase.Title);
            }
        }