/// <summary> /// Migrates the test cases from source to destination. /// </summary> public void MigrateTestCasesFromSourceToDestinationInternal() { if (!string.IsNullOrEmpty(this.MigrationTestCasesRetryJsonPath) && File.Exists(this.MigrationTestCasesRetryJsonPath)) { this.testCasesMigrationLogManager = new MigrationLogManager(this.MigrationTestCasesRetryJsonPath); this.testCasesMigrationLogManager.LoadCollectionFromExistingFile(); this.testCasesMapping = this.testCasesMigrationLogManager.GetProssedItemsMappings(); } else { this.testCasesMigrationLogManager = new MigrationLogManager("testCases", this.DefaultJsonFolder); } this.ProgressConcurrentQueue.Enqueue("Prepare source test cases..."); ITestPlan sourceTestPlan = TestPlanManager.GetTestPlanByName(this.sourceTeamProject, this.SelectedSourceTestPlan); List <TestCase> sourceTestCases = TestCaseManager.GetAllTestCasesFromSuiteCollection(this.sourcePreferences.TestPlan, this.sourcePreferences.TestPlan.RootSuite.SubSuites); TestCaseManager.AddTestCasesWithoutSuites(this.sourceTeamProject, this.sourcePreferences.TestPlan, sourceTestCases); foreach (TestCase currentSourceTestCase in sourceTestCases) { if (this.executionCancellationToken.IsCancellationRequested) { break; } // If it's already processed skip it if (this.testCasesMigrationLogManager.MigrationEntries.Count(e => e.SourceId.Equals(currentSourceTestCase.ITestCase.Id) && e.IsProcessed.Equals(true)) > 0) { continue; } string infoMessage = String.Empty; try { infoMessage = String.Format("Start Migrating Test Case with Source Id= {0}", currentSourceTestCase.Id); log.Info(infoMessage); this.ProgressConcurrentQueue.Enqueue(infoMessage); //Don't migrate the test case if its suite is in the exclusion list if (currentSourceTestCase.ITestSuiteBase != null && this.ObservableSuitesToBeSkipped.Count(t => t != null && t.NewText != null && t.NewText.Equals(currentSourceTestCase.ITestSuiteBase.Title)) > 0) { continue; } List <TestStep> currentSourceTestCaseTestSteps = TestStepManager.GetTestStepsFromTestActions(this.sourceTeamProject, currentSourceTestCase.ITestCase.Actions); bool shouldCreateTestCase = true; foreach (TestStep currentTestStep in currentSourceTestCaseTestSteps) { if (currentTestStep.IsShared) { //If the test step is shared we change the current shared step id with the newly created shared step in the destination team project if (this.sharedStepsMapping.ContainsKey(currentTestStep.SharedStepId)) { currentTestStep.SharedStepId = this.sharedStepsMapping[currentTestStep.SharedStepId]; } else { // Don't save if the required shared steps are missing shouldCreateTestCase = false; } } } if (shouldCreateTestCase) { TestCase newTestCase = currentSourceTestCase.Save(this.destinationTeamProject, this.destinationPreferences.TestPlan, true, null, currentSourceTestCaseTestSteps, false, isMigration: true); this.testCasesMapping.Add(currentSourceTestCase.ITestCase.Id, newTestCase.ITestCase.Id); this.testCasesMigrationLogManager.Log(currentSourceTestCase.ITestCase.Id, newTestCase.ITestCase.Id, true); infoMessage = String.Format("Test Case Migrated SUCCESSFULLY: Source Id= {0}, Destination Id= {1}", currentSourceTestCase.ITestCase.Id, newTestCase.ITestCase.Id); log.Info(infoMessage); this.ProgressConcurrentQueue.Enqueue(infoMessage); } } catch (Exception ex) { if (currentSourceTestCase != null) { this.testCasesMigrationLogManager.Log(currentSourceTestCase.ITestCase.Id, -1, false, ex.Message); log.Error(ex); this.ProgressConcurrentQueue.Enqueue(ex.Message); } } finally { this.testCasesMigrationLogManager.Save(); this.MigrationTestCasesRetryJsonPath = this.testCasesMigrationLogManager.FullResultFilePath; } } }