Beispiel #1
0
        public ObservableList <RallyTestPlan> GetRallyTestPlansByProject(string RallyServerUrl, string RallyUserName, string RallyPassword, string RallyProject, string solutionFolder, string projName)
        {
            ObservableList <RallyTestPlan> rallyTestPlanList = new ObservableList <RallyTestPlan>();

            RallyRestApi restApi = new RallyRestApi();

            restApi.Authenticate(RallyUserName, RallyPassword, RallyServerUrl, proxy: null, allowSSO: false);

            if (restApi.AuthenticationState == RallyRestApi.AuthenticationResult.Authenticated)
            {
                DynamicJsonObject sub      = restApi.GetSubscription("Workspaces");
                Request           wRequest = new Request(sub["Workspaces"]);
                wRequest.Limit = 1000;
                int         projectId     = 0;
                QueryResult queryWSResult = restApi.Query(wRequest);
                foreach (var result in queryWSResult.Results)
                {
                    Request projectsRequest = new Request(result["Projects"]);
                    projectsRequest.Fetch = new List <string>()
                    {
                        "Name", "ObjectID"
                    };
                    projectsRequest.Limit = 10000;
                    QueryResult queryProjectResult = restApi.Query(projectsRequest);
                    foreach (var p in queryProjectResult.Results)
                    {
                        if (Convert.ToString(p["Name"]) == projName)
                        {
                            int.TryParse(Convert.ToString(p["ObjectID"]), out projectId);
                            break;
                        }
                    }
                }

                if (projectId > 0)
                {
                    //Query for items
                    Request request    = new Request("testset");
                    var     projectRef = "/project/" + projectId;
                    request.Query = new Query("Project", Query.Operator.Equals, projectRef);

                    QueryResult queryTestSetResult = restApi.Query(request);
                    foreach (var result in queryTestSetResult.Results)
                    {
                        RallyTestPlan plan      = new RallyTestPlan();
                        int           testSetId = 0;
                        int.TryParse(Convert.ToString(result["ObjectID"]), out testSetId);

                        if (testSetId > 0)
                        {
                            plan.Name         = Convert.ToString(result["Name"]);
                            plan.RallyID      = Convert.ToString(result["ObjectID"]);
                            plan.Description  = Convert.ToString(result["Description"]);
                            plan.CreatedBy    = Convert.ToString(result["Owner"]["_refObjectName"]);
                            plan.CreationDate = Convert.ToDateTime(result["CreationDate"]);
                            plan.TestCases    = new ObservableList <RallyTestCase>();
                        }
                        rallyTestPlanList.Add(plan);
                    }
                }
            }


            return(rallyTestPlanList);
        }
