/// <summary>
        /// Migrates the shared steps from source to destination.
        /// </summary>
        private void MigrateSharedStepsFromSourceToDestinationInternal()
        {
            if (!string.IsNullOrEmpty(this.MigrationSharedStepsRetryJsonPath) && File.Exists(this.MigrationSharedStepsRetryJsonPath))
            {
                this.sharedStepsMigrationLogManager = new MigrationLogManager(this.MigrationSharedStepsRetryJsonPath);
                this.sharedStepsMigrationLogManager.LoadCollectionFromExistingFile();
                this.sharedStepsMapping = this.sharedStepsMigrationLogManager.GetProssedItemsMappings();
            }
            else
            {
                this.sharedStepsMigrationLogManager = new MigrationLogManager("sharedSteps", this.DefaultJsonFolder);
            }

            List <SharedStep> sourceSharedSteps = SharedStepManager.GetAllSharedStepsInTestPlan(this.sourceTeamProject);

            foreach (SharedStep currentSourceSharedStep in sourceSharedSteps)
            {
                if (this.executionCancellationToken.IsCancellationRequested)
                {
                    break;
                }

                // If it's already processed skip it
                if (this.sharedStepsMigrationLogManager.MigrationEntries.Count(e => e.SourceId.Equals(currentSourceSharedStep.ISharedStep.Id) && e.IsProcessed.Equals(true)) > 0)
                {
                    continue;
                }
                string infoMessage = String.Empty;
                try
                {
                    infoMessage = String.Format("Start Migrating Shared Step with Source Id= {0}", currentSourceSharedStep.Id);
                    log.Info(infoMessage);
                    this.ProgressConcurrentQueue.Enqueue(infoMessage);

                    List <TestStep> testSteps     = TestStepManager.GetTestStepsFromTestActions(this.sourceTeamProject, currentSourceSharedStep.ISharedStep.Actions);
                    SharedStep      newSharedStep = currentSourceSharedStep.Save(this.destinationTeamProject, true, testSteps, false);
                    newSharedStep.ISharedStep.Refresh();
                    this.sharedStepsMapping.Add(currentSourceSharedStep.ISharedStep.Id, newSharedStep.ISharedStep.Id);

                    this.sharedStepsMigrationLogManager.Log(currentSourceSharedStep.Id, newSharedStep.ISharedStep.Id, true);
                    infoMessage = String.Format("Shared Step Migrated SUCCESSFULLY: Source Id= {0}, Destination Id= {1}", currentSourceSharedStep.Id, newSharedStep.ISharedStep.Id);
                    log.Info(infoMessage);
                    this.ProgressConcurrentQueue.Enqueue(infoMessage);
                }
                catch (Exception ex)
                {
                    this.sharedStepsMigrationLogManager.Log(currentSourceSharedStep.Id, -1, false, ex.Message);
                    log.Error(ex);
                    this.ProgressConcurrentQueue.Enqueue(ex.Message);
                }
                finally
                {
                    this.sharedStepsMigrationLogManager.Save();
                    this.MigrationSharedStepsRetryJsonPath = this.sharedStepsMigrationLogManager.FullResultFilePath;
                }
            }
            this.IsSharedStepsMigrationFinished = true;
        }
