コード例 #1
0
        public int Create(
            string DestinationPath,
            string TestSetName,
            string[] Additional = default(string[]))
        {
            int returnValue = 0;

            try
            {
                if (Connect(ServerUrl, Username, Password, Domain, Project))
                {
                    TestSetTreeManager tree = tdc.TestSetTreeManager;
                    TestSetFolder      folder;


                    folder = tree.NodeByPath[DestinationPath];
                    TestSetFactory TSFact = folder.TestSetFactory;
                    TestSet        NewTestSet;

                    NewTestSet      = TSFact.AddItem(DBNull.Value);
                    NewTestSet.Name = TestSetName;

                    //Set additional field values
                    if (Additional != default(string[]))
                    {
                        foreach (string fieldPair in Additional)
                        {
                            string[] tempFieldArray = fieldPair.Split(new[] { ";;" }, StringSplitOptions.None);
                            NewTestSet[tempFieldArray[0]] = tempFieldArray[1];
                        }
                    }
                    NewTestSet.Post();
                    //Console.Out.WriteLine(NewTestSet.ID);
                    returnValue = NewTestSet.ID;
                }
            }
            catch (COMException ce)
            {
                rr.AddErrorLine(HandleException(ce));
            }
            finally { Disconnect(); }

            return(returnValue);
        }
