public void AttachActivitiesGroupsAndActivities() { foreach (ActivitiesGroup group in this.ActivitiesGroups) { for (int indx = 0; indx < group.ActivitiesIdentifiers.Count;) { ActivityIdentifiers actIdentifis = group.ActivitiesIdentifiers[indx]; Activity activ = this.Activities.Where(act => act.ActivityName == actIdentifis.ActivityName && act.Guid == actIdentifis.ActivityGuid).FirstOrDefault(); if (activ == null) { activ = this.Activities.Where(act => act.Guid == actIdentifis.ActivityGuid).FirstOrDefault(); } if (activ == null) { activ = this.Activities.Where(act => act.ParentGuid == actIdentifis.ActivityGuid).FirstOrDefault(); } if (activ != null) { actIdentifis.IdentifiedActivity = activ; activ.ActivitiesGroupID = group.Name; indx++; } else { group.ActivitiesIdentifiers.RemoveAt(indx);//Activity not exist in BF anymore } } } }
private static Activity LinkStepAndUpdate(BusinessFlow busFlow, ActivityIdentifiers groupStepActivityIdent, QCTestCaseStep step, QCTestInstance testInstance) { Activity stepActivity; //already in Activities Group so get link to it stepActivity = (Activity)busFlow.Activities.Where(x => x.Guid == groupStepActivityIdent.ActivityGuid).FirstOrDefault(); // in any case update description/expected/name - even if "step" was taken from repository stepActivity.Description = StripHTML(step.Description); stepActivity.Expected = StripHTML(step.ElementsField["expected"].ToString()); stepActivity.ActivityName = testInstance.Name + ">" + step.Name; return(stepActivity); }
private string SetTargetApp() { if (mWizard.ParentActivitiesGroup.ActivitiesIdentifiers.Count > 0) { ActivityIdentifiers activityIdnt = mWizard.ParentActivitiesGroup.ActivitiesIdentifiers.Where(x => x.IdentifiedActivity != null && string.IsNullOrEmpty(x.IdentifiedActivity.TargetApplication) == false).FirstOrDefault(); if (activityIdnt != null) { return(activityIdnt.IdentifiedActivity.TargetApplication); } } if (mWizard.Context.BusinessFlow.TargetApplications.Count > 0) { return(mWizard.Context.BusinessFlow.TargetApplications[0].Name); } return(string.Empty); }
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); } }
public BusinessFlow ConvertQCTestSetToBF(QC.ALMTestSet testSet) { GingerActivitiesGroupsRepo = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <ActivitiesGroup>(); GingerActivitiesRepo = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <Activity>(); try { if (testSet == null) { return(null); } //Create Business Flow BusinessFlow busFlow = new BusinessFlow(); busFlow.Name = testSet.TestSetName; busFlow.ExternalID = testSet.TestSetID; busFlow.Status = BusinessFlow.eBusinessFlowStatus.Development; busFlow.Activities = new ObservableList <Activity>(); busFlow.Variables = new ObservableList <VariableBase>(); Dictionary <string, string> busVariables = new Dictionary <string, string>();//will store linked variables //Create Activities Group + Activities for each TC foreach (QC.ALMTSTest tc in testSet.Tests) { //check if the TC is already exist in repository ActivitiesGroup tcActivsGroup; ActivitiesGroup repoActivsGroup = null; if (repoActivsGroup == null) { repoActivsGroup = GingerActivitiesGroupsRepo.Where(x => x.ExternalID == tc.TestID).FirstOrDefault(); } if (repoActivsGroup != null) { List <Activity> repoNotExistsStepActivity = GingerActivitiesRepo.Where(z => repoActivsGroup.ActivitiesIdentifiers.Select(y => y.ActivityExternalID).ToList().Contains(z.ExternalID)) .Where(x => !tc.Steps.Select(y => y.StepID).ToList().Contains(x.ExternalID)).ToList(); tcActivsGroup = (ActivitiesGroup)repoActivsGroup.CreateInstance(); var ActivitySIdentifiersToRemove = tcActivsGroup.ActivitiesIdentifiers.Where(x => repoNotExistsStepActivity.Select(z => z.ExternalID).ToList().Contains(x.ActivityExternalID)); for (int indx = 0; indx < tcActivsGroup.ActivitiesIdentifiers.Count; indx++) { if ((indx < tcActivsGroup.ActivitiesIdentifiers.Count) && (ActivitySIdentifiersToRemove.Contains(tcActivsGroup.ActivitiesIdentifiers[indx]))) { tcActivsGroup.ActivitiesIdentifiers.Remove(tcActivsGroup.ActivitiesIdentifiers[indx]); indx--; } } tcActivsGroup.ExternalID2 = tc.TestID; busFlow.AddActivitiesGroup(tcActivsGroup); busFlow.ImportActivitiesGroupActivitiesFromRepository(tcActivsGroup, GingerActivitiesRepo, ApplicationPlatforms, true); busFlow.AttachActivitiesGroupsAndActivities(); } else //TC not exist in Ginger repository so create new one { tcActivsGroup = new ActivitiesGroup(); tcActivsGroup.Name = tc.TestName; tcActivsGroup.ExternalID = tc.TestID; tcActivsGroup.ExternalID2 = tc.LinkedTestID; tcActivsGroup.Description = tc.Description; busFlow.AddActivitiesGroup(tcActivsGroup); } //Add the TC steps as Activities if not already on the Activities group foreach (QC.ALMTSTestStep step in tc.Steps) { Activity stepActivity; bool toAddStepActivity = false; //check if mapped activity exist in repository Activity repoStepActivity = (Activity)GingerActivitiesRepo.Where(x => x.ExternalID == step.StepID).FirstOrDefault(); if (repoStepActivity != null) { //check if it is part of the Activities Group ActivityIdentifiers groupStepActivityIdent = (ActivityIdentifiers)tcActivsGroup.ActivitiesIdentifiers.Where(x => x.ActivityExternalID == step.StepID).FirstOrDefault(); if (groupStepActivityIdent != null) { //already in Activities Group so get link to it stepActivity = (Activity)busFlow.Activities.Where(x => x.Guid == groupStepActivityIdent.ActivityGuid).FirstOrDefault(); // in any case update description/expected/name - even if "step" was taken from repository stepActivity.Description = StripHTML(step.Description); stepActivity.Expected = StripHTML(step.Expected); stepActivity.ActivityName = tc.TestName + ">" + step.StepName; } 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 { stepActivity = new Activity(); stepActivity.ActivityName = tc.TestName + ">" + step.StepName; stepActivity.ExternalID = step.StepID; stepActivity.Description = StripHTML(step.Description); toAddStepActivity = true; } if (toAddStepActivity) { //not in group- need to add it busFlow.AddActivity(stepActivity, tcActivsGroup); } //pull TC-Step parameters and add them to the Activity level List <string> stepParamsList = new List <string>(); foreach (string param in stepParamsList) { //get the param value string paramSelectedValue = string.Empty; bool? isflowControlParam = null; QC.ALMTSTestParameter tcParameter = tc.Parameters.Where(x => x.Name.ToUpper() == param.ToUpper()).FirstOrDefault(); //get the param value if (tcParameter != null && tcParameter.Value != null && tcParameter.Value != string.Empty) { paramSelectedValue = tcParameter.Value; } else { isflowControlParam = null;//empty value paramSelectedValue = "<Empty>"; } //check if parameter is part of a link string linkedVariable = null; if (paramSelectedValue.StartsWith("#$#")) { string[] valueParts = paramSelectedValue.Split(new [] { "#$#" }, StringSplitOptions.None); if (valueParts.Count() == 3) { linkedVariable = valueParts[1]; paramSelectedValue = "$$_" + valueParts[2];//so it still will be considered as non-flow control if (!busVariables.Keys.Contains(linkedVariable)) { busVariables.Add(linkedVariable, valueParts[2]); } } } //determine if the param is Flow Control Param or not based on it value and agreed sign "$$_" if (paramSelectedValue.StartsWith("$$_")) { isflowControlParam = false; if (paramSelectedValue.StartsWith("$$_")) { paramSelectedValue = paramSelectedValue.Substring(3);//get value without "$$_" } } else if (paramSelectedValue != "<Empty>") { isflowControlParam = true; } //check if already exist param with that name VariableBase stepActivityVar = stepActivity.Variables.Where(x => x.Name.ToUpper() == param.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; stepActivity.AddVariable(stepActivityVar); stepActivity.AutomationStatus = eActivityAutomationStatus.Development;//reset status because new flow control param was added } else { //add as String param stepActivityVar = new VariableString(); stepActivityVar.Name = param; ((VariableString)stepActivityVar).InitialStringValue = paramSelectedValue; 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; stepActivity.AddVariable(stepActivityVar); stepActivity.AutomationStatus = 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; ((VariableString)stepActivityVar).InitialStringValue = paramSelectedValue; stepActivity.AddVariable(stepActivityVar); stepActivity.AutomationStatus = 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 == paramSelectedValue).FirstOrDefault(); if (stepActivityVarOptionalVar == null) { //no such variable value option so add it stepActivityVarOptionalVar = new OptionalValue(paramSelectedValue); ((VariableSelectionList)stepActivityVar).OptionalValuesList.Add(stepActivityVarOptionalVar); if (isflowControlParam == true) { stepActivity.AutomationStatus = 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 = paramSelectedValue; if (stepActivityVar is VariableString) { ((VariableString)stepActivityVar).InitialStringValue = paramSelectedValue; } } catch (Exception ex) { Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); } } //add linked variable if needed if (!string.IsNullOrEmpty(linkedVariable)) { stepActivityVar.LinkedVariableName = linkedVariable; } else { stepActivityVar.LinkedVariableName = string.Empty;//clear old links } } } //order the Activities Group activities according to the order of the matching steps in the TC try { int startGroupActsIndxInBf = 0; if (busFlow.Activities.Count > 0) { startGroupActsIndxInBf = busFlow.Activities.IndexOf(tcActivsGroup.ActivitiesIdentifiers[0].IdentifiedActivity); } foreach (QC.ALMTSTestStep step in tc.Steps) { int stepIndx = tc.Steps.IndexOf(step) + 1; ActivityIdentifiers actIdent = (ActivityIdentifiers)tcActivsGroup.ActivitiesIdentifiers.Where(x => x.ActivityExternalID == step.StepID).FirstOrDefault(); if (actIdent == null || actIdent.IdentifiedActivity == null) { break;//something wrong- shouldn't be null } Activity act = (Activity)actIdent.IdentifiedActivity; int groupActIndx = tcActivsGroup.ActivitiesIdentifiers.IndexOf(actIdent); int bfActIndx = busFlow.Activities.IndexOf(act); //set it in the correct place in the group int numOfSeenSteps = 0; int groupIndx = -1; foreach (ActivityIdentifiers ident in tcActivsGroup.ActivitiesIdentifiers) { groupIndx++; if (string.IsNullOrEmpty(ident.ActivityExternalID) || tc.Steps.Where(x => x.StepID == ident.ActivityExternalID).FirstOrDefault() == null) { continue;//activity which not originally came from the TC } numOfSeenSteps++; if (numOfSeenSteps >= stepIndx) { break; } } ActivityIdentifiers identOnPlace = (ActivityIdentifiers)tcActivsGroup.ActivitiesIdentifiers[groupIndx]; if (identOnPlace.ActivityGuid != act.Guid) { //replace places in group tcActivsGroup.ActivitiesIdentifiers.Move(groupActIndx, groupIndx); //replace places in business flow busFlow.Activities.Move(bfActIndx, startGroupActsIndxInBf + groupIndx); } } } catch (Exception ex) { Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); //failed to re order the activities to match the tc steps order, not worth breaking the import because of this } } //Add the BF variables (linked variables) if (busVariables.Keys.Count > 0) { foreach (KeyValuePair <string, string> var in busVariables) { //add as String param VariableString busVar = new VariableString(); busVar.Name = var.Key; busVar.InitialStringValue = var.Value; busFlow.AddVariable(busVar); } } return(busFlow); } catch (Exception ex) { Reporter.ToLog(eLogLevel.ERROR, "Failed to import QC test set and convert it into " + GingerDicser.GetTermResValue(eTermResKey.BusinessFlow), ex); return(null); } }
public void CreateActivities() { // We put all template optimized activity in Activities Group ActivitiesGroup AG = (ActivitiesGroup)(from x in mBizFlow.ActivitiesGroups where x.Name == "Optimized Activities" select x).FirstOrDefault(); if (AG == null) { AG = new ActivitiesGroup(); AG.Name = "Optimized Activities"; mBizFlow.ActivitiesGroups.Add(AG); } ActivitiesGroup AG1 = (ActivitiesGroup)(from x in mBizFlow.ActivitiesGroups where x.Name == "Optimized Activities - Not in Use" select x).FirstOrDefault(); if (AG1 == null) { AG1 = new ActivitiesGroup(); AG1.Name = "Optimized Activities - Not in Use"; mBizFlow.ActivitiesGroups.Add(AG1); } for (int i = 0; i < AG.ActivitiesIdentifiers.Count; i++) { ActivityIdentifiers ia = AG.ActivitiesIdentifiers[i]; Activity a1 = (Activity)(from x in mBizFlow.Activities where x.Guid == ia.ActivityGuid select x).FirstOrDefault(); if (!AG1.CheckActivityInGroup(a1)) { AG1.AddActivityToGroup(a1); } } // Search each activity if not found create new foreach (GherkinStep GH in mOptimizedSteps) { Activity a1 = (Activity)(from x in mBizFlow.Activities where x.ActivityName == GH.Text select x).FirstOrDefault(); if (a1 == null) { if (GH.AutomationStatus == "Automated in Shared Repo - ") { ObservableList <Activity> activities = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <Activity>(); Activity a2 = (Activity) (from x in activities where x.ActivityName == GH.Text select x).FirstOrDefault(); //FIXME if (a2 != null) { a2.Active = false; mBizFlow.AddActivity(a2, AG); } } else { Activity a = new Activity(); a.ActivityName = GH.Text; a.Active = false; a.TargetApplication = WorkSpace.Instance.Solution.MainApplication; a.ActionRunOption = eActionRunOption.ContinueActionsRunOnFailure; CreateActivityVariables(a); CreateActivitySelectionVariables(a); mBizFlow.AddActivity(a, AG); } } //TODO: handle if exist we need to update !? else { AG1.RemoveActivityFromGroup(a1); } } foreach (ActivityIdentifiers ia in AG1.ActivitiesIdentifiers) { Activity a1 = (Activity) (from x in mBizFlow.Activities where x.Guid == ia.ActivityGuid select x).FirstOrDefault(); if (AG.CheckActivityInGroup(a1)) { AG.RemoveActivityFromGroup(a1); } } WorkSpace.Instance.SolutionRepository.SaveRepositoryItem(mBizFlow); }