/// <summary>
        /// Gets the shared step by unique identifier.
        /// </summary>
        /// <param name="sharedStepId">The shared step unique identifier.</param>
        /// <returns></returns>
        public static SharedStep GetSharedStepById(ITestManagementTeamProject testManagementTeamProject, int sharedStepId)
        {
            ISharedStep sharedStepCore    = testManagementTeamProject.SharedSteps.Find(sharedStepId);
            SharedStep  currentSharedStep = new SharedStep(sharedStepCore);

            return(currentSharedStep);
        }
        /// <summary>
        /// Saves the specified shared step.
        /// </summary>
        /// <param name="sharedStep">The shared step.</param>
        /// <param name="createNew">if set to <c>true</c> [create new].</param>
        /// <param name="newSuiteTitle">The new suite title.</param>
        /// <param name="testSteps">The test steps.</param>
        /// <returns></returns>
        public static SharedStep Save(this SharedStep sharedStep, ITestManagementTeamProject testManagementTeamProject, bool createNew, ICollection <TestStep> testSteps, bool shouldSetArea = true)
        {
            SharedStep currentSharedStep = sharedStep;

            if (createNew)
            {
                ISharedStep sharedStepCore = testManagementTeamProject.SharedSteps.Create();
                currentSharedStep = new SharedStep(sharedStepCore);
            }
            if (shouldSetArea)
            {
                currentSharedStep.ISharedStep.Area = sharedStep.Area;
            }
            currentSharedStep.ISharedStep.Title    = sharedStep.Title;
            currentSharedStep.ISharedStep.Priority = (int)sharedStep.Priority;
            currentSharedStep.ISharedStep.Actions.Clear();
            currentSharedStep.ISharedStep.Owner = testManagementTeamProject.TfsIdentityStore.FindByTeamFoundationId(sharedStep.TeamFoundationId);
            List <Guid> addedSharedStepGuids = new List <Guid>();

            foreach (TestStep currentStep in testSteps)
            {
                ITestStep testStepCore = currentSharedStep.ISharedStep.CreateTestStep();
                testStepCore.Title          = currentStep.ActionTitle;
                testStepCore.ExpectedResult = currentStep.ActionExpectedResult;
                currentSharedStep.ISharedStep.Actions.Add(testStepCore);
            }
            currentSharedStep.ISharedStep.Flush();
            currentSharedStep.ISharedStep.Save();

            return(currentSharedStep);
        }
