private void AddChildTestCases(ITestSuiteBase source, ITestSuiteBase target, ITestPlan targetPlan) { target.Refresh(); targetPlan.Refresh(); targetPlan.RefreshRootSuite(); if (CanSkipElementBecauseOfTags(source.Id)) { return; } Trace.WriteLine(string.Format(" Suite has {0} test cases", source.TestCases.Count), "TestPlansAndSuites"); List <ITestCase> tcs = new List <ITestCase>(); foreach (ITestSuiteEntry sourceTestCaseEntry in source.TestCases) { Trace.WriteLine($"Work item: {sourceTestCaseEntry.Id}"); if (CanSkipElementBecauseOfTags(sourceTestCaseEntry.Id)) { return; } Trace.WriteLine(string.Format(" Processing {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); WorkItem wi = targetWitStore.FindReflectedWorkItem(sourceTestCaseEntry.TestCase.WorkItem, me.ReflectedWorkItemIdFieldName, false); if (wi == null) { Trace.WriteLine(string.Format(" Can't find work item for Test Case. Has it been migrated? {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); break; } var exists = (from tc in target.TestCases where tc.TestCase.WorkItem.Id == wi.Id select tc).SingleOrDefault(); if (exists != null) { Trace.WriteLine(string.Format(" Test case already in suite {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); } else { ITestCase targetTestCase = targetTestStore.Project.TestCases.Find(wi.Id); if (targetTestCase == null) { Trace.WriteLine(string.Format(" ERROR: Test case not found {0} : {1} - {2} ", sourceTestCaseEntry.EntryType, sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); } else { tcs.Add(targetTestCase); Trace.WriteLine(string.Format(" Adding {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); } } } target.TestCases.AddCases(tcs); targetPlan.Save(); Trace.WriteLine(string.Format(" SAVED {0} : {1} - {2} ", target.TestSuiteType.ToString(), target.Id, target.Title), "TestPlansAndSuites"); }