/// <summary> /// Adds the test cases subsuites. /// </summary> /// <param name="suiteTestCaseCollection">The suite test case collection.</param> public void AddTestCasesSubsuites(List <TestCase> suiteTestCaseCollection) { int selectedSuiteId = RegistryManager.Instance.GetSelectedSuiteId(); if (this.ShowSubSuitesTestCases) { List <TestCase> testCasesList = new List <TestCase>(); ITestSuiteBase currentSuite = TestSuiteManager.GetTestSuiteById(ExecutionContext.TestManagementTeamProject, ExecutionContext.Preferences.TestPlan, selectedSuiteId); if (currentSuite is IStaticTestSuite) { testCasesList = TestCaseManager.GetAllTestCasesFromSuiteCollection(ExecutionContext.Preferences.TestPlan, (currentSuite as IStaticTestSuite).SubSuites); testCasesList.ForEach(x => suiteTestCaseCollection.Add(x)); } } }
/// <summary> /// Filters the suites without suite. /// </summary> public void FilterSuitesWithoutSuite() { if (ExecutionContext.Preferences.TestPlan.RootSuite.SubSuites.FirstOrDefault() == null) { return; } List <TestCase> testCasesWithSuite = TestCaseManager.GetAllTestCasesFromSuiteCollection(ExecutionContext.Preferences.TestPlan, ExecutionContext.Preferences.TestPlan.RootSuite.SubSuites); List <TestCase> filteredTestCases = new List <TestCase>(); foreach (TestCase currentTestCase in this.ObservableTestCases) { if (!testCasesWithSuite.Contains(currentTestCase)) { filteredTestCases.Add(currentTestCase); } } this.InitialTestCaseCollection.Clear(); filteredTestCases.ForEach(x => this.InitialTestCaseCollection.Add(x)); }
/// <summary> /// Adds the new test cases to new suites destination. /// </summary> public void AddNewTestCasesToNewSuitesDestinationInternal() { if (!string.IsNullOrEmpty(this.MigrationAddTestCasesToSuitesRetryJsonPath) && File.Exists(this.MigrationAddTestCasesToSuitesRetryJsonPath)) { this.testCasesAddToSuitesMigrationLogManager = new MigrationLogManager(this.MigrationAddTestCasesToSuitesRetryJsonPath); this.testCasesAddToSuitesMigrationLogManager.LoadCollectionFromExistingFile(); this.sharedStepsMapping = this.testCasesAddToSuitesMigrationLogManager.GetProssedItemsMappings(); } else { this.testCasesAddToSuitesMigrationLogManager = new MigrationLogManager("testCasesToSuites", this.DefaultJsonFolder); } this.ProgressConcurrentQueue.Enqueue("Prepare destination test cases..."); ITestPlan destinationTestPlan = TestPlanManager.GetTestPlanByName(this.destinationTeamProject, this.SelectedDestinationTestPlan); List <TestCase> destinationTestCases = TestCaseManager.GetAllTestCasesInTestPlan(this.destinationTeamProject, destinationTestPlan, false); 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); foreach (TestCase currentSourceTestCase in sourceTestCases) { if (this.executionCancellationToken.IsCancellationRequested) { break; } // If it's already processed skip it if (this.testCasesAddToSuitesMigrationLogManager.MigrationEntries.Count(e => e.SourceId.Equals(currentSourceTestCase.ITestCase.Id) && e.IsProcessed.Equals(true)) > 0) { continue; } if (currentSourceTestCase.ITestSuiteBase != null && this.ObservableSuitesToBeSkipped.Count(t => t != null && t.NewText != null && t.NewText.Equals(currentSourceTestCase.ITestSuiteBase.Title)) > 0) { continue; } string infoMessage = String.Empty; try { infoMessage = String.Format("Start Adding to Suite Test Case with Source Id= {0}", currentSourceTestCase.Id); log.Info(infoMessage); this.ProgressConcurrentQueue.Enqueue(infoMessage); if (currentSourceTestCase.ITestSuiteBase == null) { continue; } else { int sourceParentSuiteId = currentSourceTestCase.ITestSuiteBase.Id; if (!this.suitesMapping.ContainsKey(sourceParentSuiteId)) { return; } else { int destinationSuiteId = this.suitesMapping[sourceParentSuiteId]; ITestSuiteBase destinationSuite = this.destinationTeamProject.TestSuites.Find(destinationSuiteId); if (this.testCasesMapping.ContainsKey(currentSourceTestCase.ITestCase.Id)) { TestCase currentDestinationTestCase = destinationTestCases.FirstOrDefault(t => t.Id.Equals(this.testCasesMapping[currentSourceTestCase.ITestCase.Id])); destinationSuite.AddTestCase(currentDestinationTestCase.ITestCase); this.testCasesAddToSuitesMigrationLogManager.Log(currentSourceTestCase.ITestCase.Id, destinationSuite.Id, true); infoMessage = String.Format("Test Case SUCCESSFULLY added to Suite: Test Case Id= {0}, Suite Id= {1}", currentDestinationTestCase.ITestCase.Id, destinationSuite.Id); log.Info(infoMessage); this.ProgressConcurrentQueue.Enqueue(infoMessage); } } } } catch (Exception ex) { if (currentSourceTestCase != null) { this.testCasesAddToSuitesMigrationLogManager.Log(currentSourceTestCase.ITestCase.Id, -1, false, ex.Message); log.Error(ex); this.ProgressConcurrentQueue.Enqueue(ex.Message); } } finally { this.testCasesAddToSuitesMigrationLogManager.Save(); this.MigrationAddTestCasesToSuitesRetryJsonPath = this.testCasesAddToSuitesMigrationLogManager.FullResultFilePath; } } }
/// <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; } } }