Beispiel #2
0
        public static BusinessFlow ConvertRallyTestPlanToBF(RallyTestPlan testPlan)
        {
            try
            {
                if (testPlan == null)
                {
                    return(null);
                }

                //Create Business Flow
                BusinessFlow busFlow = new BusinessFlow();
                busFlow.Name       = testPlan.Name;
                busFlow.ExternalID = "RallyID=" + testPlan.RallyID;
                busFlow.Status     = BusinessFlow.eBusinessFlowStatus.Development;
                busFlow.Activities = new ObservableList <Activity>();
                busFlow.Variables  = new ObservableList <VariableBase>();

                //Create Activities Group + Activities for each TC
                foreach (RallyTestCase tc in testPlan.TestCases)
                {
                    //check if the TC is already exist in repository
                    ActivitiesGroup tcActivsGroup;
                    ActivitiesGroup repoActivsGroup = null;
                    if (repoActivsGroup == null)
                    {
                        repoActivsGroup = GingerActivitiesGroupsRepo.Where(x => x.ExternalID != null ? x.ExternalID.Split('|').First().Split('=').Last() == tc.RallyID : false).FirstOrDefault();
                    }
                    if (repoActivsGroup != null)
                    {
                        tcActivsGroup = (ActivitiesGroup)repoActivsGroup.CreateInstance();
                        busFlow.AddActivitiesGroup(tcActivsGroup);
                        busFlow.ImportActivitiesGroupActivitiesFromRepository(tcActivsGroup, GingerActivitiesRepo, true, true);
                        busFlow.AttachActivitiesGroupsAndActivities();
                    }
                    else // TC not exist in Ginger repository so create new one
                    {
                        tcActivsGroup             = new ActivitiesGroup();
                        tcActivsGroup.Name        = tc.Name;
                        tcActivsGroup.Description = tc.Description;
                        tcActivsGroup.ExternalID  = "RallyID=" + tc.RallyID + "|AtsID=" + tc.BTSID;
                        busFlow.AddActivitiesGroup(tcActivsGroup);
                    }

                    foreach (RallyTestStep step in tc.TestSteps)
                    {
                        Activity stepActivity;
                        bool     toAddStepActivity = false;

                        // check if mapped activity exist in repository
                        Activity repoStepActivity = GingerActivitiesRepo.Where(x => x.ExternalID != null ? x.ExternalID.Split('|').First().Split('=').Last() == step.RallyIndex : false).FirstOrDefault();
                        if (repoStepActivity != null)
                        {
                            //check if it is part of the Activities Group
                            ActivityIdentifiers groupStepActivityIdent = tcActivsGroup.ActivitiesIdentifiers.Where(x => x.ActivityExternalID == step.RallyIndex).FirstOrDefault();
                            if (groupStepActivityIdent != null)
                            {
                                //already in Activities Group so get link to it
                                stepActivity = busFlow.Activities.Where(x => x.Guid == groupStepActivityIdent.ActivityGuid).FirstOrDefault();
                            }
                            else // not in ActivitiesGroup so get instance from repo
                            {
                                stepActivity      = (Activity)repoStepActivity.CreateInstance();
                                toAddStepActivity = true;
                            }
                        }
                        else //Step not exist in Ginger repository so create new one
                        {
                            string strBtsID = string.Empty;
                            stepActivity = new Activity();
                            stepActivity.ActivityName = tc.Name + ">" + step.Name;
                            stepActivity.ExternalID   = "RallyID=" + step.RallyIndex + "|AtsID=" + strBtsID;
                            stepActivity.Description  = StripHTML(step.Description);
                            stepActivity.Expected     = StripHTML(step.ExpectedResult);

                            toAddStepActivity = true;
                        }

                        if (toAddStepActivity)
                        {
                            // not in group- need to add it
                            busFlow.AddActivity(stepActivity);
                            tcActivsGroup.AddActivityToGroup(stepActivity);
                        }

                        //pull TC-Step parameters and add them to the Activity level
                        foreach (RallyTestParameter param in tc.Parameters)   // Params taken from TestScriptLevel only!!!! Also exists parapameters at TestCase, to check if them should be taken!!!
                        {
                            bool?isflowControlParam = null;

                            //detrmine if the param is Flow Control Param or not based on it value and agreed sign "$$_"
                            if (param.Value.ToString().StartsWith("$$_"))
                            {
                                isflowControlParam = false;
                                if (param.Value.ToString().StartsWith("$$_"))
                                {
                                    param.Value = param.Value.ToString().Substring(3); //get value without "$$_"
                                }
                            }
                            else if (param.Value.ToString() != "<Empty>")
                            {
                                isflowControlParam = true;
                            }

                            //check if already exist param with that name
                            VariableBase stepActivityVar = stepActivity.Variables.Where(x => x.Name.ToUpper() == param.Name.ToUpper()).FirstOrDefault();
                            if (stepActivityVar == null)
                            {
                                //#Param not exist so add it
                                if (isflowControlParam == true)
                                {
                                    //add it as selection list param
                                    stepActivityVar      = new VariableSelectionList();
                                    stepActivityVar.Name = param.Name;
                                    stepActivity.AddVariable(stepActivityVar);
                                    stepActivity.AutomationStatus = Activity.eActivityAutomationStatus.Development;//reset status because new flow control param was added
                                }
                                else
                                {
                                    //add as String param
                                    stepActivityVar      = new VariableString();
                                    stepActivityVar.Name = param.Name;
                                    ((VariableString)stepActivityVar).InitialStringValue = param.Value;
                                    stepActivity.AddVariable(stepActivityVar);
                                }
                            }
                            else
                            {
                                //#param exist
                                if (isflowControlParam == true)
                                {
                                    if (!(stepActivityVar is VariableSelectionList))
                                    {
                                        //flow control param must be Selection List so transform it
                                        stepActivity.Variables.Remove(stepActivityVar);
                                        stepActivityVar      = new VariableSelectionList();
                                        stepActivityVar.Name = param.Name;
                                        stepActivity.AddVariable(stepActivityVar);
                                        stepActivity.AutomationStatus = Activity.eActivityAutomationStatus.Development;//reset status because flow control param was added
                                    }
                                }
                                else if (isflowControlParam == false)
                                {
                                    if (stepActivityVar is VariableSelectionList)
                                    {
                                        //change it to be string variable
                                        stepActivity.Variables.Remove(stepActivityVar);
                                        stepActivityVar      = new VariableString();
                                        stepActivityVar.Name = param.Name;
                                        ((VariableString)stepActivityVar).InitialStringValue = param.Value;
                                        stepActivity.AddVariable(stepActivityVar);
                                        stepActivity.AutomationStatus = Activity.eActivityAutomationStatus.Development;//reset status because flow control param was removed
                                    }
                                }
                            }

                            //add the variable selected value
                            if (stepActivityVar is VariableSelectionList)
                            {
                                OptionalValue stepActivityVarOptionalVar = ((VariableSelectionList)stepActivityVar).OptionalValuesList.Where(x => x.Value == param.Value).FirstOrDefault();
                                if (stepActivityVarOptionalVar == null)
                                {
                                    //no such variable value option so add it
                                    stepActivityVarOptionalVar = new OptionalValue(param.Value);
                                    ((VariableSelectionList)stepActivityVar).OptionalValuesList.Add(stepActivityVarOptionalVar);
                                    if (isflowControlParam == true)
                                    {
                                        stepActivity.AutomationStatus = Activity.eActivityAutomationStatus.Development;//reset status because new param value was added
                                    }
                                }
                                //set the selected value
                                ((VariableSelectionList)stepActivityVar).SelectedValue = stepActivityVarOptionalVar.Value;
                            }
                            else
                            {
                                //try just to set the value
                                try
                                {
                                    stepActivityVar.Value = param.Value;
                                    if (stepActivityVar is VariableString)
                                    {
                                        ((VariableString)stepActivityVar).InitialStringValue = param.Value;
                                    }
                                }
                                catch (Exception ex) { Reporter.ToLog(eAppReporterLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); }
                            }
                        }
                    }
                }

                return(busFlow);
            }
            catch (Exception ex)
            {
                Reporter.ToLog(eAppReporterLogLevel.ERROR, "Failed to import Rally test set and convert it into " + GingerDicser.GetTermResValue(eTermResKey.BusinessFlow), ex);
                return(null);
            }
        }