Exemple #2
0
        /// <summary>
        /// Gets all full test cases for observable test cases.
        /// </summary>
        /// <param name="testPlan">The test plan.</param>
        /// <param name="selectedTestCases">The selected test cases.</param>
        /// <returns>
        /// list of full test cases
        /// </returns>
        private List <TestCaseFull> GetAllFullTestCasesForObservableTestCases(List <TestCase> selectedTestCases)
        {
            List <TestCaseFull> fullTestCases = new List <TestCaseFull>();

            foreach (TestCase currentTestCase in selectedTestCases)
            {
                string          mostRecentResult = TestCaseManager.GetMostRecentTestCaseResult(ExecutionContext.Preferences.TestPlan, currentTestCase.Id);
                string          executionComment = TestCaseManager.GetMostRecentExecutionComment(ExecutionContext.Preferences.TestPlan, currentTestCase.Id);
                List <TestStep> currentTestSteps = TestStepManager.GetTestStepsFromTestActions(ExecutionContext.TestManagementTeamProject, currentTestCase.ITestCase.Actions);
                fullTestCases.Add(new TestCaseFull(currentTestCase, currentTestSteps, mostRecentResult, executionComment));
            }

            return(fullTestCases);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TestCaseDetailedViewModel"/> class.
        /// </summary>
        /// <param name="testCaseId">The test case unique identifier.</param>
        /// <param name="suiteId">The suite unique identifier.</param>
        public TestCaseDetailedViewModel(int testCaseId, int suiteId)
        {
            ITestCase      testCaseCore      = ExecutionContext.TestManagementTeamProject.TestCases.Find(testCaseId);
            ITestSuiteBase testSuiteBaseCore = null;

            if (suiteId != -1)
            {
                testSuiteBaseCore = ExecutionContext.TestManagementTeamProject.TestSuites.Find(suiteId);
            }

            this.TestCase    = new TestCase(testCaseCore, testSuiteBaseCore, ExecutionContext.Preferences.TestPlan);
            this.TestActions = new List <ITestAction>();
            this.TestCase.ITestCase.Actions.ToList().ForEach(x => this.TestActions.Add(x));
            this.ObservableTestSteps = new ObservableCollection <TestStep>();
            List <TestStep> testSteps = TestStepManager.GetTestStepsFromTestActions(ExecutionContext.TestManagementTeamProject, this.TestActions);

            this.AssociatedAutomation = this.TestCase.ITestCase.GetAssociatedAutomation();
            TestStepManager.UpdateGenericSharedSteps(testSteps);
            this.InitializeTestSteps(testSteps);
        }
Exemple #4
0
        /// <summary>
        /// Finds the and replace information test case/shared step.
        /// </summary>
        /// <param name="entityToReplaceIn">The test case/shared step to replace in.</param>
        private void FindAndReplaceInEntityInternal(Object entityToReplaceIn)
        {
            TestCase   currentTestCase   = null;
            SharedStep currentSharedStep = null;

            if (entityToReplaceIn is TestCase)
            {
                currentTestCase           = entityToReplaceIn as TestCase;
                currentTestCase.ITestCase = ExecutionContext.TestManagementTeamProject.TestCases.Find(currentTestCase.ITestCase.Id);
                log.InfoFormat("Find and Replace in test case with Title= \"{0}\" id= \"{1}\"", currentTestCase.Title, currentTestCase.Id);
                List <TestStep> testSteps = TestStepManager.GetTestStepsFromTestActions(ExecutionContext.TestManagementTeamProject, currentTestCase.ITestCase.Actions.ToList());
                this.ReplaceTestCaseTitle(currentTestCase);
                this.ChangeTestCasePriority(currentTestCase);
                this.ChangeTestCaseOwner(currentTestCase);
                this.ReplaceStepsInTestCase(currentTestCase, testSteps);

                currentTestCase.ITestCase.Actions.Add(currentTestCase.ITestCase.CreateTestStep());
                currentTestCase.ITestCase.Flush();
                currentTestCase.ITestCase.Save();

                currentTestCase.ITestCase.Actions.RemoveAt(currentTestCase.ITestCase.Actions.Count - 1);
                currentTestCase.ITestCase.Save();
            }
            else
            {
                currentSharedStep             = entityToReplaceIn as SharedStep;
                currentSharedStep.ISharedStep = ExecutionContext.TestManagementTeamProject.SharedSteps.Find(currentSharedStep.ISharedStep.Id);
                log.InfoFormat("Find and Replace in shared step with Title= \"{0}\" id= \"{1}\"", currentSharedStep.Title, currentSharedStep.Id);
                List <TestStep> testSteps = TestStepManager.GetTestStepsFromTestActions(ExecutionContext.TestManagementTeamProject, currentSharedStep.ISharedStep.Actions.ToList());
                this.ReplaceSharedStepTitle(currentSharedStep);
                this.ChangeSharedStepPriority(currentSharedStep);
                this.ChangeSharedStepOwner(currentSharedStep);
                this.ReplaceStepsInSharedStep(currentSharedStep, testSteps);

                currentSharedStep.ISharedStep.Actions.Add(currentSharedStep.ISharedStep.CreateTestStep());
                currentSharedStep.ISharedStep.Flush();
                currentSharedStep.ISharedStep.Save();
                currentSharedStep.ISharedStep.Actions.RemoveAt(currentSharedStep.ISharedStep.Actions.Count - 1);
                currentSharedStep.ISharedStep.Save();
            }
        }
Exemple #5
0
        /// <summary>
        /// Duplicates the test case/shared Step.
        /// </summary>
        /// <param name="entityToBeDuplicated">The test case/shared step to be duplicated.</param>
        private void DuplicateEntityInternal(Object entityToBeDuplicated)
        {
            SharedStep currentSharedStep = null;

            if (entityToBeDuplicated is TestCase)
            {
                TestCase  testCaseToBeDuplicated = entityToBeDuplicated as TestCase;
                ITestCase testCaseCore           = ExecutionContext.TestManagementTeamProject.TestCases.Create();
                TestCase  currentTestCase        = new TestCase(testCaseCore, testCaseToBeDuplicated.ITestSuiteBase, ExecutionContext.Preferences.TestPlan);
                currentTestCase.ITestCase.Area  = testCaseToBeDuplicated.ITestCase.Area;
                currentTestCase.ITestCase.Title = testCaseToBeDuplicated.ITestCase.Title;
                //currentTestCase.ITestCase = ExecutionContext.TestManagementTeamProject.TestCases.Find(currentTestCase.ITestCase.Id);
                log.InfoFormat("Duplicate test case with Title= \"{0}\" id= \"{1}\"", currentTestCase.Title, currentTestCase.Id);
                List <TestStep> testSteps = TestStepManager.GetTestStepsFromTestActions(ExecutionContext.TestManagementTeamProject, testCaseToBeDuplicated.ITestCase.Actions.ToList());
                this.ReplaceTestCaseTitle(currentTestCase);
                this.ChangeTestCasePriority(currentTestCase);
                this.ChangeTestCaseOwner(currentTestCase);
                this.ReplaceStepsInTestCase(currentTestCase, testSteps);

                currentTestCase.ITestCase.Flush();
                currentTestCase.ITestCase.Save();
                this.AddTestCaseToSuite(currentTestCase);
            }
            else
            {
                SharedStep  sharedStepToBeDuplicated = entityToBeDuplicated as SharedStep;
                ISharedStep sharedStepCore           = ExecutionContext.TestManagementTeamProject.SharedSteps.Create();
                currentSharedStep = new SharedStep(sharedStepCore);
                currentSharedStep.ISharedStep.Area = sharedStepToBeDuplicated.ISharedStep.Area;
                log.InfoFormat("Duplicate shared step with Title= \"{0}\" id= \"{1}\"", currentSharedStep.Title, currentSharedStep.Id);
                List <TestStep> testSteps = TestStepManager.GetTestStepsFromTestActions(ExecutionContext.TestManagementTeamProject, currentSharedStep.ISharedStep.Actions.ToList());
                this.ReplaceSharedStepTitle(currentSharedStep);
                this.ChangeSharedStepPriority(currentSharedStep);
                this.ChangeSharedStepOwner(currentSharedStep);
                this.ReplaceStepsInSharedStep(currentSharedStep, testSteps);

                currentSharedStep.ISharedStep.Flush();
                currentSharedStep.ISharedStep.Save();
            }
        }
        /// <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 test case test steps from attribute test case actions.
        /// </summary>
        private void InitializeTestCaseTestStepsFromITestCaseActions()
        {
            List <TestStep> testSteps = TestStepManager.GetTestStepsFromTestActions(TestCaseManagerCore.ExecutionContext.TestManagementTeamProject, this.TestCase.ITestCase.Actions);

            this.AddTestStepsToObservableCollection(testSteps);
        }