/// <summary>
 /// Removes the test step from test steps observable collection.
 /// </summary>
 /// <param name="testStepToBeRemoved">The test step to be removed.</param>
 /// <param name="selectedIndex">Index of the selected.</param>
 public void RemoveTestStepFromObservableCollection(TestStep testStepToBeRemoved, int selectedIndex)
 {
     this.ObservableTestSteps.Remove(testStepToBeRemoved);
     log.InfoFormat("Remove test step ActionTitle = {0}, ExpectedResult= {1}", testStepToBeRemoved.ActionTitle, testStepToBeRemoved.ActionExpectedResult);
     UndoRedoManager.Instance().Push((r, i) => this.InsertTestStepInTestCase(r, i), testStepToBeRemoved, selectedIndex, "remove Test Step");
     TestStepManager.UpdateGenericSharedSteps(this.ObservableTestSteps);
 }
 /// <summary>
 /// Inserts the test step information to the test case.
 /// </summary>
 /// <param name="testStepToInsert">The test step to be insert.</param>
 /// <param name="selectedIndex">Index of the selected test step.</param>
 /// <param name="skipShared">if set to <c>true</c> [skip shared].</param>
 /// <returns>
 /// new selected index
 /// </returns>
 public int InsertTestStepInTestCase(TestStep testStepToInsert, int selectedIndex, bool skipShared = true)
 {
     if (!skipShared)
     {
         selectedIndex = this.FindNextNotSharedStepIndex(selectedIndex);
     }
     // If you delete first step and call redo operation, the step should be inserted at the beginning
     if (selectedIndex == -2)
     {
         log.InfoFormat("Insert test step ActionTitle= {0}, ActionExpectedResult= {1}, index= {2}", testStepToInsert.ActionTitle, testStepToInsert.ActionExpectedResult, 0);
         this.ObservableTestSteps.Insert(0, testStepToInsert);
     }
     else if (selectedIndex != -1)
     {
         this.ObservableTestSteps.Insert(selectedIndex + 1, testStepToInsert);
         log.InfoFormat("Insert test step ActionTitle= {0}, ActionExpectedResult= {1}, index= {2}", testStepToInsert.ActionTitle, testStepToInsert.ActionExpectedResult, selectedIndex + 1);
     }
     else
     {
         this.ObservableTestSteps.Add(testStepToInsert);
         selectedIndex = this.ObservableTestSteps.Count - 1;
         log.InfoFormat("Insert test step ActionTitle= {0}, ActionExpectedResult= {1}, end of test case", testStepToInsert.ActionTitle, testStepToInsert.ActionExpectedResult);
     }
     UndoRedoManager.Instance().Push((r, i) => this.RemoveTestStepFromObservableCollection(r, i), testStepToInsert, selectedIndex);
     TestStepManager.UpdateGenericSharedSteps(this.ObservableTestSteps);
     return(selectedIndex);
 }
        /// <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);
        }
        /// <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);
        }
예제 #5
0
        /// <summary>
        /// Exports the test cases.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="selectedTestCases">The selected test cases.</param>
        public void ExportTestCases(string fileName, List <TestCase> selectedTestCases)
        {
            List <TestCaseFull> fullTestCases = this.GetAllFullTestCasesForObservableTestCases(selectedTestCases);

            foreach (TestCaseFull currentFullTestCase in fullTestCases)
            {
                TestStepManager.UpdateGenericSharedSteps(currentFullTestCase.TestSteps);
                currentFullTestCase.TestSteps = this.InitializeTestStepsForExport(currentFullTestCase.TestSteps);
            }

            HtmlTestCaseExportTemplate htmlTestCaseExportTemplate = new HtmlTestCaseExportTemplate();

            htmlTestCaseExportTemplate.Session = new Dictionary <string, object>();
            htmlTestCaseExportTemplate.Session.Add("FullTestCases", fullTestCases);
            htmlTestCaseExportTemplate.Initialize();
            string       currentSvcFileContent = htmlTestCaseExportTemplate.TransformText();
            StreamWriter writer = new StreamWriter(fileName, false, System.Text.Encoding.UTF8);

            using (writer)
            {
                writer.WriteLine(currentSvcFileContent);
            }
        }