public void ImportQC(TestScript ts) { TreeManager treeM = TdOLE.TreeManager; SubjectNode node = treeM.get_NodeByPath("Subject") as SubjectNode; SubjectNode TargetNode = (SubjectNode)GetTargetNode(node, ts.QcFolderPath); TestFactory TstFac = TargetNode.TestFactory; List existingTests = TstFac.NewList(""); bool exists = false; Test tarTest = null; foreach (Test tst in existingTests) { if (tst.Name == ts.TestCaseName) { exists = true; tarTest = tst; continue; } } if (exists) // checkout and update { VCS vcs = tarTest.VCS; if (vcs.IsLocked) { vcs.UndoCheckout(true); vcs.CheckOut("-1", "Test Update " + DateTime.Now.ToString(), true); } else { vcs.CheckOut("-1", "Test Update " + DateTime.Now.ToString(), true); } AssignValue2Test(tarTest, ts); vcs.CheckIn("", ""); tarTest.Post(); } else // new creation { tarTest = TstFac.AddItem(DBNull.Value); AssignValue2Test(tarTest, ts); tarTest.Post(); } }
/// <summary> /// Export Activities Group details to QC, can be used for creating new matching QC Test Case or updating an existing one /// </summary> /// <param name="activitiesGroup">Activities Group to Export</param> /// <param name="mappedTest">The QC Test Case which mapped to the Activities Group (in case exist) and needs to be updated</param> /// <param name="uploadPath">Upload path in QC Test Plan</param> /// <param name="result">Export error result</param> /// <returns></returns> public static bool ExportActivitiesGroupToQC(ActivitiesGroup activitiesGroup, Test mappedTest, string uploadPath, ObservableList <ExternalItemFieldBase> testCaseFields, ref string result) { Test test; try { if (mappedTest == null) { //##create new Test Case in QC TestFactory TestF = (TestFactory)mTDConn.TestFactory; test = (Test)TestF.AddItem(System.DBNull.Value); test.Type = "MANUAL"; //set the upload path TreeManager treeM = (TreeManager)mTDConn.TreeManager; ISysTreeNode testParentFolder = (ISysTreeNode)treeM.get_NodeByPath(uploadPath); test["TS_SUBJECT"] = testParentFolder.NodeID; } else { //##update existing test case test = ImportFromQC.GetQCTest(activitiesGroup.ExternalID); //delete the un-needed steps DesignStepFactory stepF = test.DesignStepFactory; List stepsList = stepF.NewList(""); foreach (DesignStep step in stepsList) { if (activitiesGroup.ActivitiesIdentifiers.Where(x => x.IdentifiedActivity.ExternalID == step.ID.ToString()).FirstOrDefault() == null) { stepF.RemoveItem(step.ID); } } //delete the existing parameters StepParams testParams = test.Params; if (testParams.Count > 0) { for (int indx = 0; indx < testParams.Count; indx++) { testParams.DeleteParam(testParams.ParamName[indx]); testParams.Save(); } } } //set item fields foreach (ExternalItemFieldBase field in testCaseFields) { if (field.ToUpdate || field.Mandatory) { if (string.IsNullOrEmpty(field.SelectedValue) == false && field.SelectedValue != "NA") { test[field.ID] = field.SelectedValue; } else { try { test[field.ID] = "NA"; } catch { } } } } //post the test test.Name = activitiesGroup.Name; test.Post(); activitiesGroup.ExternalID = test.ID.ToString(); activitiesGroup.ExternalID2 = test.ID.ToString(); //Add/update all test steps + Parameters foreach (ActivityIdentifiers actIdent in activitiesGroup.ActivitiesIdentifiers) { ExportActivityAsTestStep(test, (Activity)actIdent.IdentifiedActivity); } return(true); } catch (Exception ex) { result = "Unexpected error occurred- " + ex.Message; Reporter.ToLog(eLogLevel.ERROR, "Failed to export the Activities Group to QC/ALM", ex); return(false); } }