public override TCObject Execute(TCObject requirementSet, TCAddOnTaskContext taskContext) { RequirementSet rs = (RequirementSet)requirementSet; JiraConfig config = rs.GetJiraConfig(); #region Setup if (config == null) { string url = taskContext.GetStringValue("Jira Instance URL: ", false); string jqlValue = taskContext.GetStringValue("JQL Filter for requirements: ", false); config = new JiraConfig { baseURL = url, jqlFilter = jqlValue, fieldMaps = new List <FieldMap>() { new FieldMap { direction = JiraService.Configuration.Direction.jira_to_tosca, jiraJsonPath = "$.fields.summary", toscaField = "Name" } } }; rs.SaveConfig(config); } string username, password; if (CredentialManager.Instance.Credentials.Any(x => x.BaseURL == config.baseURL)) { Credential credential = CredentialManager.Instance.Credentials.First(x => x.BaseURL == config.baseURL); username = credential.Username; password = credential.Password; } else { username = taskContext.GetStringValue("Jira Username", false); password = taskContext.GetStringValue("Jira Password", true); CredentialManager.Instance.StoreOrUpdateCredential(new Credential { BaseURL = config.baseURL, Description = "Created by Jira Config", Username = username, Password = password }); } #endregion var jira = new JiraService.Jira(config.baseURL, username, password); var issueService = jira.GetIssueService(); String startTime = DateTime.Now.ToString("yyyyMMddHHmmss"); string jql = config.jqlFilter; JiraService.Issue.Issue[] issues = null; Task <JiraService.Issue.Issue[]> issueTask = null; try { issueTask = issueService.SearchAsync(jql); while (!issueTask.IsCompleted) { taskContext.ShowStatusInfo($"Gettign issues for JQL: {jql}"); System.Threading.Thread.Sleep(100); } //order the issues so that subtasks are not created before parent tasks issues = issueTask.Result.OrderBy(x => x.fields.project.name).ThenBy(x => x.id).ToArray(); taskContext.ShowStatusInfo("Creating Requirements"); } catch (Exception e) { string err = e.Message; if (e.InnerException != null) { err += "\r\n" + e.InnerException.Message; } taskContext.ShowErrorMessage($"Error synchronising", err); taskContext.ShowStatusInfo($"Error synchronising: {err}"); return(requirementSet); } HashSet <string> updatedItems = new HashSet <string>(); if (issues != null) { foreach (var issue in issues) { var req = CreateOrUpdateRequirement(rs, config, issue); updatedItems.Add(req.UniqueId); } // Prompt status taskContext.ShowMessageBox("Jira Sync", issues.Length.ToString() + " requirements have been synchronised."); } return(null); }
/// <summary> /// This method handles the migration of Manual TestCase /// </summary> /// <param name="filePath">File Path of the ManualTestCase Excel sheet.</param> public void ProcessManualTestCaseFile(string filePath, TCAddOnTaskContext taskContext) { //ClosedXML has been used here to read the excel files. The library can be found in Tosca Installation Directory at '%TRICENTIS_HOME%\ToscaCommander'. //Alternatively, Microsoft.Office.Interop.Excel library or other third-party library can also be used. XLWorkbook workBook = new XLWorkbook(filePath); int workSheetNumber = 0; foreach (IXLWorksheet sheet in workBook.Worksheets) { workSheetNumber++; // track worksheet number taskContext.ShowProgressInfo(workBook.Worksheets.Count, workSheetNumber, "Process worksheet: " + sheet.Name); IXLRange usedRange = sheet.RangeUsed(); int testCaseFolderId = 0; int testCaseId = 0; int testStepId = 0; string testFolderName = "not resolved"; string testCaseName = "not resolved"; string testCaseDescription = "not resolved"; string testStepName = "not resolved"; // exported hp sheet will start in row = 5 // example in row = 5 // properties in row = 4 // we only have to import "Import_Tests_QC" if (sheet.Name.Equals("Import_Tests_QC") || (workBook.Worksheets.Count == 1)) { for (int row = 1; row <= usedRange.RowCount(); row++) { //taskContext.ShowProgressInfo(usedRange.RowCount(), row, "Processed rows (Max: " + usedRange.RowCount() + ")"); // exported hp sheet has data starting at column = 2 for (int column = -5; column <= usedRange.ColumnCount(); column++) { string cellValue = usedRange.Row(row).Cell(column).Value.ToString(); //taskContext.ShowStatusInfo("Actual cell (Max: " + usedRange.ColumnCount() + ")" + cellValue + "( with subject: " + usedRange.Row(3).Cell(column).Value.ToString() + ")"); if (!string.IsNullOrEmpty(cellValue)) { switch (usedRange.Row(3).Cell(column).Value.ToString()) { case "Subject": if (testFolderName == "not resolved" || !testFolderName.Equals(cellValue)) { testFolderName = cellValue.Trim(); //Creates TestFolder testCaseFolderId = Builder.CreateFolder(testFolderName, FolderType.TestCases, Definition.TestCasesFolderId); } break; case "Test Name": if (!testCaseName.Equals(cellValue)) { testCaseName = cellValue.Trim(); //Creates TestCase testCaseId = Builder.CreateTestCase(testCaseName, testCaseDescription, testCaseFolderId); } break; case "Test Description": testCaseDescription = cellValue.Trim(); break; case "Step Name": testStepName = cellValue.Trim(); //Creates ManualTestStep testStepId = Builder.CreateManualTestStep(testStepName, testCaseId, null); break; case "Step Description": //Creates ManualTestStepValue with ActionMode as Input Builder.CreateManualTestStepValue(cellValue, testStepId, "DATA", ActionMode.Input.ToString(), null); break; case "Expected result": //Creates ManualTestStepValue with ActionMode as Verify Builder.CreateManualTestStepValue(cellValue, testStepId, "", ActionMode.Verify.ToString(), null); break; } } } } } else { taskContext.ShowStatusInfo("Not in scope: " + sheet.Name); } } }