private static QCTestSet UpdateExistingTestSet(BusinessFlow businessFlow, QCTestSet mappedTestSet, string uploadPath, ObservableList <ExternalItemFieldBase> testSetFields)
        {
            QCTestSet testSet = ImportFromQCRest.GetQCTestSet(mappedTestSet.Id.ToString());

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

            testSet.ElementsField["name"] = businessFlow.Name;

            try
            {
                QCItem          item     = ConvertObjectValuesToQCItem(testSet, ResourceType.TEST_SET, true);
                ALMResponseData response = QCRestAPIConnect.UpdateEntity(ResourceType.TEST_SET, testSet.Id, item);
                return(QCRestAPIConnect.GetTestSetDetails(testSet.Id));
            }
            catch (Exception ex)
            {
                Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}");
                return(null);
            }
        }
    public void SetNowMobEvidenceInven()
    {
        if (nowInven == null)
        {
            nowInven = new List <QCItem>();
        }
        List <QuestPerMob> list = Inventory.GetInstance().GetNowMobEvidencesInven();

        for (int i = 0; i < list.Count; i++)
        {
            GameObject temp = Instantiate(itemBtn);
            Text       numText;
            SetItemBtnCtx(temp, list[i], out numText);

            QCItem qc = new QCItem(temp, numText, list[i]);
            nowInven.Add(qc);
            Button btn = temp.GetComponent <Button>();
            btn.onClick.AddListener(
                () =>
            {
                AudioThing.GetInstance().PlaySFX(AudioThing.E_SFX.CLICK);
                OnClickQCInven(qc);
            }
                );

            temp.transform.SetParent(nowInvenContents.transform);
        }
    }
    void SettleNowInvenItem(E_Monster mob, E_Evidence evidence)
    {
        for (int i = 0; i < nowInven.Count; i++)
        {
            if (nowInven[i].qpm.IsIt(mob, evidence))
            {
                nowInven[i].qpm.number++;
                nowInven[i].numText.text = nowInven[i].qpm.number.ToString();
                return;
            }
        }
        QuestPerMob qpm = new QuestPerMob(mob, evidence, 1);

        GameObject temp = Instantiate(itemBtn);
        Text       numText;

        SetItemBtnCtx(temp, qpm, out numText);

        QCItem qc = new QCItem(temp, numText, qpm);

        nowInven.Add(qc);
        Button btn = temp.GetComponent <Button>();

        btn.onClick.AddListener(
            () =>
        {
            AudioThing.GetInstance().PlaySFX(AudioThing.E_SFX.CLICK);
            OnClickQCInven(qc);
        }
            );

        temp.transform.SetParent(nowInvenContents.transform);
    }
        private static QCItem ConvertObjectValuesToQCItem(object item, ResourceType type, bool isUpdate = false)
        {
            QCItem itemWithValues = new QCItem();

            dynamic itemVals = item;

            foreach (var keyValue in itemVals.ElementsField)
            {
                if (keyValue.Key != "order-id")
                {
                    itemWithValues.Fields.Add(keyValue.Key, keyValue.Value);
                }
            }

            if (itemVals.GetType().GetProperty("Id") != null)
            {
                // Do nothing
            }
            if (itemVals.GetType().GetProperty("ParentId") != null && itemVals.GetType().GetProperty("ParentId").GetValue(itemVals, null) != null)
            {
                itemWithValues.Fields.Add("parent-id", itemVals.GetType().GetProperty("ParentId").GetValue(itemVals, null));
            }
            if (itemVals.GetType().GetProperty("Description") != null && itemVals.GetType().GetProperty("Description").GetValue(itemVals, null) != null && !isUpdate)
            {
                itemWithValues.Fields.Add("description", EscapeChars(itemVals.GetType().GetProperty("Description").GetValue(itemVals, null)));
            }
            if (itemVals.GetType().GetProperty("Name") != null && itemVals.GetType().GetProperty("Name").GetValue(itemVals, null) != null && !isUpdate)
            {
                itemWithValues.Fields.Add("name", EscapeChars(itemVals.GetType().GetProperty("Name").GetValue(itemVals, null)));
            }
            if (itemVals.GetType().GetProperty("Path") != null && itemVals.GetType().GetProperty("Path").GetValue(itemVals, null) != null && !isUpdate)
            {
                if (!(type == ResourceType.TEST_SET))
                {
                    itemWithValues.Fields.Add("hierarchical-path", itemVals.GetType().GetProperty("Path").GetValue(itemVals, null));
                }
            }
            if (itemVals.GetType().GetProperty("DefualtValue") != null && itemVals.GetType().GetProperty("DefualtValue").GetValue(itemVals, null) != null)
            {
                itemWithValues.Fields.Add("default-value", itemVals.GetType().GetProperty("DefualtValue").GetValue(itemVals, null));
            }
            if (itemVals.GetType().GetProperty("ActualValue") != null && itemVals.GetType().GetProperty("ActualValue").GetValue(itemVals, null) != null)
            {
                itemWithValues.Fields.Add("actual-value", itemVals.GetType().GetProperty("ActualValue").GetValue(itemVals, null));
            }
            if (itemVals.GetType().GetProperty("TestOrder") != null && itemVals.GetType().GetProperty("TestOrder").GetValue(itemVals, null) != null && !isUpdate)
            {
                itemWithValues.Fields.Add("order-id", itemVals.GetType().GetProperty("TestOrder").GetValue(itemVals, null));
            }
            if (itemVals.GetType().GetProperty("TestId") != null && itemVals.GetType().GetProperty("TestId").GetValue(itemVals, null) != null && !isUpdate)
            {
                itemWithValues.Fields.Add("test-id", itemVals.GetType().GetProperty("TestId").GetValue(itemVals, null));
            }
            if (itemVals.GetType().GetProperty("CycleId") != null && itemVals.GetType().GetProperty("CycleId").GetValue(itemVals, null) != null && !isUpdate)
            {
                itemWithValues.Fields.Add("cycle-id", itemVals.GetType().GetProperty("CycleId").GetValue(itemVals, null));
            }

            return(itemWithValues);
        }