Beispiel #3
0
        public RallyTestPlan GetRallyTestPlanFullData(string RallyServerUrl, string RallyUserName, string RallyPassword, string RallyProject, RallyTestPlan testPlan)
        {
            Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;

            RallyTestPlan plan = new RallyTestPlan();

            RallyRestApi restApi = new RallyRestApi();

            restApi.Authenticate(RallyUserName, RallyPassword, RallyServerUrl, proxy: null, allowSSO: false);

            if (restApi.AuthenticationState == RallyRestApi.AuthenticationResult.Authenticated)
            {
                DynamicJsonObject sub      = restApi.GetSubscription("Workspaces");
                Request           wRequest = new Request(sub["Workspaces"]);
                wRequest.Limit = 1000;
                int         projectId     = 0;
                QueryResult queryWSResult = restApi.Query(wRequest);
                foreach (var result in queryWSResult.Results)
                {
                    Request projectsRequest = new Request(result["Projects"]);
                    projectsRequest.Fetch = new List <string>()
                    {
                        "Name", "ObjectID"
                    };
                    projectsRequest.Limit = 10000;
                    QueryResult queryProjectResult = restApi.Query(projectsRequest);
                    foreach (var p in queryProjectResult.Results)
                    {
                        if (Convert.ToString(p["Name"]) == RallyProject)
                        {
                            int.TryParse(Convert.ToString(p["ObjectID"]), out projectId);
                            break;
                        }
                    }
                }

                if (projectId > 0)
                {
                    //Query for items
                    Request request    = new Request("testset");
                    var     projectRef = "/project/" + projectId;
                    request.Query = new Query("Project", Query.Operator.Equals, projectRef);

                    QueryResult queryTestSetResult = restApi.Query(request);
                    foreach (var result in queryTestSetResult.Results)
                    {
                        int testSetId = 0;
                        int.TryParse(Convert.ToString(result["ObjectID"]), out testSetId);

                        if (testSetId > 0 && testPlan.RallyID == Convert.ToString(result["ObjectID"]))
                        {
                            plan.Name         = Convert.ToString(result["Name"]);
                            plan.RallyID      = Convert.ToString(result["ObjectID"]);
                            plan.Description  = Convert.ToString(result["Description"]);
                            plan.CreatedBy    = Convert.ToString(result["Owner"]["_refObjectName"]);
                            plan.CreationDate = Convert.ToDateTime(result["CreationDate"]);
                            plan.TestCases    = new ObservableList <RallyTestCase>();

                            Request reqTestCase  = new Request("testcase");
                            var     testSetIdRef = "/testset/" + testSetId;
                            reqTestCase.Query = new Query("TestSets", Query.Operator.Equals, testSetIdRef);

                            QueryResult queryTestcaseResult = restApi.Query(reqTestCase);
                            foreach (var testCaseResult in queryTestcaseResult.Results)
                            {
                                string   name       = Convert.ToString(testCaseResult["Name"]);
                                string   id         = Convert.ToString(testCaseResult["ObjectID"]);
                                string   desc       = Convert.ToString(testCaseResult["Description"]);
                                string   owner      = Convert.ToString(testCaseResult["Owner"]["_refObjectName"]);
                                DateTime createDate = Convert.ToDateTime(testCaseResult["CreationDate"]);

                                RallyTestCase tcase      = new RallyTestCase(name, id, desc, owner, createDate);
                                string        scriptdesc = Convert.ToString(testCaseResult["ValidationInput"]);
                                RallyTestStep script     = new RallyTestStep("Test Step 1", string.Empty, scriptdesc, owner);
                                tcase.TestSteps.Add(script);

                                plan.TestCases.Add(tcase);
                            }
                        }
                    }
                }
            }

            Mouse.OverrideCursor = null;
            return(plan);
        }