/// <summary> /// Loads project settings from registry. /// </summary> public void LoadProjectSettingsFromRegistry(ref TfsTeamProjectCollection tfsTeamProjectCollection, ref ITestManagementTeamProject testManagementTeamProject, ref Preferences preferences, ITestManagementService testService, string selectedTestPlan) { log.Info("Load project info loaded from registry!"); string teamProjectUri = RegistryManager.Instance.GetTeamProjectUri(); string teamProjectName = RegistryManager.Instance.GetTeamProjectName(); string projectDllPath = RegistryManager.Instance.GetProjectDllPath(); if (!string.IsNullOrEmpty(teamProjectUri) && !string.IsNullOrEmpty(teamProjectName)) { preferences.TfsUri = new Uri(teamProjectUri); log.InfoFormat("Registry> TFS URI: {0}", preferences.TfsUri); preferences.TestProjectName = teamProjectName; log.InfoFormat("Registry> Test Project Name: {0}", preferences.TestProjectName); tfsTeamProjectCollection = new TfsTeamProjectCollection(preferences.TfsUri); log.InfoFormat("Registry> TfsTeamProjectCollection: {0}", tfsTeamProjectCollection); testService = (ITestManagementService)tfsTeamProjectCollection.GetService(typeof(ITestManagementService)); testManagementTeamProject = testService.GetTeamProject(preferences.TestProjectName); selectedTestPlan = RegistryManager.Instance.GetTestPlan(); log.InfoFormat("Registry> SelectedTestPlan: {0}", selectedTestPlan); if (!string.IsNullOrEmpty(selectedTestPlan)) { preferences.TestPlan = TestPlanManager.GetTestPlanByName(testManagementTeamProject, selectedTestPlan); this.IsInitializedFromRegistry = true; } } }
/// <summary> /// Loads the project settings from user decision destination. /// </summary> /// <param name="projectPicker">The project picker.</param> public void LoadProjectSettingsFromUserDecisionDestination(TeamProjectPicker projectPicker) { base.LoadProjectSettingsFromUserDecision(projectPicker, ref this.destinationTfsTeamProjectCollection, ref this.destinationTeamProject, ref this.destinationPreferences, this.DestinationTestService, this.SelectedDestinationTestPlan, false); if (this.destinationPreferences.TfsUri != null && this.destinationPreferences != null) { this.DestinationFullTeamProjectName = base.GenerateFullTeamProjectName(this.destinationPreferences.TfsUri.ToString(), this.destinationPreferences.TestProjectName); this.destinationPreferences.TestPlan = TestPlanManager.GetTestPlanByName(this.destinationTeamProject, this.SelectedDestinationTestPlan); base.InitializeTestPlans(this.destinationTeamProject, this.ObservableDestinationTestPlans); if (this.ObservableDestinationTestPlans.Count > 0) { this.SelectedDestinationTestPlan = this.ObservableDestinationTestPlans[0]; } } }
/// <summary> /// Handles the Loaded event of the UserControl control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private void UserControl_Loaded(object sender, RoutedEventArgs e) { if (isInitialized) { return; } this.ShowProgressBar(); this.ProjectSelectionViewModel = new ProjectSelectionViewModel(); bool showTfsServerUnavailableException = false; Task t = Task.Factory.StartNew(() => { this.ProjectSelectionViewModel.LoadProjectSettingsFromRegistry(); try { ProjectSelectionViewModel.InitializeTestPlans(ExecutionContext.TestManagementTeamProject); } catch (Exception) { showTfsServerUnavailableException = true; } }); t.ContinueWith(antecedent => { this.DataContext = this.ProjectSelectionViewModel; isInitialized = true; if (this.ProjectSelectionViewModel.IsInitializedFromRegistry && !this.skipAutoLoad) { if (showTfsServerUnavailableException) { ModernDialog.ShowMessage("Team Foundation services are unavailable and no test plans can be populated. Please try again after few seconds.", "Warning", MessageBoxButton.OK); Application.Current.Shutdown(); } else { if (this.ProjectSelectionViewModel.SelectedTestPlan != null) { ExecutionContext.Preferences.TestPlan = TestPlanManager.GetTestPlanByName(ExecutionContext.TestManagementTeamProject, this.ProjectSelectionViewModel.SelectedTestPlan); } this.AddNewLinksToWindow(); } } else { HideProgressBar(); } }, TaskScheduler.FromCurrentSynchronizationContext()); }
/// <summary> /// Handles the Click event of the DisplayButton control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private void DisplayButton_Click(object sender, RoutedEventArgs e) { this.ProjectSelectionViewModel.SelectedTestPlan = cbTestPlans.Text; if (string.IsNullOrEmpty(this.ProjectSelectionViewModel.SelectedTestPlan)) { ModernDialog.ShowMessage("No test plan selected.", "Warning", MessageBoxButton.OK); return; } if (ExecutionContext.TestManagementTeamProject == null) { ModernDialog.ShowMessage("No test project selected.", "Warning", MessageBoxButton.OK); return; } RegistryManager.WriteCurrentTestPlan(this.ProjectSelectionViewModel.SelectedTestPlan); try { ExecutionContext.Preferences.TestPlan = TestPlanManager.GetTestPlanByName(ExecutionContext.TestManagementTeamProject, this.ProjectSelectionViewModel.SelectedTestPlan); } catch (Exception) { ModernDialog.ShowMessage("Team Foundation services are unavailable and no test plans can be populated. Please try again after few seconds.", "Warning", MessageBoxButton.OK); } this.AddNewLinksToWindow(); }
/// <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; } } }
/// <summary> /// Initializes the selected destination test plan. /// </summary> public void InitializeSelectedDestinationTestPlan() { this.destinationPreferences.TestPlan = TestPlanManager.GetTestPlanByName(this.destinationTeamProject, this.SelectedDestinationTestPlan); }
/// <summary> /// Initializes the selected source test plan. /// </summary> public void InitializeSelectedSourceTestPlan() { this.sourcePreferences.TestPlan = TestPlanManager.GetTestPlanByName(this.sourceTeamProject, this.SelectedSourceTestPlan); }