Esempio n. 5
0
 public static ALMResponseData CreateNewEntity(ResourceType resourceType, QCItem item)
 {
     try
     {
         return(QcRestClient.CreateNewEntity(resourceType, item));
     }
     catch (Exception ex)
     {
         Reporter.ToLog(eAppReporterLogLevel.ERROR, "Failed to create entity with REST API", ex);
         return(null);
     }
 }
        private static void UpdateTestInstances(BusinessFlow businessFlow, ObservableList <ActivitiesGroup> existingActivitiesGroups, QCTestSet testSet, ObservableList <ExternalItemFieldBase> testInstancesFields)
        {
            QCTestInstanceColl testInstances = ImportFromQCRest.ImportTestSetInstanceData(testSet);

            foreach (QCTestInstance testInstance in testInstances)
            {
                ActivitiesGroup ag = businessFlow.ActivitiesGroups.Where(x => (x.ExternalID == testInstance.TestId.ToString() && x.ExternalID2 == testInstance.Id.ToString())).FirstOrDefault();
                if (ag == null)
                {
                    QCRestAPIConnect.DeleteEntity(ResourceType.TEST_CYCLE, testInstance.Id);
                }
                else
                {
                    existingActivitiesGroups.Add(ag);
                    //set item fields for test instances
                    foreach (ExternalItemFieldBase field in testInstancesFields)
                    {
                        if ((field.ToUpdate || field.Mandatory) && (!(field.ExternalID == "test-id") && !(field.ExternalID == "cycle-id")))
                        {
                            if (string.IsNullOrEmpty(field.ExternalID) == false && field.SelectedValue != "NA")
                            {
                                if (testInstance.ElementsField.ContainsKey(field.ID))
                                {
                                    testInstance.ElementsField[field.ExternalID] = field.SelectedValue;
                                }
                            }
                        }
                    }

                    try
                    {
                        QCItem          item     = ConvertObjectValuesToQCItem(testInstance, ResourceType.TEST_CYCLE, true);
                        ALMResponseData response = QCRestAPIConnect.UpdateEntity(ResourceType.TEST_CYCLE, testInstance.Id, item);

                        if (response.IsSucceed)
                        {
                            testInstances.Add(QCRestAPIConnect.GetTestInstanceDetails(testInstance.Id));
                            ag.ExternalID2 = response.IdCreated;//the test case instance ID in the test set- used for exporting the execution details
                        }
                    }
                    catch (Exception ex)
                    {
                        Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}");
                    }
                }
            }
        }
        private static QCTestSet CreateNewTestSet(BusinessFlow businessFlow, string uploadPath, ObservableList <ExternalItemFieldBase> testSetFields)
        {
            QCTestSet testSet = new QCTestSet();

            //set the upload path
            testSet.ElementsField["parent-id"] = QCRestAPIConnect.GetLastTestSetIdFromPath(uploadPath).ToString();

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

            testSet.ElementsField["name"]       = businessFlow.Name;
            testSet.ElementsField["subtype-id"] = "hp.qc.test-set.default";

            try
            {
                QCItem          item     = ConvertObjectValuesToQCItem(testSet, ResourceType.TEST_SET);
                ALMResponseData response = QCRestAPIConnect.CreateNewEntity(ResourceType.TEST_SET, item);
                return(QCRestAPIConnect.GetTestSetDetails(response.IdCreated));
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("The Test Set already exists"))
                {
                    string result = "Cannot export Business Flow - The Test Set already exists in the selected folder. ";
                    Reporter.ToLog(eLogLevel.ERROR, result, ex);
                    return(null);
                }

                Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}");
                return(null);
            }
        }
    void OnClickQCSelected(QCItem qc)
    {
        if (qc.qpm.number <= 0)
        {
            Debug.LogError("QC OnClickQCSelected");
        }

        SettleNowInvenItem(qc.qpm.mob, qc.qpm.evidence);

        if (qc.qpm.number == 1)
        {
            selectedItem.Remove(qc);
            Destroy(qc.go);
            return;
        }
        qc.qpm.number--;
        qc.numText.text = qc.qpm.number.ToString();
    }
        private static void CreateNewTestInstances(BusinessFlow businessFlow, ObservableList <ActivitiesGroup> existingActivitiesGroups, QCTestSet testSet, ObservableList <ExternalItemFieldBase> testInstancesFields)
        {
            int counter = 1;

            foreach (ActivitiesGroup ag in businessFlow.ActivitiesGroups)
            {
                if (existingActivitiesGroups.Contains(ag) == false && string.IsNullOrEmpty(ag.ExternalID) == false && ImportFromQCRest.GetQCTest(ag.ExternalID) != null)
                {
                    QCTestInstance testInstance = new QCTestInstance
                    {
                        TestId    = ag.ExternalID,
                        CycleId   = testSet.Id,
                        TestOrder = counter++.ToString(),
                    };

                    //set item fields for test instances
                    foreach (ExternalItemFieldBase field in testInstancesFields)
                    {
                        if ((field.ToUpdate || field.Mandatory) && (!(field.ExternalID == "test-id") && !(field.ExternalID == "cycle-id")))
                        {
                            if (string.IsNullOrEmpty(field.ExternalID) == false && field.SelectedValue != "NA")
                            {
                                testInstance.ElementsField[field.ExternalID] = field.SelectedValue;
                            }
                            else
                            {
                                try { testInstance.ElementsField[field.ID] = "NA"; }
                                catch { }
                            }
                        }
                    }

                    testInstance.ElementsField["subtype-id"] = "hp.qc.test-instance.MANUAL";
                    QCItem          item     = ConvertObjectValuesToQCItem(testInstance, ResourceType.TEST_CYCLE);
                    ALMResponseData response = QCRestAPIConnect.CreateNewEntity(ResourceType.TEST_CYCLE, item);

                    if (response.IsSucceed) // # Currently bug in HPE failing the test instance creation despite it working.
                    {
                        //QCTestInstance testInstanceCreated = QCRestAPIConnect.QcRestClient.GetTestInstanceDetails(response.IdCreated);
                        ag.ExternalID2 = response.IdCreated;//the test case instance ID in the test set- used for exporting the execution details
                    }
                }
            }
        }
    public void SettleSelectItem(E_Monster mob, E_Evidence evidence)  //셀렉티드 아이템이 만들어지는 곳.
    {
        QuestPerMob qpm = new QuestPerMob(mob, evidence, 1);

        if (selectedItem == null)
        {
            selectedItem = new List <QCItem>();
        }
        for (int i = 0; i < selectedItem.Count; i++)
        {
            if (selectedItem[i].qpm.IsIt(mob, evidence))
            {
                selectedItem[i].qpm.number++;
                selectedItem[i].numText.text = selectedItem[i].qpm.number.ToString();
                return;
            }
        }

        //새로 만들 차례
        GameObject temp = Instantiate(itemBtn);
        Text       numText;

        SetItemBtnCtx(temp, qpm, out numText);
        QCItem qc = new QCItem(temp, numText, qpm);

        selectedItem.Add(qc);

        Button btn = temp.GetComponent <Button>();

        btn.onClick.AddListener(
            () =>
        {
            AudioThing.GetInstance().PlaySFX(AudioThing.E_SFX.CLICK);
            OnClickQCSelected(qc);
        }
            );


        temp.transform.SetParent(nowSelectedContents.transform);
    }
        private static QCTestCase CreateNewTestCase(ActivitiesGroup activitiesGroup, string uploadPath, ObservableList <ExternalItemFieldBase> testCaseFields)
        {
            QCTestCase test = new QCTestCase();

            test.ElementsField["subtype-id"] = "MANUAL";
            test.ElementsField["parent-id"]  = QCRestAPIConnect.GetLastTestPlanIdFromPath(uploadPath).ToString();

            //set item fields
            foreach (ExternalItemFieldBase field in testCaseFields)
            {
                if (field.ToUpdate || field.Mandatory)
                {
                    if (string.IsNullOrEmpty(field.SelectedValue) == false && field.SelectedValue != "NA")
                    {
                        test.ElementsField.Add(field.ExternalID, field.SelectedValue);
                    }
                    else
                    {
                        try { test.ElementsField.Add(field.ExternalID, "NA"); }
                        catch { }
                    }
                }
            }

            //post the test
            test.ElementsField["name"]        = activitiesGroup.Name;
            test.ElementsField["description"] = activitiesGroup.Description;
            QCItem          item     = ConvertObjectValuesToQCItem(test, ResourceType.TEST_CASE);
            ALMResponseData response = QCRestAPIConnect.CreateNewEntity(ResourceType.TEST_CASE, item);

            test.Id = response.IdCreated;
            activitiesGroup.ExternalID  = test.Id;
            activitiesGroup.ExternalID2 = test.Id;

            return(QCRestAPIConnect.GetTestCases(new List <string> {
                test.Id
            })[0]);
        }
        private static QCTestCase UpdateExistingTestCase(QCTestCase mappedTest, ActivitiesGroup activitiesGroup, ObservableList <ExternalItemFieldBase> testCaseFields)
        {
            QCTestCase test = mappedTest;

            //set item fields
            foreach (ExternalItemFieldBase field in testCaseFields)
            {
                if (field.ToUpdate || field.Mandatory)
                {
                    if (string.IsNullOrEmpty(field.SelectedValue) == false && field.SelectedValue != "NA")
                    {
                        if (test.ElementsField.ContainsKey(field.ExternalID))
                        {
                            test.ElementsField[field.ExternalID] = field.SelectedValue;
                        }
                    }

                    else
                    {
                        try { test.ElementsField.Add(field.ExternalID, "NA"); }
                        catch { }
                    }
                }
            }

            //update the test
            test.ElementsField["name"]        = activitiesGroup.Name;
            test.ElementsField["description"] = activitiesGroup.Description;
            QCItem          item     = ConvertObjectValuesToQCItem(test, ResourceType.TEST_CASE, true);
            ALMResponseData response = QCRestAPIConnect.UpdateEntity(ResourceType.TEST_CASE, test.Id, item);

            activitiesGroup.ExternalID  = test.Id;
            activitiesGroup.ExternalID2 = test.Id;

            return(test);
        }
        private static void UpdateTestStep(QCTestCase test, ActivitiesGroup activitiesGroup, Activity identifiedActivity, ObservableList <ExternalItemFieldBase> designStepsFields, ObservableList <ExternalItemFieldBase> designStepsParamsFields)
        {
            QCTestCaseStepsColl testCaseDesignStep = QCRestAPIConnect.GetTestCasesSteps(new List <string> {
                test.Id
            });

            //delete the un-needed steps
            foreach (QCTestCaseStep step in testCaseDesignStep)
            {
                if (activitiesGroup.ActivitiesIdentifiers.Where(x => x.IdentifiedActivity.ExternalID == step.Id.ToString()).FirstOrDefault() == null)
                {
                    QCRestAPIConnect.DeleteEntity(ALM_Common.DataContracts.ResourceType.DESIGN_STEP, step.Id);
                }
            }

            //delete the existing parameters
            QCTestCaseParamsColl testCaseParams = QCRestAPIConnect.GetTestCaseParams(test.Id);

            if (testCaseParams.Count > 0)
            {
                for (int indx = 0; indx < testCaseParams.Count; indx++)
                {
                    QCRestAPIConnect.DeleteEntity(ALM_Common.DataContracts.ResourceType.DESIGN_STEP_PARAMETERS, testCaseParams[indx].Id);
                }
            }

            foreach (QCTestCaseStep step in testCaseDesignStep)
            {
                //set item fields
                foreach (ExternalItemFieldBase field in designStepsFields)
                {
                    if (field.ToUpdate || field.Mandatory)
                    {
                        if (string.IsNullOrEmpty(field.SelectedValue) == false && field.SelectedValue != "NA")
                        {
                            if (step.ElementsField.ContainsKey(field.ExternalID))
                            {
                                step.ElementsField[field.ExternalID] = field.SelectedValue;
                            }
                        }
                    }
                }

                step.ElementsField["name"] = identifiedActivity.ActivityName;
                string descriptionTemplate =
                    "<html><body><div align=\"left\"><font face=\"Arial\"><span style=\"font-size:8pt\"><<&Description&&>><br /><<&Parameters&>><br /><<&Actions&>></span></font></div></body></html>";
                string description = descriptionTemplate.Replace("<<&Description&&>>", identifiedActivity.Description);

                QCTestCaseParamsColl testParams = QCRestAPIConnect.GetTestCaseParams(test.Id);
                string paramsSigns = string.Empty;
                if (identifiedActivity.Variables.Count > 0)
                {
                    paramsSigns = "<br />Parameters:<br />";
                    foreach (VariableBase var in identifiedActivity.Variables)
                    {
                        paramsSigns += "&lt;&lt;&lt;" + var.Name.ToLower() + "&gt;&gt;&gt;<br />";
                        //try to add the paramter to the test case parameters list
                        try
                        {
                            QCTestCaseParam newParam = new QCTestCaseParam();

                            //set item fields
                            foreach (ExternalItemFieldBase field in designStepsParamsFields)
                            {
                                if (field.ToUpdate || field.Mandatory)
                                {
                                    if (string.IsNullOrEmpty(field.SelectedValue) == false && field.SelectedValue != "NA")
                                    {
                                        newParam.ElementsField.Add(field.ExternalID, field.SelectedValue);
                                    }
                                    else
                                    {
                                        try { newParam.ElementsField.Add(field.ExternalID, "NA"); }
                                        catch { }
                                    }
                                }
                            }

                            newParam.Name   = var.Name.ToLower();
                            newParam.TestId = test.Id;

                            QCItem itemTestCaseParam = ConvertObjectValuesToQCItem(newParam, ResourceType.TEST_CASE_PARAMETERS);
                            QCRestAPIConnect.CreateNewEntity(ResourceType.TEST_CASE_PARAMETERS, itemTestCaseParam);
                        }
                        catch (Exception ex) { Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}"); }
                    }
                }

                description = description.Replace("<<&Parameters&>>", paramsSigns);

                string actsDesc = string.Empty;
                if (identifiedActivity.Acts.Count > 0)
                {
                    actsDesc = "Actions:<br />";
                    foreach (Act act in identifiedActivity.Acts)
                    {
                        actsDesc += act.Description + "<br />";
                    }
                }
                description      = description.Replace("<<&Actions&>>", actsDesc);
                step.Description = description;
                step.ElementsField["expected"] = identifiedActivity.Expected;

                QCItem          itemDesignStep = ConvertObjectValuesToQCItem(step, ResourceType.DESIGN_STEP, true);
                ALMResponseData response       = QCRestAPIConnect.UpdateEntity(ResourceType.DESIGN_STEP, step.Id, itemDesignStep);

                identifiedActivity.ExternalID = step.Id;
            }
        }
        private static bool CreateTestStep(QCTestCase test, Activity activity, ObservableList <ExternalItemFieldBase> designStepsFields, ObservableList <ExternalItemFieldBase> designStepsParamsFields, int stepOrder)
        {
            //create new step
            QCTestCaseStep step = new QCTestCaseStep();

            //set item fields
            foreach (ExternalItemFieldBase field in designStepsFields)
            {
                if (field.ToUpdate || field.Mandatory)
                {
                    if (string.IsNullOrEmpty(field.SelectedValue) == false && field.SelectedValue != "NA")
                    {
                        step.ElementsField.Add(field.ExternalID, field.SelectedValue);
                    }
                    else
                    {
                        try { step.ElementsField.Add(field.ExternalID, "NA"); }
                        catch { }
                    }
                }
            }

            step.ElementsField["name"]       = activity.ActivityName;
            step.ElementsField["parent-id"]  = test.Id;
            step.ElementsField["step-order"] = stepOrder.ToString();

            string descriptionTemplate =
                "<html><body><div align=\"left\"><font face=\"Arial\"><span style=\"font-size:8pt\"><<&Description&&>><br /><<&Parameters&>><br /><<&Actions&>></span></font></div></body></html>";
            string description = descriptionTemplate.Replace("<<&Description&&>>", activity.Description);
            QCTestCaseParamsColl testParams = QCRestAPIConnect.GetTestCaseParams(test.Id);
            string paramsSigns = string.Empty;

            if (activity.Variables.Count > 0)
            {
                paramsSigns = "<br />Parameters:<br />";
                foreach (VariableBase var in activity.Variables)
                {
                    paramsSigns += "&lt;&lt;&lt;" + var.Name.ToLower() + "&gt;&gt;&gt;<br />";
                    //try to add the paramter to the test case parameters list
                    try
                    {
                        QCTestCaseParam newParam = new QCTestCaseParam();

                        //set item fields
                        foreach (ExternalItemFieldBase field in designStepsParamsFields)
                        {
                            if (field.ToUpdate || field.Mandatory)
                            {
                                if (string.IsNullOrEmpty(field.SelectedValue) == false && field.SelectedValue != "NA")
                                {
                                    newParam.ElementsField.Add(field.ExternalID, field.SelectedValue);
                                }
                                else
                                {
                                    try { newParam.ElementsField.Add(field.ExternalID, "NA"); }
                                    catch { }
                                }
                            }
                        }

                        newParam.Name   = var.Name.ToLower();
                        newParam.TestId = test.Id;

                        QCItem itemTestCaseParam = ConvertObjectValuesToQCItem(newParam, ResourceType.TEST_CASE_PARAMETERS);
                        QCRestAPIConnect.CreateNewEntity(ResourceType.TEST_CASE_PARAMETERS, itemTestCaseParam);
                    }
                    catch (Exception ex) { Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}"); }
                }
            }
            description = description.Replace("<<&Parameters&>>", paramsSigns);

            string actsDesc = string.Empty;

            if (activity.Acts.Count > 0)
            {
                actsDesc = "Actions:<br />";
                foreach (Act act in activity.Acts)
                {
                    actsDesc += act.Description + "<br />";
                }
            }
            description      = description.Replace("<<&Actions&>>", actsDesc);
            step.Description = description;
            step.ElementsField["expected"] = activity.Expected;

            QCItem          itemDesignStep = ConvertObjectValuesToQCItem(step, ResourceType.DESIGN_STEP);
            ALMResponseData response       = QCRestAPIConnect.CreateNewEntity(ResourceType.DESIGN_STEP, itemDesignStep);

            activity.ExternalID = response.IdCreated;

            if (activity.ExternalID != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 15
0
 public static ALMResponseData UpdateEntity(ResourceType resourceType, string id, QCItem itemDesignStep)
 {
     try
     {
         return(QcRestClient.UpdateEntity(resourceType, id, itemDesignStep));
     }
     catch (Exception ex)
     {
         Reporter.ToLog(eAppReporterLogLevel.ERROR, "Failed to update entity with REST API", ex);
         return(null);
     }
 }
        public static bool ExportExceutionDetailsToALM(BusinessFlow bizFlow, ref string result, ObservableList <ExternalItemFieldBase> runFields, bool exectutedFromAutomateTab, PublishToALMConfig publishToALMConfig = null)
        {
            result = string.Empty;
            if (bizFlow.ExternalID == "0" || String.IsNullOrEmpty(bizFlow.ExternalID))
            {
                result = GingerDicser.GetTermResValue(eTermResKey.BusinessFlow) + ": " + bizFlow.Name + " is missing ExternalID, cannot locate QC TestSet without External ID";
                return(false);
            }

            try
            {
                //get the BF matching test set
                QCTestSet testSet = ImportFromQCRest.GetQCTestSet(bizFlow.ExternalID);//bf.externalID holds the TestSet TSTests collection id
                if (testSet != null)
                {
                    //get the Test set TC's
                    QCTestInstanceColl qcTSTests = QCRestAPIConnect.GetTestInstancesOfTestSet(testSet.Id); //list of TSTest's on main TestSet in TestLab

                    //get all BF Activities groups
                    ObservableList <ActivitiesGroup> activGroups = bizFlow.ActivitiesGroups;
                    if (activGroups.Count > 0)
                    {
                        foreach (ActivitiesGroup activGroup in activGroups)
                        {
                            if ((publishToALMConfig.FilterStatus == FilterByStatus.OnlyPassed && activGroup.RunStatus == ActivitiesGroup.eActivitiesGroupRunStatus.Passed) ||
                                (publishToALMConfig.FilterStatus == FilterByStatus.OnlyFailed && activGroup.RunStatus == ActivitiesGroup.eActivitiesGroupRunStatus.Failed) ||
                                publishToALMConfig.FilterStatus == FilterByStatus.All)
                            {
                                QCTestInstance tsTest = null;
                                //go by TC ID = TC Instancs ID
                                tsTest = qcTSTests.Find(x => x.TestId == activGroup.ExternalID && x.Id == activGroup.ExternalID2);
                                if (tsTest == null)
                                {
                                    //go by Linked TC ID + TC Instancs ID
                                    tsTest = qcTSTests.Find(x => ImportFromQCRest.GetTSTestLinkedID(x) == activGroup.ExternalID && x.Id == activGroup.ExternalID2);
                                }
                                if (tsTest == null)
                                {
                                    //go by TC ID
                                    tsTest = qcTSTests.Find(x => x.TestId == activGroup.ExternalID);
                                }
                                if (tsTest != null)
                                {
                                    //get activities in group
                                    List <Activity> activities   = (bizFlow.Activities.Where(x => x.ActivitiesGroupID == activGroup.Name)).Select(a => a).ToList();
                                    string          TestCaseName = PathHelper.CleanInValidPathChars(tsTest.Name);
                                    if ((publishToALMConfig.VariableForTCRunName == null) || (publishToALMConfig.VariableForTCRunName == string.Empty))
                                    {
                                        String timeStamp = DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss");
                                        publishToALMConfig.VariableForTCRunName = "GingerRun_" + timeStamp;
                                    }

                                    QCRun runToExport = new QCRun();

                                    foreach (ExternalItemFieldBase field in runFields)
                                    {
                                        if (field.ToUpdate || field.Mandatory)
                                        {
                                            if (string.IsNullOrEmpty(field.SelectedValue) == false && field.SelectedValue != "NA")
                                            {
                                                runToExport.ElementsField.Add(field.ExternalID, field.SelectedValue);
                                            }
                                            else
                                            {
                                                try { runToExport.ElementsField.Add(field.ExternalID, "NA"); }
                                                catch { }
                                            }
                                        }
                                    }

                                    runToExport.ElementsField["name"]        = publishToALMConfig.VariableForTCRunNameCalculated;
                                    runToExport.ElementsField["test-id"]     = tsTest.TestId;
                                    runToExport.ElementsField["testcycl-id"] = tsTest.Id;
                                    runToExport.ElementsField["cycle-id"]    = tsTest.CycleId;
                                    runToExport.ElementsField["duration"]    = "0";
                                    runToExport.ElementsField["subtype-id"]  = "hp.qc.run.MANUAL";
                                    runToExport.ElementsField["owner"]       = ALMCore.AlmConfig.ALMUserName;

                                    QCItem          itemToExport = ConvertObjectValuesToQCItem(runToExport, ResourceType.TEST_RUN);
                                    ALMResponseData responseData = QCRestAPIConnect.CreateNewEntity(ResourceType.TEST_RUN, itemToExport);
                                    if (!responseData.IsSucceed)
                                    {
                                        result = "Failed to create run using rest API";
                                        return(false);
                                    }
                                    QCRun currentRun = QCRestAPIConnect.GetRunDetail(responseData.IdCreated);

                                    // Attach ActivityGroup Report if needed
                                    if (publishToALMConfig.ToAttachActivitiesGroupReport)
                                    {
                                        if ((activGroup.TempReportFolder != null) && (activGroup.TempReportFolder != string.Empty) &&
                                            (System.IO.Directory.Exists(activGroup.TempReportFolder)))
                                        {
                                            //Creating the Zip file - start
                                            string targetZipPath = System.IO.Directory.GetParent(activGroup.TempReportFolder).ToString();
                                            string zipFileName   = targetZipPath + "\\" + TestCaseName.ToString() + "_GingerHTMLReport.zip";

                                            if (!System.IO.File.Exists(zipFileName))
                                            {
                                                ZipFile.CreateFromDirectory(activGroup.TempReportFolder, zipFileName);
                                            }
                                            else
                                            {
                                                System.IO.File.Delete(zipFileName);
                                                ZipFile.CreateFromDirectory(activGroup.TempReportFolder, zipFileName);
                                            }
                                            System.IO.Directory.Delete(activGroup.TempReportFolder, true);
                                            //Creating the Zip file - finish
                                            //Attaching Zip file - start
                                            //AttachmentFactory attachmentFactory = (AttachmentFactory)run.Attachments;
                                            //TDAPIOLELib.Attachment attachment = (TDAPIOLELib.Attachment)attachmentFactory.AddItem(System.DBNull.Value);
                                            //attachment.Description = "TC Ginger Execution HTML Report";
                                            //attachment.Type = 1;
                                            //attachment.FileName = zipFileName;
                                            //attachment.Post();

                                            //Attaching Zip file - finish
                                            System.IO.File.Delete(zipFileName);
                                        }
                                    }


                                    //create run with activities as steps
                                    QCRunStepColl runSteps = ImportFromQCRest.GetRunSteps(currentRun.Id);

                                    int index = 1;
                                    foreach (QCRunStep runStep in runSteps)
                                    {
                                        //search for matching activity based on ID and not order, un matching steps need to be left as No Run
                                        string   stepName         = runStep.Name;
                                        Activity matchingActivity = activities.Where(x => x.ExternalID == runStep.ElementsField["desstep-id"].ToString()).FirstOrDefault();
                                        if (matchingActivity != null)
                                        {
                                            switch (matchingActivity.Status)
                                            {
                                            case Amdocs.Ginger.CoreNET.Execution.eRunStatus.Failed:
                                                runStep.Status = "Failed";
                                                List <Act> failedActs = matchingActivity.Acts.Where(x => x.Status == Amdocs.Ginger.CoreNET.Execution.eRunStatus.Failed).ToList();
                                                string     errors     = string.Empty;
                                                foreach (Act act in failedActs)
                                                {
                                                    errors += act.Error + Environment.NewLine;
                                                }
                                                runStep.Actual = errors;
                                                break;

                                            case Amdocs.Ginger.CoreNET.Execution.eRunStatus.NA:
                                                runStep.ElementsField["status"] = "N/A";
                                                runStep.ElementsField["actual"] = "NA";
                                                break;

                                            case Amdocs.Ginger.CoreNET.Execution.eRunStatus.Passed:
                                                runStep.ElementsField["status"] = "Passed";
                                                runStep.ElementsField["actual"] = "Passed as expected";
                                                break;

                                            case Amdocs.Ginger.CoreNET.Execution.eRunStatus.Skipped:
                                                runStep.ElementsField["status"] = "N/A";
                                                runStep.ElementsField["actual"] = "Skipped";
                                                break;

                                            case Amdocs.Ginger.CoreNET.Execution.eRunStatus.Pending:
                                                runStep.ElementsField["status"] = "No Run";
                                                runStep.ElementsField["actual"] = "Was not executed";
                                                break;

                                            case Amdocs.Ginger.CoreNET.Execution.eRunStatus.Running:
                                                runStep.ElementsField["status"] = "Not Completed";
                                                runStep.ElementsField["actual"] = "Not Completed";
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            //Step not exist in Ginger so left as "No Run" unless it is step data
                                            if (runStep.Name.ToUpper() == "STEP DATA")
                                            {
                                                runStep.ElementsField["status"] = "Passed";
                                            }
                                            else
                                            {
                                                runStep.ElementsField["status"] = "No Run";
                                            }
                                        }

                                        QCItem          stepToUpdate      = ConvertObjectValuesToQCItem(runStep, ResourceType.RUN_STEP);
                                        ALMResponseData stepDataForUpdate = QCRestAPIConnect.UpdateEntity(ResourceType.RUN_STEP, runStep.Id, stepToUpdate);

                                        index++;
                                    }

                                    //get all execution status for all steps
                                    ObservableList <string> stepsStatuses = new ObservableList <string>();
                                    foreach (QCRunStep runStep in runSteps)
                                    {
                                        stepsStatuses.Add(runStep.Status);
                                    }

                                    //update the TC general status based on the activities status collection.
                                    if (stepsStatuses.Where(x => x == "Failed").Count() > 0)
                                    {
                                        currentRun.Status = "Failed";
                                    }
                                    else if (stepsStatuses.Where(x => x == "No Run").Count() == runSteps.Count || stepsStatuses.Where(x => x == "N/A").Count() == runSteps.Count)
                                    {
                                        currentRun.Status = "No Run";
                                    }
                                    else if (stepsStatuses.Where(x => x == "Passed").Count() == runSteps.Count || (stepsStatuses.Where(x => x == "Passed").Count() + stepsStatuses.Where(x => x == "N/A").Count()) == runSteps.Count)
                                    {
                                        currentRun.ElementsField["status"] = "Passed";
                                    }
                                    else
                                    {
                                        currentRun.ElementsField["status"] = "Not Completed";
                                    }

                                    QCItem          runToUpdate      = ConvertObjectValuesToQCItem(currentRun, ResourceType.TEST_RUN);
                                    ALMResponseData runDataForUpdate = QCRestAPIConnect.UpdateEntity(ResourceType.TEST_RUN, currentRun.Id, runToUpdate);
                                }
                                else
                                {
                                    //No matching TC was found for the ActivitiesGroup in QC
                                    result = "Matching TC's were not found for all " + GingerDicser.GetTermResValue(eTermResKey.ActivitiesGroups) + " in QC/ALM.";
                                }
                            }
                            if (result != string.Empty)
                            {
                                return(false);
                            }
                        }
                    }
                    else
                    {
                        //No matching Test Set was found for the BF in QC
                        result = "No matching Test Set was found in QC/ALM.";
                    }

                    if (result == string.Empty)
                    {
                        result = "Export performed successfully.";
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                result = "Unexpected error occurred- " + ex.Message;
                Reporter.ToLog(eLogLevel.ERROR, "Failed to export execution details to QC/ALM", ex);
                return(false);
            }

            return(false); // Remove it at the end
        }
Esempio n. 17
0
        public override bool ExportBusinessFlowToALM(BusinessFlow businessFlow, bool performSaveAfterExport = false, ALMIntegration.eALMConnectType almConectStyle = ALMIntegration.eALMConnectType.Manual, string testPlanUploadPath = null, string testLabUploadPath = null)
        {
            if (businessFlow == null)
            {
                return(false);
            }

            if (businessFlow.ActivitiesGroups.Count == 0)
            {
                Reporter.ToUser(eUserMsgKey.StaticInfoMessage, "The " + GingerDicser.GetTermResValue(eTermResKey.BusinessFlow) + " do not include " + GingerDicser.GetTermResValue(eTermResKey.ActivitiesGroups) + " which supposed to be mapped to ALM Test Cases, please add at least one " + GingerDicser.GetTermResValue(eTermResKey.ActivitiesGroup) + " before doing export.");
                return(false);
            }

            QCRestClient.QCTestSet matchingTS = null;

            Amdocs.Ginger.Common.eUserMsgSelection userSelec = Amdocs.Ginger.Common.eUserMsgSelection.None;
            //check if the businessFlow already mapped to QC Test Set
            if (String.IsNullOrEmpty(businessFlow.ExternalID) == false)
            {
                matchingTS = ((QCRestAPICore)ALMIntegration.Instance.AlmCore).GetQCTestSet(businessFlow.ExternalID);
                if (matchingTS != null)
                {
                    //ask user if want to continute
                    userSelec = Reporter.ToUser(eUserMsgKey.BusinessFlowAlreadyMappedToTC, businessFlow.Name, matchingTS.Name);
                    if (userSelec == Amdocs.Ginger.Common.eUserMsgSelection.Cancel)
                    {
                        return(false);
                    }
                    else if (userSelec == Amdocs.Ginger.Common.eUserMsgSelection.No)
                    {
                        matchingTS = null;
                    }
                }
            }


            //check if all of the business flow activities groups already exported to QC and export the ones which not
            foreach (ActivitiesGroup ag in businessFlow.ActivitiesGroups)
            {
                //
                matchingTC = null;
                //check if the ActivitiesGroup already mapped to QC Test Case
                if (String.IsNullOrEmpty(ag.ExternalID) == false)
                {
                    matchingTC = ((QCRestAPICore)ALMIntegration.Instance.AlmCore).GetQCTest(ag.ExternalID);
                    if (matchingTC != null)
                    {
                        //ask user if want to continute
                        Amdocs.Ginger.Common.eUserMsgSelection userSelect = Reporter.ToUser(eUserMsgKey.ActivitiesGroupAlreadyMappedToTC, ag.Name, matchingTC.Name);
                        if (userSelect == Amdocs.Ginger.Common.eUserMsgSelection.Cancel)
                        {
                            return(false);
                        }
                        else if (userSelect == Amdocs.Ginger.Common.eUserMsgSelection.No)
                        {
                            matchingTC = null;
                        }
                        else
                        {
                            if (String.IsNullOrEmpty(testPlanUploadPath))
                            {
                                //testPlanUploadPath = "";
                                string parentId = matchingTC.ElementsField["parent-id"].ToString();

                                //need to test as the function changed in the library
                                QCTestFolder testPlanFolder = QCRestAPIConnect.QcRestClient.GetTestPlanFolderDetails(parentId);
                                string       revrsePath     = testPlanFolder.Name + "/";

                                string testPlanRootFolderId = QCRestAPIConnect.QcRestClient.GetTestPlanRootFolder().Id;
                                while (testPlanFolder.Id != testPlanRootFolderId)
                                {
                                    testPlanFolder = QCRestAPIConnect.QcRestClient.GetTestPlanFolderDetails(testPlanFolder.ParentId);
                                    revrsePath     = revrsePath + testPlanFolder.Name + "/";
                                }
                                revrsePath = revrsePath.Substring(0, revrsePath.Length - 1);
                                string[] str = revrsePath.Split('/');
                                Array.Reverse(str);
                                testPlanUploadPath = string.Join("\\", str);
                            }
                        }
                    }
                }

                //if user selected No and want to create new testplans to selected folder path
                if (matchingTC == null && String.IsNullOrEmpty(testPlanUploadPath))
                {
                    //get the QC Test Plan path to upload the activities group to
                    testPlanUploadPath = SelectALMTestPlanPath();
                    if (String.IsNullOrEmpty(testPlanUploadPath))
                    {
                        //no path to upload to
                        return(false);
                    }
                    //create upload path if checked to create separete folder
                    if (QCTestPlanFolderTreeItem.IsCreateBusinessFlowFolder)
                    {
                        try
                        {
                            string newFolderId = QCRestAPIConnect.GetLastTestPlanIdFromPath(testPlanUploadPath).ToString();
                            QCItem newFolder   = new QCItem();
                            newFolder.Fields.Add("name", businessFlow.Name);
                            newFolder.Fields.Add("parent-id", QCRestAPIConnect.GetLastTestPlanIdFromPath(testPlanUploadPath).ToString());
                            ALMResponseData responseData = QCRestAPIConnect.CreateNewEntity(ResourceType.TEST_FOLDERS, newFolder);
                            newFolderId        = responseData.IdCreated;
                            testPlanUploadPath = testPlanUploadPath + "\\" + businessFlow.Name;
                        }
                        catch (Exception ex)
                        {
                            Reporter.ToLog(eLogLevel.ERROR, "Failed to get create folder for Test Plan with REST API", ex);
                        }
                    }
                }

                ExportActivitiesGroupToALM(ag, testPlanUploadPath, false, businessFlow);
            }

            if (matchingTS == null && string.IsNullOrEmpty(testLabUploadPath))
            {
                if (userSelec == Amdocs.Ginger.Common.eUserMsgSelection.No)
                {
                    Reporter.ToUser(eUserMsgKey.ExportQCNewTestSetSelectDiffFolder);
                }

                //get the QC Test Plan path to upload the activities group to
                testLabUploadPath = SelectALMTestLabPath();
                if (String.IsNullOrEmpty(testLabUploadPath))
                {
                    //no path to upload to
                    return(false);
                }
            }

            //upload the business flow
            Reporter.ToStatus(eStatusMsgKey.ExportItemToALM, null, businessFlow.Name);
            string res = string.Empty;

            ObservableList <ExternalItemFieldBase> allFields = new ObservableList <ExternalItemFieldBase>(WorkSpace.Instance.Solution.ExternalItemsFields);

            ALMIntegration.Instance.RefreshALMItemFields(allFields, true, null);

            ObservableList <ExternalItemFieldBase> testSetFieldsFields = CleanUnrelvantFields(allFields, ResourceType.TEST_SET);
            ObservableList <ExternalItemFieldBase> testInstanceFields  = CleanUnrelvantFields(allFields, ResourceType.TEST_CYCLE);

            bool exportRes = ((QCRestAPICore)ALMIntegration.Instance.AlmCore).ExportBusinessFlowToALM(businessFlow, matchingTS, testLabUploadPath, testSetFieldsFields, testInstanceFields, ref res);

            Reporter.HideStatusMessage();
            if (exportRes)
            {
                if (performSaveAfterExport)
                {
                    Reporter.ToStatus(eStatusMsgKey.SaveItem, null, businessFlow.Name, GingerDicser.GetTermResValue(eTermResKey.BusinessFlow));
                    WorkSpace.Instance.SolutionRepository.SaveRepositoryItem(businessFlow);
                    Reporter.HideStatusMessage();
                }
                if (almConectStyle != ALMIntegration.eALMConnectType.Auto)
                {
                    Reporter.ToUser(eUserMsgKey.ExportItemToALMSucceed);
                }
                return(true);
            }
            else
            if (almConectStyle != ALMIntegration.eALMConnectType.Auto)
            {
                Reporter.ToUser(eUserMsgKey.ExportItemToALMFailed, GingerDicser.GetTermResValue(eTermResKey.BusinessFlow), businessFlow.Name, res);
            }

            return(false);
        }