コード例 #1
0
        /// <summary>
        /// Imports the test suites and sections
        /// </summary>
        /// <param name="streamWriter"></param>
        /// <param name="spiraClient"></param>
        /// <param name="testRailApi"></param>
        private void ImportTestSuites(StreamWriter streamWriter, SpiraSoapService.SoapServiceClient spiraClient, TestLink testLinkApi, List <TestSuite> testSuites, int?parentTestFolderId = null)
        {
            //Get the test suites from the TestLink API
            if (testSuites != null)
            {
                foreach (TestSuite testSuite in testSuites)
                {
                    //Extract the user data
                    int testLinkId = testSuite.id;

                    //Create the new SpiraTest test folder
                    RemoteTestCaseFolder remoteTestFolder = new RemoteTestCaseFolder();
                    remoteTestFolder.Name = testSuite.name;
                    remoteTestFolder.ParentTestCaseFolderId = parentTestFolderId;
                    int newTestCaseFolderId = spiraClient.TestCase_CreateFolder(remoteTestFolder).TestCaseFolderId.Value;
                    streamWriter.WriteLine("Added test suite: " + testLinkId);

                    //Add to the mapping hashtables
                    if (!this.testSuiteMapping.ContainsKey(testLinkId))
                    {
                        this.testSuiteMapping.Add(testLinkId, newTestCaseFolderId);
                    }

                    //See if this test suite has any child test suites
                    List <TestSuite> childTestSuites = testLinkApi.GetTestSuitesForTestSuite(testLinkId);
                    if (childTestSuites != null && childTestSuites.Count > 0)
                    {
                        ImportTestSuites(streamWriter, spiraClient, testLinkApi, childTestSuites, newTestCaseFolderId);
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Imports the test suites and sections
        /// </summary>
        /// <param name="streamWriter"></param>
        /// <param name="spiraClient"></param>
        /// <param name="testRailApi"></param>
        private void ImportTestSuites(StreamWriter streamWriter, SpiraSoapService.SoapServiceClient spiraClient, APIClient testRailApi)
        {
            //Get the test cases from the TestRail API
            JArray testSuites = (JArray)testRailApi.SendGet("get_suites/" + this.testRailProjectId);

            if (testSuites != null)
            {
                foreach (JObject testSuite in testSuites)
                {
                    //Extract the user data
                    int testRailId = testSuite["id"].Value <int>();

                    //Create the new SpiraTest test folder
                    RemoteTestCaseFolder remoteTestFolder = new RemoteTestCaseFolder();
                    remoteTestFolder.Name        = testSuite["name"].Value <string>();
                    remoteTestFolder.Description = testSuite["description"].Value <string>();
                    int newTestCaseFolderId = spiraClient.TestCase_CreateFolder(remoteTestFolder).TestCaseFolderId.Value;
                    streamWriter.WriteLine("Added test suite: " + testRailId);

                    //Add to the mapping hashtables
                    if (!this.testSuiteMapping.ContainsKey(testRailId))
                    {
                        this.testSuiteMapping.Add(testRailId, newTestCaseFolderId);
                    }

                    //Now get each section in the suite
                    JArray testSections = (JArray)testRailApi.SendGet("get_sections/" + this.testRailProjectId + "&suite_id=" + testRailId);
                    if (testSections != null)
                    {
                        Dictionary <string, int> usedSectionNames = new  Dictionary <string, int>();
                        foreach (JObject testSection in testSections)
                        {
                            //Extract the user data
                            int testRailSectionId = testSection["id"].Value <int>();

                            //See if we have a name for this already in this suite, if so, re-use the existing section name
                            string sectionName = testSection["name"].Value <string>();
                            if (usedSectionNames.ContainsKey(sectionName))
                            {
                                //Add to the mapping dictionary
                                if (!this.testSuiteSectionMapping.ContainsKey(testRailSectionId))
                                {
                                    this.testSuiteSectionMapping.Add(testRailSectionId, usedSectionNames[sectionName]);
                                }
                            }
                            else
                            {
                                //Create the new SpiraTest test folder
                                remoteTestFolder             = new RemoteTestCaseFolder();
                                remoteTestFolder.Name        = sectionName;
                                remoteTestFolder.Description = testSection["description"].Value <string>();

                                //See if we have a parent section already imported
                                int?parentSectionId = testSection["parent_id"].Value <int?>();
                                if (parentSectionId.HasValue && this.testSuiteSectionMapping.ContainsKey(parentSectionId.Value))
                                {
                                    remoteTestFolder.ParentTestCaseFolderId = this.testSuiteSectionMapping[parentSectionId.Value];
                                }
                                else
                                {
                                    //Otherwise just import directly under the suite
                                    remoteTestFolder.ParentTestCaseFolderId = newTestCaseFolderId;
                                }

                                int newTestCaseFolderId2 = spiraClient.TestCase_CreateFolder(remoteTestFolder).TestCaseFolderId.Value;
                                streamWriter.WriteLine("Added test section: " + testRailSectionId);
                                usedSectionNames.Add(sectionName, newTestCaseFolderId2);

                                //Add to the mapping dictionary
                                if (!this.testSuiteSectionMapping.ContainsKey(testRailSectionId))
                                {
                                    this.testSuiteSectionMapping.Add(testRailSectionId, newTestCaseFolderId2);
                                }
                            }
                        }
                    }
                }
            }
        }