/// <summary> /// Imports a single test run with its tests /// </summary> private void ImportTestRun(StreamWriter streamWriter, SpiraSoapService.SoapServiceClient spiraClient, APIClient testRailApi, JObject testRun) { //Extract the test rail data if (testRun["id"].Type == JTokenType.Integer) { int testRailRunId = testRun["id"].Value <int>(); streamWriter.WriteLine("Importing test run: " + testRailRunId); int? milestoneId = testRun["milestone_id"].Value <int?>(); int? planId = testRun["plan_id"].Value <int?>(); string name = testRun["name"].Value <string>(); string description = testRun["description"].Value <string>(); //See if we have any tests in the run JArray tests = (JArray)testRailApi.SendGet("get_tests/" + testRailRunId); if (tests != null) { foreach (JObject test in tests) { int trTestId = test["id"].Value <int>(); streamWriter.WriteLine("Importing test: T" + trTestId); int trTestCaseId = test["case_id"].Value <int>(); int trStatusId = test["status_id"].Value <int>(); string title = test["title"].Value <string>(); int?spiraTesterId = null; int?spiraReleaseId = null; int spiraTestCaseId = this.testCaseMapping[trTestCaseId]; int?spiraTestSetId = null; int spiraExecutionStatusId = ConvertExecutionStatus(trStatusId); int?assignedToId = test["assignedto_id"].Value <int?>(); if (assignedToId.HasValue && this.usersMapping.ContainsKey(assignedToId.Value)) { spiraTesterId = this.usersMapping[assignedToId.Value]; } if (milestoneId.HasValue && this.releaseMapping.ContainsKey(milestoneId.Value)) { spiraReleaseId = this.releaseMapping[milestoneId.Value]; } if (planId.HasValue && this.testSetMapping.ContainsKey(planId.Value)) { spiraTestSetId = this.testSetMapping[planId.Value]; } //Now get the results for the test JArray results = (JArray)testRailApi.SendGet("get_results/" + trTestId); if (results != null) { foreach (JObject result in results) { int trResultId = result["id"].Value <int>(); streamWriter.WriteLine("Importing result: " + trResultId); DateTime executionDate = FromUnixTime(result["created_on"].Value <long>()); //streamWriter.WriteLine("*DEBUG*: " + executionDate.ToString() + "==" + result["created_on"].Value<long>()); string actualResults = result["comment"].Value <string>(); //We now upload each of these as a test run to SpiraTest //Now create a new test run shell from this test case RemoteManualTestRun[] remoteTestRuns = spiraClient.TestRun_CreateFromTestCases(new int[] { spiraTestCaseId }, null); if (remoteTestRuns.Length > 0) { //We concatenate the test run name and test title from TestRail string testRunName = name + ": " + title; //Update the test run information RemoteManualTestRun remoteTestRun = remoteTestRuns[0]; remoteTestRun.ExecutionStatusId = spiraExecutionStatusId; remoteTestRun.StartDate = executionDate; DateTime endDate = executionDate; //We don't have a good way to parse TestRail durations remoteTestRun.EndDate = endDate; remoteTestRun.Name = testRunName; remoteTestRun.TestSetId = spiraTestSetId; //remoteTestRun.TestSetTestCaseId = testSetTestCaseId; //No equivalent in TestRail remoteTestRun.TesterId = spiraTesterId; remoteTestRun.ReleaseId = spiraReleaseId; //Now the steps foreach (RemoteTestRunStep remoteTestRunStep in remoteTestRun.TestRunSteps) { remoteTestRunStep.ActualResult = actualResults; remoteTestRunStep.ExecutionStatusId = spiraExecutionStatusId; } //Save the run spiraClient.TestRun_Save(remoteTestRuns, executionDate); streamWriter.WriteLine("Added manual test run for result: " + trResultId); } } } } } } }