Beispiel #3
0
        /// <summary>
        /// Edits the current entity internal.
        /// </summary>
        private void EditCurrentEntityInternal()
        {
            if (this.dgTestCases.SelectedItem == null)
            {
                return;
            }

            if (this.dgTestCases.SelectedItem is TestCase)
            {
                TestCase currentTestCase = this.dgTestCases.SelectedItem as TestCase;
                if (currentTestCase.ITestSuiteBase != null)
                {
                    log.InfoFormat("Edit test case with id: {0} and suite id {1}", currentTestCase.ITestCase.Id, currentTestCase.ITestSuiteBase.Id);
                    Navigator.Instance.NavigateToTestCasesEditView(this, currentTestCase.ITestCase.Id, currentTestCase.ITestSuiteBase.Id);
                }
                else
                {
                    log.InfoFormat("Edit test case with id: {0}", currentTestCase.ITestCase.Id);
                    Navigator.Instance.NavigateToTestCasesEditView(this, currentTestCase.ITestCase.Id, -1);
                }
            }
            else
            {
                SharedStep currentSharedStep = this.dgTestCases.SelectedItem as SharedStep;
                log.InfoFormat("Edit Shared Step with id: {0} ", currentSharedStep.ISharedStep.Id);
                Navigator.Instance.NavigateToTestCasesEditView(this, true, currentSharedStep.ISharedStep.Id);
            }
        }
        /// <summary>
        /// Saves the specified shared step.
        /// </summary>
        /// <param name="sharedStep">The shared step.</param>
        /// <param name="createNew">if set to <c>true</c> [create new].</param>
        /// <param name="newSuiteTitle">The new suite title.</param>
        /// <param name="testSteps">The test steps.</param>
        /// <returns></returns>
        public static SharedStep Save(this SharedStep sharedStep, ITestManagementTeamProject testManagementTeamProject, bool createNew, ICollection<TestStep> testSteps, bool shouldSetArea = true)
        {
            SharedStep currentSharedStep = sharedStep;
            if (createNew)
            {
                ISharedStep sharedStepCore = testManagementTeamProject.SharedSteps.Create();
                currentSharedStep = new SharedStep(sharedStepCore);
            }
            if (shouldSetArea)
            {
                currentSharedStep.ISharedStep.Area = sharedStep.Area;
            }
            currentSharedStep.ISharedStep.Title = sharedStep.Title;
            currentSharedStep.ISharedStep.Priority = (int)sharedStep.Priority;
            currentSharedStep.ISharedStep.Actions.Clear();
            currentSharedStep.ISharedStep.Owner = testManagementTeamProject.TfsIdentityStore.FindByTeamFoundationId(sharedStep.TeamFoundationId);
            List<Guid> addedSharedStepGuids = new List<Guid>();
            foreach (TestStep currentStep in testSteps)
            {
                ITestStep testStepCore = currentSharedStep.ISharedStep.CreateTestStep();
                testStepCore.Title = currentStep.ActionTitle;
                testStepCore.ExpectedResult = currentStep.ActionExpectedResult;
                currentSharedStep.ISharedStep.Actions.Add(testStepCore);
            }
            currentSharedStep.ISharedStep.Flush();
            currentSharedStep.ISharedStep.Save();

            return currentSharedStep;
        }
        /// <summary>
        /// Gets the shared step by unique identifier.
        /// </summary>
        /// <param name="sharedStepId">The shared step unique identifier.</param>
        /// <returns></returns>
        public static SharedStep GetSharedStepById(ITestManagementTeamProject testManagementTeamProject, int sharedStepId)
        {
            ISharedStep sharedStepCore = testManagementTeamProject.SharedSteps.Find(sharedStepId);
            SharedStep currentSharedStep = new SharedStep(sharedStepCore);

            return currentSharedStep;
        }
Beispiel #6
0
        /// <summary>
        /// Replaces the steps information shared step.
        /// </summary>
        /// <param name="sharedStep">The shared step.</param>
        /// <param name="testSteps">The test steps.</param>
        private void ReplaceStepsInSharedStep(SharedStep sharedStep, List <TestStep> testSteps)
        {
            if (this.ReplaceContext.ReplaceInTestSteps)
            {
                sharedStep.ISharedStep.Actions.Clear();
                List <Guid> addedSharedStepGuids = new List <Guid>();

                foreach (TestStep currentStep in testSteps)
                {
                    ITestStep testStepCore = sharedStep.ISharedStep.CreateTestStep();
                    if (this.ReplaceContext.ReplaceInTestSteps)
                    {
                        string newActionTitle = currentStep.ActionTitle.ToString().ReplaceAll(this.ReplaceContext.ObservableTextReplacePairs);
                        log.InfoFormat("Change Test step action title from \"{0}\" to \"{1}\"", currentStep.ActionTitle, newActionTitle);
                        testStepCore.Title = newActionTitle;
                        string newActionexpectedResult = currentStep.ActionExpectedResult.ToString().ReplaceAll(this.ReplaceContext.ObservableTextReplacePairs);
                        log.InfoFormat("Change Test step action expected result from \"{0}\" to \"{1}\"", currentStep.ActionExpectedResult, newActionexpectedResult);
                        testStepCore.ExpectedResult = newActionexpectedResult;
                    }
                    else
                    {
                        testStepCore.Title          = currentStep.ActionTitle;
                        testStepCore.ExpectedResult = currentStep.ActionExpectedResult;
                    }
                    sharedStep.ISharedStep.Actions.Add(testStepCore);
                }
            }
        }
 /// <summary>
 /// Handles the KeyDown event of the dgTestCases control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.Windows.Input.KeyEventArgs"/> instance containing the event data.</param>
 private void dgSharedSteps_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
 {
     if (Keyboard.IsKeyDown(Key.Enter))
     {
         SharedStep currentSharedStep = dgSharedSteps.SelectedItem as SharedStep;
         this.NavigateToTestCasesEditView(true, currentSharedStep.ISharedStep.Id);
     }
 }
        /// <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;
        }
 /// <summary>
 /// Handles the Click event of the DuplicateButton 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 btnDuplicate_Click(object sender, RoutedEventArgs e)
 {
     this.ValidateSharedStepsSelection(() =>
     {
         SharedStep currentSharedStep = dgSharedSteps.SelectedItem as SharedStep;
         log.InfoFormat("Duplicate Shared Step with id: {0} ", currentSharedStep.ISharedStep.Id);
         this.NavigateToTestCasesEditView(true, currentSharedStep.ISharedStep.Id, true, true);
     });
 }
