コード例 #1
0
        //[Timeout(60000)]
        public void ActivityVariablesDependancyTest()
        {
            //Arrange
            ObservableList <Activity> activityList = BF1.Activities;

            BF1.EnableActivitiesVariablesDependenciesControl = true;

            //Added selection list variable in BF
            VariableSelectionList selectionList = new VariableSelectionList();

            selectionList.OptionalValuesList.Add(new OptionalValue("a"));
            selectionList.OptionalValuesList.Add(new OptionalValue("b"));
            selectionList.SelectedValue = selectionList.OptionalValuesList[0].Value;
            selectionList.ItemName      = "MyVar";
            BF1.Variables.Add(selectionList);

            //Added dependancies in activities

            string[] variableValues = { "a", "b" };

            VariableDependency actiVD0 = new VariableDependency(selectionList.Guid, selectionList.ItemName, variableValues);

            activityList[0].VariablesDependencies.Add(actiVD0);

            VariableDependency actiVD1 = new VariableDependency(selectionList.Guid, selectionList.ItemName, variableValues);

            activityList[1].VariablesDependencies.Add(actiVD1);

            VariableDependency actiVD2 = new VariableDependency(selectionList.Guid, selectionList.ItemName, variableValues[1]);

            activityList[2].VariablesDependencies.Add(actiVD2);

            //Act
            mGR.RunBusinessFlow(BF1);

            //Assert
            Assert.AreEqual(BF1.Activities[0].Status, Amdocs.Ginger.CoreNET.Execution.eRunStatus.Passed);
            Assert.AreEqual(BF1.Activities[1].Status, Amdocs.Ginger.CoreNET.Execution.eRunStatus.Passed);
            Assert.AreEqual(BF1.Activities[2].Status, Amdocs.Ginger.CoreNET.Execution.eRunStatus.Skipped);

            //Changed the selected value of selection list
            ((VariableSelectionList)BF1.Variables[0]).SelectedValue = selectionList.OptionalValuesList[1].Value;

            //Act
            mGR.RunBusinessFlow(BF1);

            //Assert
            Assert.AreEqual(BF1.Activities[0].Status, Amdocs.Ginger.CoreNET.Execution.eRunStatus.Passed);
            Assert.AreEqual(BF1.Activities[1].Status, Amdocs.Ginger.CoreNET.Execution.eRunStatus.Passed);
            Assert.AreEqual(BF1.Activities[2].Status, Amdocs.Ginger.CoreNET.Execution.eRunStatus.Passed);
        }
