コード例 #1
0
        /// <summary>
        /// Imports test cases and associated steps
        /// </summary>
        private void ImportTestCasesAndSteps(StreamWriter streamWriter, SpiraSoapService.SoapServiceClient spiraClient, TestLink testLinkApi)
        {
            //Loop through all the mapped, imported test suites
            foreach (KeyValuePair <int, int> kvp in this.testSuiteMapping)
            {
                //Get the test cases from the TestLink API
                int testSuiteId  = kvp.Key;
                int testFolderId = kvp.Value;
                streamWriter.WriteLine(String.Format("Getting test cases in test suite: {0}", testSuiteId));
                List <TestCaseFromTestSuite> testCasesInSuite = testLinkApi.GetTestCasesForTestSuite(testSuiteId, true);
                if (testCasesInSuite != null)
                {
                    foreach (TestCaseFromTestSuite testCaseInSuite in testCasesInSuite)
                    {
                        //Extract the user data
                        int    tlTestCaseId         = testCaseInSuite.id;
                        string tlTestCaseExternalId = testCaseInSuite.external_id;
                        streamWriter.WriteLine(String.Format("Finding test case: {0} - {1}", tlTestCaseId, tlTestCaseExternalId));

                        //Get the actual test case object (with steps)
                        try
                        {
                            TestCase testCase = testLinkApi.GetTestCase(tlTestCaseId);
                            if (testCase != null)
                            {
                                streamWriter.WriteLine(String.Format("Importing test case: {0}", tlTestCaseId));
                                string description = "";
                                if (!String.IsNullOrEmpty(testCase.summary))
                                {
                                    description += "<p>" + testCase.summary + "</p>";
                                }
                                if (!String.IsNullOrEmpty(testCase.preconditions))
                                {
                                    description += "<p>" + testCase.preconditions + "</p>";
                                }

                                //Reauthenticate at this point, in case disconnected
                                spiraClient.Connection_Authenticate2(Properties.Settings.Default.SpiraUserName, Properties.Settings.Default.SpiraPassword, "TestLinkImporter");
                                spiraClient.Connection_ConnectToProject(this.newProjectId);

                                //Create the new SpiraTest test case
                                RemoteTestCase remoteTestCase = new RemoteTestCase();
                                remoteTestCase.Name             = testCase.name;
                                remoteTestCase.Description      = description;
                                remoteTestCase.TestCaseTypeId   = /* Functional */ 3;
                                remoteTestCase.TestCaseStatusId = (testCase.active) ? /* Ready For Test */ 5 : /* Draft*/ 1;
                                remoteTestCase.CreationDate     = testCase.creation_ts;
                                if (testCase.importance >= 1 && testCase.importance <= 4)
                                {
                                    remoteTestCase.TestCasePriorityId = testCase.importance;
                                }

                                //We don't import the author currently
                                //remoteTestCase.AuthorId = this.usersMapping[createdById.Value];

                                //Map to the folder
                                remoteTestCase.TestCaseFolderId = testFolderId;

                                int newTestCaseId = spiraClient.TestCase_Create(remoteTestCase).TestCaseId.Value;
                                streamWriter.WriteLine("Added test case: " + tlTestCaseId);

                                //See if we have any test steps for this test case
                                if (testCase.steps != null && testCase.steps.Count > 0)
                                {
                                    streamWriter.WriteLine("Adding " + testCase.steps.Count + " test steps to test case: " + tlTestCaseId);
                                    foreach (TestStep testStep in testCase.steps)
                                    {
                                        RemoteTestStep remoteTestStep = new RemoteTestStep();
                                        remoteTestStep.Description    = testStep.actions;
                                        remoteTestStep.ExpectedResult = testStep.expected_results;
                                        spiraClient.TestCase_AddStep(remoteTestStep, newTestCaseId);
                                    }
                                    streamWriter.WriteLine("Added test steps to test case: " + tlTestCaseId);
                                }

                                //Add to the mapping hashtables
                                if (!this.testCaseMapping.ContainsKey(tlTestCaseId))
                                {
                                    this.testCaseMapping.Add(tlTestCaseId, newTestCaseId);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            streamWriter.WriteLine(String.Format("Error importing test case {0}: {1} ({2})", tlTestCaseId, ex.Message, ex.StackTrace));
                        }
                    }
                }
            }
        }