Beispiel #10
0
 private void ChangeSharedStepPriority(SharedStep currentSharedStep)
 {
     if (this.ReplaceContext.ChangePriorities)
     {
         log.InfoFormat("Change Priority from \"{0}\" to \"{1}\"", currentSharedStep.ISharedStep.Priority, (int)this.ReplaceContext.SelectedPriority);
         currentSharedStep.ISharedStep.Priority = (int)this.ReplaceContext.SelectedPriority;
         currentSharedStep.Priority             = this.ReplaceContext.SelectedPriority;
     }
 }
 /// <summary>
 /// Handles the Click event of the EditButton 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 btnEdit_Click(object sender, RoutedEventArgs e)
 {
     this.ValidateSharedStepsSelection(() =>
     {
         SharedStep currentSharedStep = this.dgSharedSteps.SelectedItem as SharedStep;
         log.InfoFormat("Edit Shared Step with id: {0} ", currentSharedStep.ISharedStep.Id);
         Navigator.Instance.NavigateToTestCasesEditView(this, true, currentSharedStep.ISharedStep.Id);
     });
 }
 /// <summary>
 /// Edits the test case internal.
 /// </summary>
 private void EditTestCaseInternal()
 {
     if (dgSharedSteps.SelectedItem != null)
     {
         SharedStep currentSharedStep = dgSharedSteps.SelectedItem as SharedStep;
         log.InfoFormat("Edit Shared Step with id: {0} ", currentSharedStep.ISharedStep.Id);
         this.NavigateToTestCasesEditView(true, currentSharedStep.ISharedStep.Id);
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="TestCaseEditViewModel"/> class.
        /// </summary>
        /// <param name="editViewContext">The edit view context.</param>
        public TestCaseEditViewModel(EditViewContext editViewContext)
        {
            this.EditViewContext     = editViewContext;
            this.Areas               = this.GetProjectAreas();
            this.ObservableTestSteps = new ObservableCollection <TestStep>();
            this.GenericParameters   = new Dictionary <string, Dictionary <string, string> >();
            if (!this.EditViewContext.IsSharedStep)
            {
                this.ShowTestCaseSpecificFields = true;
                ITestSuiteBase testSuiteBaseCore = null;
                if (this.EditViewContext.TestSuiteId != -1)
                {
                    testSuiteBaseCore = TestSuiteManager.GetTestSuiteById(TestCaseManagerCore.ExecutionContext.TestManagementTeamProject, TestCaseManagerCore.ExecutionContext.Preferences.TestPlan, this.EditViewContext.TestSuiteId);
                }
                if (this.EditViewContext.CreateNew && !this.EditViewContext.Duplicate)
                {
                    ITestCase newTestCase = TestCaseManagerCore.ExecutionContext.TestManagementTeamProject.TestCases.Create();
                    this.TestCase = new TestCase(newTestCase, testSuiteBaseCore, TestCaseManagerCore.ExecutionContext.Preferences.TestPlan, false);
                }
                else
                {
                    ITestCase testCaseCore = TestCaseManagerCore.ExecutionContext.TestManagementTeamProject.TestCases.Find(this.EditViewContext.TestCaseId);
                    this.TestCase = new TestCase(testCaseCore, testSuiteBaseCore, TestCaseManagerCore.ExecutionContext.Preferences.TestPlan, false);
                }
                this.ObservableSharedSteps = new ObservableCollection <SharedStep>();
                this.InitializeObservableSharedSteps();
                this.InitializeInitialSharedStepCollection();
                this.InitializeTestCaseTestStepsFromITestCaseActions();
                this.AssociatedAutomation = this.TestCase.ITestCase.GetAssociatedAutomation();
                this.TestBase             = this.TestCase;
            }
            else
            {
                if (this.EditViewContext.CreateNew && !this.EditViewContext.Duplicate)
                {
                    ISharedStep currentSharedStepCore = TestCaseManagerCore.ExecutionContext.TestManagementTeamProject.SharedSteps.Create();
                    this.SharedStep = new SharedStep(currentSharedStepCore);
                }
                else
                {
                    SharedStep currentSharedStep = SharedStepManager.GetSharedStepById(TestCaseManagerCore.ExecutionContext.TestManagementTeamProject, this.EditViewContext.SharedStepId);
                    this.SharedStep = currentSharedStep;
                }

                List <TestStep> innerTestSteps = TestStepManager.GetAllTestStepsInSharedStep(this.SharedStep.ISharedStep, false);
                this.AddTestStepsToObservableCollection(innerTestSteps);
                this.ShowTestCaseSpecificFields = false;
                this.TestBase = this.SharedStep;
                this.ClearTestStepNames();
            }
            this.InitializeIdLabelFromTestBase(this.EditViewContext.CreateNew, this.EditViewContext.Duplicate);
            this.InitializePageTitle();
            log.InfoFormat("Load Edit View with Context: {0} ", editViewContext);

            TestStepManager.UpdateGenericSharedSteps(this.ObservableTestSteps);
        }
Beispiel #14
0
 /// <summary>
 /// Changes the shared step owner.
 /// </summary>
 /// <param name="currentSharedStep">The current shared step.</param>
 private void ChangeSharedStepOwner(SharedStep currentSharedStep)
 {
     if (this.ReplaceContext.ChangeOwner && this.ReplaceContext.SelectedTeamFoundationIdentityName != null)
     {
         var identity = ExecutionContext.TestManagementTeamProject.TfsIdentityStore.FindByTeamFoundationId(this.ReplaceContext.SelectedTeamFoundationIdentityName.TeamFoundationId);
         log.InfoFormat("Change Owner from \"{0}\" to \"{1}\"", currentSharedStep.ISharedStep.Owner.DisplayName, identity.DisplayName);
         currentSharedStep.ISharedStep.Owner          = identity;
         currentSharedStep.TeamFoundationIdentityName = new TeamFoundationIdentityName(identity.TeamFoundationId, identity.DisplayName);
     }
 }
        /// <summary>
        /// Gets all shared steps information test plan.
        /// </summary>
        /// <returns></returns>
        public static List<SharedStep> GetAllSharedStepsInTestPlan(ITestManagementTeamProject testManagementTeamProject)
        {
            List<SharedStep> sharedSteps = new List<SharedStep>();
            var testPlanSharedStepsCore = testManagementTeamProject.SharedSteps.Query("SELECT * FROM WorkItems WHERE [System.TeamProject] = @project and [System.WorkItemType] = 'Shared Steps'");
            foreach (ISharedStep currentSharedStepCore in testPlanSharedStepsCore)
            {
                SharedStep currentSharedStep = new SharedStep(currentSharedStepCore);
                sharedSteps.Add(currentSharedStep);
            }

            return sharedSteps;
        }
        /// <summary>
        /// Gets all shared steps information test plan.
        /// </summary>
        /// <returns></returns>
        public static List <SharedStep> GetAllSharedStepsInTestPlan(ITestManagementTeamProject testManagementTeamProject)
        {
            List <SharedStep> sharedSteps = new List <SharedStep>();
            var testPlanSharedStepsCore   = testManagementTeamProject.SharedSteps.Query("SELECT * FROM WorkItems WHERE [System.TeamProject] = @project and [System.WorkItemType] = 'Shared Steps'");

            foreach (ISharedStep currentSharedStepCore in testPlanSharedStepsCore)
            {
                SharedStep currentSharedStep = new SharedStep(currentSharedStepCore);
                sharedSteps.Add(currentSharedStep);
            }

            return(sharedSteps);
        }
Beispiel #17
0
 /// <summary>
 /// Replaces the shared step title.
 /// </summary>
 /// <param name="currentSharedStep">The current shared step.</param>
 private void ReplaceSharedStepTitle(SharedStep currentSharedStep)
 {
     if (this.ReplaceContext.ReplaceInTitles)
     {
         string newTitle = currentSharedStep.ISharedStep.Title.ReplaceAll(this.ReplaceContext.ObservableTextReplacePairs);
         if (newTitle.Length > 255)
         {
             return;
         }
         log.InfoFormat("Change Title from \"{0}\" to \"{1}\"", currentSharedStep.ISharedStep.Title, newTitle);
         currentSharedStep.ISharedStep.Title = newTitle;
         currentSharedStep.Title             = newTitle;
     }
 }
        /// <summary>
        /// Inserts the new shared step.
        /// </summary>
        /// <param name="currentSharedStep">The current shared step.</param>
        /// <param name="selectedIndex">Index of the selected test step.</param>
        /// <returns>return the index of the last inserted step</returns>
        public int InsertSharedStep(SharedStep currentSharedStep, int selectedIndex)
        {
            List <TestStep> innerTestSteps = TestStepManager.GetAllTestStepsInSharedStep(currentSharedStep.ISharedStep);

            log.InfoFormat("Insert Shared Step Title= {0}, SelectedIndex= {1}", currentSharedStep.Title, selectedIndex);
            int j = 0;
            int finalInsertedStepIndex = 0;

            for (int i = selectedIndex; i < innerTestSteps.Count + selectedIndex; i++)
            {
                finalInsertedStepIndex = this.InsertTestStepInTestCase(innerTestSteps[j], i, false);
                j++;
            }

            return(finalInsertedStepIndex);
        }
Beispiel #19
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();
            }
        }