コード例 #2
0
        private void AddExistingSelectionListVariabelesValues(Activity repositoryItem, Activity usageItem)
        {
            try
            {
                List <VariableBase> usageVars =
                    usageItem.Variables.Where(a => a is VariableSelectionList).ToList <VariableBase>();
                if (usageVars != null && usageVars.Count > 0)
                {
                    foreach (VariableBase usageVar in usageVars)
                    {
                        VariableSelectionList usageVarList = (VariableSelectionList)usageVar;
                        //get the matching var in the repo item
                        VariableBase repoVar = repositoryItem.Variables.Where(x => x.Name.ToUpper() == usageVarList.Name.ToUpper()).FirstOrDefault();
                        if (repoVar != null)
                        {
                            VariableSelectionList repoVarList = (VariableSelectionList)repoVar;

                            //go over all optional values and add the missing ones
                            foreach (OptionalValue usageValue in usageVarList.OptionalValuesList)
                            {
                                OptionalValue val = repoVarList.OptionalValuesList.Where(x => x.Value == usageValue.Value).FirstOrDefault();
                                if (val == null)
                                {
                                    //add the val
                                    repoVarList.OptionalValuesList.Add(usageValue);
                                    repoVarList.SyncOptionalValuesListAndString();
                                    repositoryItem.AutomationStatus = Activity.eActivityAutomationStatus.Development;//reset the status because new variable optional value was added
                                }
                            }

                            //keep original variable value selection
                            if (repoVarList.OptionalValuesList.Where(pv => pv.Value == usageVar.Value).FirstOrDefault() != null)
                            {
                                repoVarList.Value = usageVar.Value;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}");
            }
        }
コード例 #3
0
        public VariableSelectionListPage(VariableSelectionList var)
        {
            InitializeComponent();

            mVar = var;
            mVar.PropertyChanged += mVar_PropertyChanged;

            SetOptionalValuesGridData();
            SetOptionalValuesGridView();
            //events
            grdOptionalValues.btnAdd.AddHandler(Button.ClickEvent, new RoutedEventHandler(AddOptionalValue));
            grdOptionalValues.btnDelete.AddHandler(Button.ClickEvent, new RoutedEventHandler(btnDelete_Click));
            grdOptionalValues.btnClearAll.AddHandler(Button.ClickEvent, new RoutedEventHandler(btnClearAll_Click));
            grdOptionalValues.grdMain.RowEditEnding += grdOptionalValues_RowEditEnding;
            grdOptionalValues.Grid.IsVisibleChanged += grdOptionalValues_IsVisibleChanged;

            comboSelectedValue.ItemsSource       = mVar.OptionalValuesList.ToList <OptionalValue>();
            comboSelectedValue.DisplayMemberPath = "Value";
            App.ObjFieldBinding(comboSelectedValue, ComboBox.TextProperty, mVar, VariableSelectionList.Fields.SelectedValue);
        }
コード例 #4
0
        public void BackUpRestoreVariableSelectionList()
        {
            //Arrange

            VariableSelectionList sl = new VariableSelectionList();

            sl.Name = "Var 2";
            sl.OptionalValuesList = new ObservableList <OptionalValue>();
            sl.OptionalValuesList.Add(new OptionalValue("11"));

            //Act
            sl.SaveBackup();

            // Modify the SL
            sl.OptionalValuesList[0].Value = "00";

            sl.RestoreFromBackup();

            //Assert
            Assert.AreEqual("11", sl.OptionalValuesList[0].Value, "OptionalValuesList[0].Value");
        }
コード例 #5
0
        private void CreateActivitySelectionVariables(Activity a)
        {
            // Parmas in activity name will be %p1, %p2 etc...
            string activityName = a.ActivityName;

            while (true)
            {
                //We can use c to define multiple selection lists if needed.
                string ColName = General.GetStringBetween(activityName, "<", ">");
                if (!string.IsNullOrEmpty(ColName))
                {
                    VariableSelectionList v = new VariableSelectionList();
                    v.Name = ColName;
                    a.Variables.Add(v);
                    activityName = activityName.Substring(activityName.IndexOf(">") + 1);
                }
                else
                {
                    break;
                }
            }
        }
コード例 #6
0
        public void TestVariable_SelectionListSetValue()
        {
            //Arrange
            string variableName = "V1";

            ResetBusinessFlow();

            Activity activity1 = new Activity()
            {
                Active = true
            };

            mBF.Activities.Add(activity1);

            VariableSelectionList v1 = new VariableSelectionList()
            {
                Name = variableName
            };

            v1.OptionalValuesList.Add(new OptionalValue("Jupiter"));
            v1.OptionalValuesList.Add(new OptionalValue("Saturn"));
            activity1.AddVariable(v1);

            ActSetVariableValue actSetVariableValue = new ActSetVariableValue()
            {
                VariableName = variableName, SetVariableValueOption = VariableBase.eSetValueOptions.SetValue, Active = true, Value = "Jupiter"
            };

            activity1.Acts.Add(actSetVariableValue);

            //Act
            mGR.RunRunner();

            //Assert
            Assert.IsTrue(string.IsNullOrEmpty(actSetVariableValue.Error));
            Assert.AreEqual(eRunStatus.Passed, mBF.RunStatus);
            Assert.AreEqual(eRunStatus.Passed, activity1.Status);
            Assert.AreEqual("Jupiter", v1.Value);
        }
コード例 #7
0
        public void ActionVariablesDependancyTest()
        {
            //Arrange
            ObservableList <Activity> activityList = BF1.Activities;

            Activity activity = activityList[1];
            ObservableList <IAct> actionList = activity.Acts;

            activity.EnableActionsVariablesDependenciesControl = true;

            mGR.CurrentBusinessFlow.CurrentActivity = BF1.Activities[1];
            //Added selection list variable in activity
            VariableSelectionList selectionList = new VariableSelectionList();

            selectionList.OptionalValuesList.Add(new OptionalValue("abc"));
            selectionList.OptionalValuesList.Add(new OptionalValue("xyz"));
            selectionList.SelectedValue = selectionList.OptionalValuesList[1].Value;
            selectionList.ItemName      = "MyActVar";
            activity.Variables.Add(selectionList);

            //added action level dependancies

            string[] variableValues = { "abc", "xyz" };

            VariableDependency actiVD0 = new VariableDependency(selectionList.Guid, selectionList.ItemName, variableValues[0]);

            actionList[0].VariablesDependencies.Add(actiVD0);

            VariableDependency actiVD1 = new VariableDependency(selectionList.Guid, selectionList.ItemName, variableValues);

            actionList[1].VariablesDependencies.Add(actiVD1);

            VariableDependency actiVD3 = new VariableDependency(selectionList.Guid, selectionList.ItemName, variableValues);

            actionList[2].VariablesDependencies.Add(actiVD3);

            VariableDependency actiVD4 = new VariableDependency(selectionList.Guid, selectionList.ItemName, variableValues[0]);

            actionList[3].VariablesDependencies.Add(actiVD4);

            //Act
            mGR.RunActivity(activity);

            //Assert
            Assert.AreEqual(BF1.Activities[1].Acts[0].Status, Amdocs.Ginger.CoreNET.Execution.eRunStatus.Skipped);
            Assert.AreEqual(BF1.Activities[1].Acts[1].Status, Amdocs.Ginger.CoreNET.Execution.eRunStatus.Passed);
            Assert.AreEqual(BF1.Activities[1].Acts[2].Status, Amdocs.Ginger.CoreNET.Execution.eRunStatus.Passed);
            Assert.AreEqual(BF1.Activities[1].Acts[3].Status, Amdocs.Ginger.CoreNET.Execution.eRunStatus.Skipped);

            //Changed the selected value of selection list
            ((VariableSelectionList)activity.Variables[0]).SelectedValue = selectionList.OptionalValuesList[0].Value;

            //Act
            mGR.RunActivity(activity);

            //Assert
            Assert.AreEqual(BF1.Activities[1].Acts[0].Status, Amdocs.Ginger.CoreNET.Execution.eRunStatus.Passed);
            Assert.AreEqual(BF1.Activities[1].Acts[1].Status, Amdocs.Ginger.CoreNET.Execution.eRunStatus.Passed);
            Assert.AreEqual(BF1.Activities[1].Acts[2].Status, Amdocs.Ginger.CoreNET.Execution.eRunStatus.Passed);
            Assert.AreEqual(BF1.Activities[1].Acts[3].Status, Amdocs.Ginger.CoreNET.Execution.eRunStatus.Passed);
        }
コード例 #8
0
        public static void ClassInit(TestContext context)
        {
            Solution = new Solution();
            BF       = new BusinessFlow();

            VariableString VarString = new VariableString();

            VarString.Name            = "BF_VarString";
            VarString.SetAsInputValue = true;
            VarString.MandatoryInput  = true;
            BF.Variables.Add(VarString);

            VariableSelectionList VarList = new VariableSelectionList();

            VarList.Name            = "BF_VarList";
            VarList.SetAsInputValue = true;
            VarList.MandatoryInput  = true;
            VarList.OptionalValuesList.Add(new OptionalValue(value: " "));
            VarList.OptionalValuesList.Add(new OptionalValue(value: "aa"));
            VarList.OptionalValuesList.Add(new OptionalValue(value: "bb"));
            VarList.Value = " ";
            BF.Variables.Add(VarList);

            Activity Acty = new Activity();

            Acty.ActivityName = "Act1";

            BF.AddActivity(Acty);
            VariableString VarString2 = new VariableString();

            VarString2.Name = "NewVarString";
            Acty.AddVariable(VarString2);

            VariableString VarString3 = new VariableString();

            VarString3.Name            = "NewVarString3";
            VarString3.SetAsInputValue = true;
            VarString3.MandatoryInput  = true;
            VarString3.Value           = "test123";
            Acty.AddVariable(VarString3);

            VariableString VarString4 = new VariableString();

            VarString4.Name = "NewVarString";
            Acty.AddVariable(VarString4);

            VariableString VarString5 = new VariableString();

            VarString5.Name = "NewVarString";
            Acty.AddVariable(VarString5);

            VariableString VarString6 = new VariableString();

            VarString6.Name            = "NewVarString6";
            VarString6.SetAsInputValue = true;
            VarString6.MandatoryInput  = true;
            Acty.AddVariable(VarString6);

            ActDummy DummyAction = new ActDummy();

            Acty.Acts.Add(DummyAction);

            //ActReturnValue with static value
            ActReturnValue ARV1 = new ActReturnValue
            {
                Param    = "Value1",
                Expected = "Test1"
            };

            DummyAction.ReturnValues.Add(ARV1);



            //ActReturnValue with static value and variable

            ActReturnValue ARV2 = new ActReturnValue
            {
                Param    = "Value2",
                Expected = "Test1{Var Name=NewVarString}"
            };

            DummyAction.ReturnValues.Add(ARV2);

            //ActReturnValue with two variables
            ActReturnValue ARV3 = new ActReturnValue
            {
                Param    = "Value3",
                Expected = "{Var Name=NewVarString3}{Var Name=NewVarString}"
            };

            DummyAction.ReturnValues.Add(ARV3);
            //ActReturnValue with  variables follwed by static value
            ActReturnValue ARV4 = new ActReturnValue
            {
                Param    = "Value4",
                Expected = "{Var Name=NewVarString3}test"
            };

            DummyAction.ReturnValues.Add(ARV4);

            ActReturnValue ARV5 = new ActReturnValue
            {
                Param    = "Value5",
                Expected = "{Var Name=NewVarString3}"
            };

            DummyAction.ReturnValues.Add(ARV5);

            ABF = (AnalyzeBusinessFlow)AnalyzeBusinessFlow.Analyze(Solution, BF).Where(x => x.Description.Equals(AnalyzeBusinessFlow.LegacyOutPutValidationDescription)).First();
        }
コード例 #9
0
        public void BackUpRestore()
        {
            //Arrange
            int    ActivitiesToCreate = 5;
            string BizFlowName        = "Biz flow Back/Rest";
            string BizFlowDescription = "Desc Back/Rest tester";

            BusinessFlow BF = new BusinessFlow()
            {
                Name = BizFlowName
            };

            BF.Status     = BusinessFlow.eBusinessFlowStatus.Development;
            BF.Activities = new ObservableList <Activity>();
            ObservableList <Activity> OriginalActivitiesObj = BF.Activities;

            for (int i = 1; i <= ActivitiesToCreate; i++)
            {
                Activity a = new Activity()
                {
                    ActivityName = "Activity " + i, Description = "desc" + i, Status = eRunStatus.Passed
                };
                BF.AddActivity(a);
            }

            // Create Activity to check ref
            Activity a6 = new Activity()
            {
                ActivityName = "a6"
            };

            BF.Activities.Add(a6);

            // Add one action to make sure backup drill down, and restore the ref item not a copy
            ActGotoURL act1 = new ActGotoURL();

            act1.Description = "Goto URL 1";
            a6.Acts.Add(act1);

            //add action with input/output vals
            act1.InputValues = new ObservableList <ActInputValue>();
            string        firstInputValName = "Param1";
            ActInputValue firstInputVal     = new ActInputValue()
            {
                Param = firstInputValName
            };

            act1.InputValues.Add(firstInputVal);
            act1.InputValues.Add(new ActInputValue()
            {
                Param = "Param2"
            });

            //add flow control
            act1.FlowControls = new ObservableList <FlowControl>();
            act1.FlowControls.Add(new GingerCore.FlowControlLib.FlowControl()
            {
                Condition = "A=B", FlowControlAction = eFlowControlAction.GoToActivity
            });
            eFlowControlAction secondFlowControlAction = eFlowControlAction.RerunAction;

            GingerCore.FlowControlLib.FlowControl secondFlowControl = new GingerCore.FlowControlLib.FlowControl()
            {
                Condition = "C>123", FlowControlAction = secondFlowControlAction
            };
            act1.FlowControls.Add(secondFlowControl);
            act1.FlowControls.Add(new GingerCore.FlowControlLib.FlowControl()
            {
                Condition = "D=111", FlowControlAction = eFlowControlAction.StopRun
            });

            //BF Variables
            VariableString v = new VariableString();

            v.Name        = "Var1";
            v.Description = "VDesc 1";
            BF.AddVariable(v);
            VariableSelectionList sl = new VariableSelectionList();

            sl.Name = "Var 2";
            sl.OptionalValuesList = new ObservableList <OptionalValue>();
            sl.OptionalValuesList.Add(new OptionalValue("11"));
            sl.OptionalValuesList.Add(new OptionalValue("22"));
            sl.OptionalValuesList.Add(new OptionalValue("33"));
            BF.AddVariable(sl);

            // BF.SaveBackup();

            BF.SaveBackup();

            //Erase/Modify some stuff
            BF.Name        = "zzzz";
            BF.Description = BizFlowDescription;
            BF.Status      = BusinessFlow.eBusinessFlowStatus.Retired;
            BF.Activities[1].Description = "AAAA";
            BF.Activities.Remove(BF.Activities[2]);
            BF.Activities.Remove(BF.Activities[3]);
            act1.Description = "ZZZZZ";

            act1.InputValues[0].Param = "qqq";
            act1.InputValues.Remove(act1.InputValues[1]);

            act1.FlowControls[1].FlowControlAction = eFlowControlAction.MessageBox;
            act1.FlowControls.Add(new GingerCore.FlowControlLib.FlowControl()
            {
                Condition = "Val=123"
            });
            act1.FlowControls.Add(new GingerCore.FlowControlLib.FlowControl()
            {
                Condition = "Val=555"
            });

            sl.OptionalValuesList[0].Value = "aaaa";
            sl.OptionalValuesList.Add(new OptionalValue("44"));
            sl.OptionalValuesList.Add(new OptionalValue("55"));

            // BF.RestoreFromBackup();
            BF.RestoreFromBackup();

            // Assert
            Assert.AreEqual(BF.Name, BizFlowName, "BF.Name");
            Assert.AreEqual(BF.Description, null, "BF.Description");

            // check enum restore
            Assert.AreEqual(BF.Status, BusinessFlow.eBusinessFlowStatus.Development, "BF.Status");
            Assert.AreEqual(BF.Activities.Count(), ActivitiesToCreate + 1, "BF.Activities.Count()");

            //check original list ref obj
            Assert.AreEqual(BF.Activities, OriginalActivitiesObj, "BF.Activities REF");
            Assert.AreEqual(BF.Activities[0].Description, "desc1", "BF.Activities[0].Description");
            Assert.AreEqual(BF.Activities[5].ActivityName, "a6", "BF.Activities[5].ActivityName");

            // Check original action ref is back
            Assert.AreEqual(BF.Activities[5], a6, "BF.Activities[5] REF");
            Assert.AreEqual(act1.Description, "Goto URL 1", "act1.Description");
            Assert.AreEqual(a6.Acts[0], act1, "a6.Acts[0]");

            //check Action input values
            Assert.AreEqual(act1.InputValues.Count, 2, "act1.InputValues.Count");
            Assert.AreEqual(act1.InputValues[0], firstInputVal, "act1.InputValues[0] REF");
            Assert.AreEqual(act1.InputValues[0].Param, firstInputValName, "act1.InputValues[0].Param");

            //check Action flow control
            Assert.AreEqual(act1.FlowControls.Count, 3, "act1.FlowControls.Count");
            Assert.AreEqual(act1.FlowControls[1], secondFlowControl, "act1.FlowControls[1] REF");
            Assert.AreEqual(act1.FlowControls[1].FlowControlAction, secondFlowControlAction, "act1.FlowControls[1].FlowControlAction");

            //BF variables
            Assert.AreEqual(BF.Variables.Count, 2, "BF.Variables.Count");
            Assert.AreEqual(BF.Variables[1], sl, "BF.Variables[0] REF");
            Assert.AreEqual(((VariableSelectionList)BF.Variables[1]).OptionalValuesList[0].Value, "11", "BF.Variables[0].Value");
        }
コード例 #10
0
        public void ActivityVariableDependancyTest_WithCreateInstance()
        {
            //Arrange
            BusinessFlow bf = new BusinessFlow("Test");

            Activity activity = new Activity();
            VariableSelectionList selectionList2 = new VariableSelectionList();

            selectionList2.Name = "activityVariable1";
            selectionList2.OptionalValuesList.Add(new OptionalValue("c"));
            selectionList2.OptionalValuesList.Add(new OptionalValue("d"));

            VariableDependency vd = new VariableDependency(selectionList2.Guid, selectionList2.ItemName, selectionList2.Value);

            ActGotoURL actGotoURL = new ActGotoURL();

            actGotoURL.Description = "www.google.com";
            actGotoURL.VariablesDependencies.Add(vd);
            ActDummy actDummy = new ActDummy();

            actDummy.Description = "www.google.com";
            actDummy.VariablesDependencies.Add(vd);
            activity.Variables.Add(selectionList2);
            activity.Acts.Add(actGotoURL);
            activity.Acts.Add(actDummy);
            Activity activity2 = new Activity();
            ActDummy act2      = new ActDummy();

            act2.Description = "www.google.com";
            activity2.Acts.Add(act2);
            VariableSelectionList selectionList = new VariableSelectionList();

            selectionList.Name = "bfVariable1";
            selectionList.OptionalValuesList.Add(new OptionalValue("a"));
            selectionList.OptionalValuesList.Add(new OptionalValue("b"));

            bf.Variables.Add(selectionList);


            VariableDependency vd1 = new VariableDependency(selectionList.Guid, selectionList.ItemName, selectionList.Value);

            activity.VariablesDependencies.Add(vd1);
            activity2.VariablesDependencies.Add(vd1);

            bf.Activities.RemoveAt(0);
            bf.Activities.Add(activity);
            bf.Activities.Add(activity2);


            //Act
            BusinessFlow bfCopy = (BusinessFlow)bf.CreateInstance();

            Guid newBFVarGuid       = bfCopy.Variables.Where(x => x.Name == "bfVariable1").FirstOrDefault().Guid;
            Guid newActivityVarGuid = bfCopy.Activities[0].Variables[0].Guid;

            //Assert
            Assert.AreEqual(newBFVarGuid, bfCopy.Activities[0].VariablesDependencies[0].VariableGuid);
            Assert.AreEqual(newBFVarGuid, bfCopy.Activities[1].VariablesDependencies[0].VariableGuid);
            Assert.AreEqual(newActivityVarGuid, bfCopy.Activities[0].Acts[0].VariablesDependencies[0].VariableGuid);
            Assert.AreEqual(newActivityVarGuid, bfCopy.Activities[0].Acts[1].VariablesDependencies[0].VariableGuid);
        }
コード例 #11
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);
            }
        }
コード例 #12
0
        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);
            }
        }