コード例 #2
0
ファイル: ExportToQC.cs プロジェクト: svendster/Ginger
        public static bool ExportBusinessFlowToQC(BusinessFlow businessFlow, TestSet mappedTestSet, string uploadPath, ObservableList <ExternalItemFieldBase> testSetFields, ref string result)
        {
            TestSet testSet;
            ObservableList <ActivitiesGroup> existingActivitiesGroups = new ObservableList <ActivitiesGroup>();

            try
            {
                if (mappedTestSet == null)
                {
                    //##create new Test Set in QC
                    TestSetFactory TestSetF = (TestSetFactory)mTDConn.TestSetFactory;
                    testSet = (TestSet)TestSetF.AddItem(System.DBNull.Value);

                    //set the upload path
                    TestSetTreeManager treeM = (TestSetTreeManager)mTDConn.TestSetTreeManager;
                    ISysTreeNode       testSetParentFolder = (ISysTreeNode)treeM.get_NodeByPath(uploadPath);
                    testSet.TestSetFolder = testSetParentFolder.NodeID;
                }
                else
                {
                    //##update existing test set
                    //testSet = mappedTestSet;
                    testSet = ImportFromQC.GetQCTestSet(mappedTestSet.ID.ToString());

                    TSTestFactory testsF      = (TSTestFactory)testSet.TSTestFactory;
                    List          tsTestsList = testsF.NewList("");
                    foreach (TSTest tsTest in tsTestsList)
                    {
                        ActivitiesGroup ag = businessFlow.ActivitiesGroups.Where(x => (x.ExternalID == tsTest.TestId.ToString() && x.ExternalID2 == tsTest.ID.ToString())).FirstOrDefault();
                        if (ag == null)
                        {
                            testsF.RemoveItem(tsTest.ID);
                        }
                        else
                        {
                            existingActivitiesGroups.Add(ag);
                        }
                    }
                }

                //set item fields
                foreach (ExternalItemFieldBase field in testSetFields)
                {
                    if (field.ToUpdate || field.Mandatory)
                    {
                        if (string.IsNullOrEmpty(field.SelectedValue) == false && field.SelectedValue != "NA")
                        {
                            testSet[field.ID] = field.SelectedValue;
                        }
                        else
                        {
                            try { testSet[field.ID] = "NA"; }
                            catch { }
                        }
                    }
                }

                //post the test set
                testSet.Name = businessFlow.Name;

                try
                {
                    testSet.Post();
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("The Test Set already exists"))
                    {
                        result = "Cannot export " + GingerDicser.GetTermResValue(eTermResKey.BusinessFlow) + "- The Test Set already exists in the selected folder. ";
                        Reporter.ToLog(eLogLevel.ERROR, result, ex);
                        return(false);
                    }

                    //Searching for the testset in case it was created in ALM although getting exception
                    TestSetFactory     TSetFact            = mTDConn.TestSetFactory;
                    TDFilter           tsFilter            = TSetFact.Filter;
                    TestSetTreeManager treeM               = (TestSetTreeManager)mTDConn.TestSetTreeManager;
                    ISysTreeNode       testSetParentFolder = (ISysTreeNode)treeM.get_NodeByPath(uploadPath);

                    try
                    {
                        tsFilter["CY_FOLDER_ID"] = "" + testSetParentFolder.NodeID + "";
                    }
                    catch (Exception e)
                    {
                        tsFilter["CY_FOLDER_ID"] = "\"" + testSetParentFolder.Path.ToString() + "\"";
                        Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {e.Message}", e);
                    }

                    List TestsetList = TSetFact.NewList(tsFilter.Text);
                    foreach (TestSet set in TestsetList)
                    {
                        if (set.Name == businessFlow.Name)
                        {
                            testSet = set;
                            break;
                        }
                    }
                }

                businessFlow.ExternalID = testSet.ID.ToString();

                //Add missing test cases
                TSTestFactory testCasesF = testSet.TSTestFactory;
                foreach (ActivitiesGroup ag in businessFlow.ActivitiesGroups)
                {
                    if (existingActivitiesGroups.Contains(ag) == false && string.IsNullOrEmpty(ag.ExternalID) == false && ImportFromQC.GetQCTest(ag.ExternalID) != null)
                    {
                        TSTest tsTest = testCasesF.AddItem(ag.ExternalID);
                        if (tsTest != null)
                        {
                            ag.ExternalID2 = tsTest.ID;//the test case instance ID in the test set- used for exporting the execution details
                        }
                    }
                    else
                    {
                        foreach (ActivityIdentifiers actIdent in ag.ActivitiesIdentifiers)
                        {
                            ExportActivityAsTestStep(ImportFromQC.GetQCTest(ag.ExternalID), (Activity)actIdent.IdentifiedActivity);
                        }
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                result = "Unexpected error occurred- " + ex.Message;
                Reporter.ToLog(eLogLevel.ERROR, "Failed to export the " + GingerDicser.GetTermResValue(eTermResKey.BusinessFlow) + " to QC/ALM", ex);
                return(false);
            }
        }
コード例 #3
0
        private TestSetFolder CreateTestSetNames(List <string> TestSetNames, TestSetFolder TSFolder)
        {
            List <ItemValue> tcList = new List <ItemValue>();

            #region Generate TestSet Name
            //Get all match test cases and store it to a List
            try
            {
                ICommand com        = tdConn.Command as ICommand;
                string[] columnName = { "TS_TEST_ID", configFile.CaseFilter.TestSetName };

                string sqlCommand = GenerateSQLText(columnName);
                com.CommandText = sqlCommand;

                IRecordset recList = com.Execute() as IRecordset;

                recList.First();
                for (int num = 0; num < recList.RecordCount; num++)
                {
                    ItemValue tc = new ItemValue();
                    tc.Test_ID = recList["TS_TEST_ID"].ToString();
                    if (recList[configFile.CaseFilter.TestSetName] != null)
                    {
                        tc.Test_Custom = recList[configFile.CaseFilter.TestSetName].ToString();
                    }
                    tcList.Insert(0, tc);
                    recList.Next();
                }
            }
            catch (Exception e)
            {
                AutoLog.Info("AutoIntSys: Exception with " + e.Message);
                AutoLog.Info("AutoIntSys: Fail to get Specified Field Value from TEST Table!");
                //Debug.Print("AutoIntSys:Fail to get Specified Field Value from TEST Table!");
                //Debug.Print("AutoIntSys:" + e);
                return(null);
            }
            #endregion

            #region Generate TestSet
            try
            {
                TestSetFactory TSFact   = TSFolder.TestSetFactory as TestSetFactory;
                TestFactory    TestFact = tdConn.TestFactory as TestFactory;
                foreach (string TSName in TestSetNames)
                {
                    TestSet       TestSetName;
                    TSTestFactory TSTestFact;

                    TestSetName = TSFact.AddItem(TSName) as TestSet;
                    TestSetName.Post();
                    TSTestFact = TestSetName.TSTestFactory as TSTestFactory;

                    foreach (ItemValue t in tcList)
                    {
                        if (t.Test_Custom == TSName)
                        {
                            TSTestFact.AddItem(t.Test_ID);
                        }
                    }
                }

                createTSSucess = true;
                return(TSFolder);
            }
            catch (Exception e)
            {
                AutoLog.Info("AutoIntSys: Exception with " + e.Message);
                AutoLog.Info("AutoIntSys: Create Test Sets Error!");
                //Debug.Print("AutoIntSys:Create Test Sets Error!");
                //Debug.Print("AutoIntSys:" + e.Message);
                return(null);
            }
            #endregion
        }