Beispiel #20
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>
        /// Replaces the steps information shared step.
        /// </summary>
        /// <param name="sharedStep">The shared step.</param>
        /// <param name="testSteps">The test steps.</param>
        private void ReplaceStepsInSharedStep(SharedStep sharedStep, List<TestStep> testSteps)
        {
            if (this.ReplaceContext.ReplaceInTestSteps)
            {
                sharedStep.ISharedStep.Actions.Clear();
                List<Guid> addedSharedStepGuids = new List<Guid>();

                foreach (TestStep currentStep in testSteps)
                {
                    ITestStep testStepCore = sharedStep.ISharedStep.CreateTestStep();
                    if (this.ReplaceContext.ReplaceInTestSteps)
                    {
                        string newActionTitle = currentStep.ActionTitle.ToString().ReplaceAll(this.ReplaceContext.ObservableTextReplacePairs);
                        log.InfoFormat("Change Test step action title from \"{0}\" to \"{1}\"", currentStep.ActionTitle, newActionTitle);
                        testStepCore.Title = newActionTitle;
                        string newActionexpectedResult = currentStep.ActionExpectedResult.ToString().ReplaceAll(this.ReplaceContext.ObservableTextReplacePairs);
                        log.InfoFormat("Change Test step action expected result from \"{0}\" to \"{1}\"", currentStep.ActionExpectedResult, newActionexpectedResult);
                        testStepCore.ExpectedResult = newActionexpectedResult;
                    }
                    else
                    {
                        testStepCore.Title = currentStep.ActionTitle;
                        testStepCore.ExpectedResult = currentStep.ActionExpectedResult;
                    }
                    sharedStep.ISharedStep.Actions.Add(testStepCore);
                }
            }
        }
 private void ChangeSharedStepPriority(SharedStep currentSharedStep)
 {
     if (this.ReplaceContext.ChangePriorities)
     {
         log.InfoFormat("Change Priority from \"{0}\" to \"{1}\"", currentSharedStep.ISharedStep.Priority, (int)this.ReplaceContext.SelectedPriority);
         currentSharedStep.ISharedStep.Priority = (int)this.ReplaceContext.SelectedPriority;
         currentSharedStep.Priority = this.ReplaceContext.SelectedPriority;
     }
 }
 /// <summary>
 /// Changes the shared step owner.
 /// </summary>
 /// <param name="currentSharedStep">The current shared step.</param>
 private void ChangeSharedStepOwner(SharedStep currentSharedStep)
 {
     if (this.ReplaceContext.ChangeOwner && this.ReplaceContext.SelectedTeamFoundationIdentityName != null)
     {
         var identity = ExecutionContext.TestManagementTeamProject.TfsIdentityStore.FindByTeamFoundationId(this.ReplaceContext.SelectedTeamFoundationIdentityName.TeamFoundationId);
         log.InfoFormat("Change Owner from \"{0}\" to \"{1}\"", currentSharedStep.ISharedStep.Owner.DisplayName, identity.DisplayName);
         currentSharedStep.ISharedStep.Owner = identity;
         currentSharedStep.TeamFoundationIdentityName = new TeamFoundationIdentityName(identity.TeamFoundationId, identity.DisplayName);
     }
 }
 /// <summary>
 /// Replaces the shared step title.
 /// </summary>
 /// <param name="currentSharedStep">The current shared step.</param>
 private void ReplaceSharedStepTitle(SharedStep currentSharedStep)
 {
     if (this.ReplaceContext.ReplaceInTitles)
     { 
         string newTitle = currentSharedStep.ISharedStep.Title.ReplaceAll(this.ReplaceContext.ObservableTextReplacePairs);
         if (newTitle.Length > 255)
         {
             return;
         }
         log.InfoFormat("Change Title from \"{0}\" to \"{1}\"", currentSharedStep.ISharedStep.Title, newTitle);
         currentSharedStep.ISharedStep.Title = newTitle;
         currentSharedStep.Title = newTitle;
     }
 }
        /// <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>
        /// Inserts the new shared step.
        /// </summary>
        /// <param name="currentSharedStep">The current shared step.</param>
        /// <param name="selectedIndex">Index of the selected test step.</param>
        /// <returns>return the index of the last inserted step</returns>
        public int InsertSharedStep(SharedStep currentSharedStep, int selectedIndex)
        {
            List<TestStep> innerTestSteps = TestStepManager.GetAllTestStepsInSharedStep(currentSharedStep.ISharedStep);
            log.InfoFormat("Insert Shared Step Title= {0}, SelectedIndex= {1}", currentSharedStep.Title, selectedIndex);
            int j = 0;
            int finalInsertedStepIndex = 0;
            for (int i = selectedIndex; i < innerTestSteps.Count + selectedIndex; i++)
            {
                finalInsertedStepIndex = this.InsertTestStepInTestCase(innerTestSteps[j], i, false);
                j++;
            }

            return finalInsertedStepIndex;
        }