コード例 #1
0
        /// <summary>
        /// Sets the test case suite.
        /// </summary>
        /// <param name="suiteId">The suite unique identifier.</param>
        /// <param name="testCase">The test case.</param>
        private static void SetTestCaseSuite(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, int suiteId, TestCase testCase)
        {
            var newSuite = TestSuiteManager.GetTestSuiteById(testManagementTeamProject, testPlan, suiteId);

            if (newSuite != null)
            {
                newSuite.AddTestCase(testCase.ITestCase);
                testCase.ITestSuiteBase = newSuite;
            }
        }
コード例 #2
0
        /// <summary>
        /// Saves the specified test case.
        /// </summary>
        /// <param name="sourceTestCase">The test case.</param>
        /// <param name="testManagementTeamProject">The test management team project.</param>
        /// <param name="testPlan">The test plan.</param>
        /// <param name="createNew">should be saved as new test case.</param>
        /// <param name="suiteId">The suite identifier.</param>
        /// <param name="testSteps">The test steps.</param>
        /// <param name="shouldAssignArea">if set to <c>true</c> [should assign area].</param>
        /// <param name="isMigration">if set to <c>true</c> [is migration].</param>
        /// <returns>
        /// the saved test case
        /// </returns>
        public static TestCase Save(
            this TestCase sourceTestCase,
            ITestManagementTeamProject testManagementTeamProject,
            ITestPlan testPlan,
            bool createNew,
            int?suiteId,
            ICollection <TestStep> testSteps,
            bool shouldAssignArea = true,
            bool isMigration      = false)
        {
            TestCase currentTestCase = sourceTestCase;

            if (createNew)
            {
                ITestCase testCaseCore = testManagementTeamProject.TestCases.Create();
                currentTestCase = new TestCase(testCaseCore, sourceTestCase.ITestSuiteBase, testPlan);
            }
            if (shouldAssignArea)
            {
                currentTestCase.ITestCase.Area = sourceTestCase.Area;
            }
            currentTestCase.ITestCase.Description = sourceTestCase.ITestCase.Description;
            currentTestCase.ITestCase.Title       = sourceTestCase.Title;
            currentTestCase.ITestCase.Priority    = (int)sourceTestCase.Priority;
            currentTestCase.ITestCase.Actions.Clear();
            currentTestCase.ITestCase.Owner = testManagementTeamProject.TfsIdentityStore.FindByTeamFoundationId(sourceTestCase.TeamFoundationId);
            if (sourceTestCase.ITestCase.Implementation != null && isMigration)
            {
                currentTestCase.ITestCase.Implementation = sourceTestCase.ITestCase.Implementation;
            }
            List <Guid> addedSharedStepGuids = new List <Guid>();

            foreach (TestStep currentStep in testSteps)
            {
                if (currentStep.IsShared && !addedSharedStepGuids.Contains(currentStep.TestStepGuid))
                {
                    ISharedStep          sharedStepCore          = testManagementTeamProject.SharedSteps.Find(currentStep.SharedStepId);
                    ISharedStepReference sharedStepReferenceCore = currentTestCase.ITestCase.CreateSharedStepReference();
                    sharedStepReferenceCore.SharedStepId = sharedStepCore.Id;
                    currentTestCase.ITestCase.Actions.Add(sharedStepReferenceCore);
                    addedSharedStepGuids.Add(currentStep.TestStepGuid);
                }
                else if (!currentStep.IsShared)
                {
                    ITestStep testStepCore = currentTestCase.ITestCase.CreateTestStep();
                    testStepCore.Title          = currentStep.ActionTitle;
                    testStepCore.ExpectedResult = currentStep.ActionExpectedResult;
                    currentTestCase.ITestCase.Actions.Add(testStepCore);
                }
            }

            if (suiteId != null)
            {
                var newSuite = TestSuiteManager.GetTestSuiteById(testManagementTeamProject, testPlan, (int)suiteId);
                sourceTestCase.ITestSuiteBase = newSuite;
            }
            currentTestCase.ITestCase.Flush();
            currentTestCase.ITestCase.Save();
            if (suiteId != null)
            {
                SetTestCaseSuite(testManagementTeamProject, testPlan, (int)suiteId, currentTestCase);
            }

            currentTestCase.ITestCase.Flush();
            currentTestCase.ITestCase.Save();

            return(currentTestCase);
        }