示例#1
0
    void WindowContextMenu(Event current, ScenarioStep step)
    {
        secondClicked = null;
        GenericMenu menu = new GenericMenu();

        secondClicked = step;
        if (state == EditingState.standart)
        {
            lastClicked = step;
        }
        else
        {
            secondClicked = step;
        }
        switch (state)
        {
        case EditingState.standart:
            menu.AddItem(new GUIContent("Add conncection"), false, MakeConnection);
            menu.AddItem(new GUIContent("Remove conncection"), false, RemoveConnection);
            menu.AddItem(new GUIContent("Remove step"), false, RemoveStep);
            break;

        case EditingState.makeConnection:
            menu.AddItem(new GUIContent("attach"), false, AttachConnection);
            break;

        case EditingState.removeConnection:
            menu.AddItem(new GUIContent("deattach"), false, DeattachConnection);
            break;
        }
        menu.ShowAsContext();
        current.Use();
    }
示例#2
0
    public override void Action(Transform interactionArea, ScenarioStep scenarioStep)
    {
        if (!scenarioStep.IsPreviousStepsDone())
        {
            return;
        }
        if (scenarioStep.gameObjects[0] == null || (interactionArea == scenarioStep.gameObjects[0].transform) || (scenarioStep.gameObjects[0] == GlowEffectRayCaster.Instance.GetCatchedObject()))
        {
            if (scenarioStep.strings[1] != null)
            {
                MessageShow.Instance.ShowMessage(scenarioStep.strings[1]);
            }

            if (scenarioStep.strings[0] != "" && !Input.GetKeyDown(scenarioStep.strings[0]))
            {
                return;
            }

            MessageShow.Instance.ShowMessage("");
            scenarioStep.IsDone = true;
        }
        else
        {
            MessageShow.Instance.ShowMessage("");
        }
    }
示例#3
0
    ScenarioAction GetScriptableObjectByName(ScenarioStep step)
    {
        ScenarioAction temp = null;

        foreach (var obj in actions)
        {
            if (obj.name == step.scriptableObjectName)
            {
                temp = Instantiate(obj) as ScenarioAction;
            }
        }
        foreach (var obj in helpactions)
        {
            if (obj.name == step.scriptableObjectName)
            {
                temp = Instantiate(obj) as ScenarioAction;
            }
        }
        foreach (var obj in states)
        {
            if (obj.name == step.scriptableObjectName)
            {
                temp = Instantiate(obj) as ScenarioAction;
            }
        }
        foreach (var obj in conditions)
        {
            if (obj.name == step.scriptableObjectName)
            {
                temp = Instantiate(obj) as ScenarioAction;
            }
        }

        return(temp);
    }
        private ScenarioStep CloneTo(ScenarioStep step, string currentBlock)
        {
            ScenarioStep newStep = null;

            if (currentBlock == "When")
            {
                newStep = new When();
            }
            else if (currentBlock == "Then")
            {
                newStep = new Then();
            }
            else // Given or empty
            {
                newStep = new Given();
            }

            Debug.Assert(newStep != null);

            newStep.Text = step.Text;
            newStep.MultiLineTextArgument = step.MultiLineTextArgument;
            newStep.TableArg      = Clone(step.TableArg);
            newStep.ScenarioBlock = step.ScenarioBlock;
            newStep.StepKeyword   = step.StepKeyword;

            return(newStep);
        }
        private ScenarioStep Clone(ScenarioStep step)
        {
            ScenarioStep newStep = null;

            if (step is Given)
            {
                newStep = new Given();
            }
            else if (step is When)
            {
                newStep = new When();
            }
            else if (step is Then)
            {
                newStep = new Then();
            }
            else if (step is And)
            {
                newStep = new And();
            }
            else if (step is But)
            {
                newStep = new But();
            }

            Debug.Assert(newStep != null);

            newStep.Text = step.Text;
            newStep.MultiLineTextArgument = step.MultiLineTextArgument;
            newStep.TableArg      = Clone(step.TableArg);
            newStep.ScenarioBlock = step.ScenarioBlock;
            newStep.StepKeyword   = step.StepKeyword;

            return(newStep);
        }
示例#6
0
    public override void Action(Transform interactionArea, ScenarioStep scenarioStep)
    {
        if (!scenarioStep.IsPreviousStepsDone())
        {
            return;
        }

        if (scenarioStep.strings[0] != "" && !Input.GetKeyDown(scenarioStep.strings[0]))
        {
            return;
        }

        if (GameObject.Find("ScenarioManager").GetComponent <Scenario>().endcount == 0)
        {
            GameObject.Find("ScenarioManager").GetComponent <Scenario>().Score -= step.floats[0];
        }

        scenarioStep.IsDone = true;
        GameObject.Find("ScenarioManager").GetComponent <Scenario>().endcount = 0;
        if (!GameObject.FindGameObjectWithTag("TextExit"))
        {
            GameObject.FindGameObjectWithTag("TextExit").SetActive(true);
        }
        Destroy(GameObject.FindGameObjectWithTag("Scenario"), 2f);
    }
        public StepBuilder(string keyword, StepKeyword stepKeyword, string text, FilePosition position, ScenarioBlock scenarioBlock)
        {
            switch (stepKeyword)
            {
            case StepKeyword.Given:
                step = new Given();
                break;

            case StepKeyword.When:
                step = new When();
                break;

            case StepKeyword.Then:
                step = new Then();
                break;

            case StepKeyword.And:
                step = new And();
                break;

            case StepKeyword.But:
                step = new But();
                break;

            default:
                throw new NotSupportedException();
            }

            step.Keyword       = keyword;
            step.Text          = text;
            step.FilePosition  = position;
            step.ScenarioBlock = scenarioBlock;
            step.StepKeyword   = stepKeyword;
        }
示例#8
0
        private void GenerateStep(CodeMemberMethod testMethod, ScenarioStep scenarioStep, ParameterSubstitution paramToIdentifier)
        {
            var testRunnerField = GetTestRunnerExpression();

            //testRunner.Given("something");
            List <CodeExpression> arguments = new List <CodeExpression>();

            arguments.Add(
                GetSubstitutedString(scenarioStep.Text, paramToIdentifier));
            if (scenarioStep.MultiLineTextArgument != null || scenarioStep.TableArg != null)
            {
                AddLineDirectiveHidden(testMethod.Statements);
                arguments.Add(
                    GetMultilineTextArgExpression(scenarioStep.MultiLineTextArgument, paramToIdentifier));
                arguments.Add(
                    GetTableArgExpression(scenarioStep.TableArg, testMethod.Statements, paramToIdentifier));
            }

            AddLineDirective(testMethod.Statements, scenarioStep);
            testMethod.Statements.Add(
                new CodeMethodInvokeExpression(
                    testRunnerField,
                    scenarioStep.GetType().Name,
                    arguments.ToArray()));
        }
示例#9
0
 public StepInstance(ScenarioStep step, Feature feature, StepContext stepContext, INativeSuggestionItemFactory <TNativeSuggestionItem> nativeSuggestionItemFactory, int level = 1)
     : base((StepDefinitionType)step.ScenarioBlock, (StepDefinitionKeyword)step.StepKeyword, step.Keyword, step.Text, stepContext)
 {
     this.NativeSuggestionItem = nativeSuggestionItemFactory.Create(step.Text, GetInsertionText(step), level, StepDefinitionType.ToString().Substring(0, 1), this);
     this.FilePosition         = step.FilePosition;
     this.SourceFile           = feature.SourceFile;
 }
示例#10
0
        public StepBuilder(string keyword, StepKeyword stepKeyword, string text, FilePosition position)
        {
            switch (stepKeyword)
            {
                case StepKeyword.Given:
                    step = new Given();
                    break;
                case StepKeyword.When:
                    step = new When();
                    break;
                case StepKeyword.Then:
                    step = new Then();
                    break;
                case StepKeyword.And:
                    step = new And();
                    break;
                case StepKeyword.But:
                    step = new But();
                    break;
                default:
                    throw new NotSupportedException();
            }

            step.Keyword = keyword;
            step.Text = text;
            step.FilePosition = position;
        }
 void Update()
 {
     for (int k = 0; k < activeSteps.Count; k++)
     {
         ScenarioStep temp = activeSteps[k];
         if (temp.IsPreviousStepsDone())
         {
             if (temp.stepType == null)
             {
                 temp.stepType = scriptableObjects[temp.scriptableObjectName];
             }
             temp.stepType.Action(interactingObject, temp);
             if (temp.IsDone)
             {
                 activeSteps.Remove(temp);
                 foreach (var next in temp.nextSteps)
                 {
                     if (!activeSteps.Contains(allSteps[next]))
                     {
                         allSteps[next].IsDone = false;
                         activeSteps.Add(allSteps[next]);
                     }
                 }
                 break;
             }
         }
     }
 }
示例#12
0
    public override void Action(Transform interactionArea, ScenarioStep scenarioStep)
    {
        bool   tagflag = false;
        string tag;

        tag = scenarioStep.gameObjects[0].tag;
        //scenarioStep.ints[2]++;
        //Debug.Log(scenarioStep.ints[2]);
        if (GameObject.FindGameObjectWithTag(tag))
        {
            tagflag = true;
        }
        if (tagflag)
        {
            GameObject.Find("ScenarioManager").GetComponent <Scenario>().Score += step.floats[0];

            if (scenarioController == null)
            {
                scenarioController = GameObject.FindObjectOfType <ScenarioController>();
            }
            scenarioController.RemoveActiveStep(scenarioStep);
            scenarioController.AddActiveStep(scenarioStep.GetStep(scenarioStep.ints[0]));
        }
        else
        {
            scenarioStep.IsDone = true;
        }
    }
        private void AddInstances(ScenarioStep scenarioStep, ScenarioOutline scenarioOutline, Feature feature, StepContext stepContext, INativeSuggestionItemFactory <TNativeSuggestionItem> nativeSuggestionItemFactory)
        {
            foreach (var exampleSet in scenarioOutline.Examples.ExampleSets)
            {
                foreach (var row in exampleSet.Table.Body)
                {
                    var replacedText = paramRe.Replace(scenarioStep.Text,
                                                       match =>
                    {
                        string param    = match.Groups["param"].Value;
                        int headerIndex = Array.FindIndex(exampleSet.Table.Header.Cells, c => c.Value.Equals(param));
                        if (headerIndex < 0)
                        {
                            return(match.Value);
                        }
                        return(row.Cells[headerIndex].Value);
                    });

                    var newStep = scenarioStep.Clone();
                    newStep.Text = replacedText;
                    instances.Add(new StepInstance <TNativeSuggestionItem>(newStep, feature, stepContext, nativeSuggestionItemFactory, 2)
                    {
                        ParentTemplate = this
                    });
                }
            }
        }
示例#14
0
        private void listBoxScenarioSteps_SelectedValueChanged(object sender, EventArgs e)
        {
            ScenarioStep step = (ScenarioStep)listBoxScenarioSteps.SelectedItem;

            if (step == null)
            {
                return;
            }

            labelScenarioStepName.Text                 = step.Name;
            textBoxScenarioStepDescription.Text        = step.Description;
            textBoxScenarioStepId.Text                 = step.Id.ToString();
            textBoxScenarioStepIndex.Text              = step.StepIndex.ToString();
            textBoxScenarioStepQuestRewardId.Text      = step.QuestRewardId.ToString();
            linkLabelScenarioStepQuestReward.Visible   = !(textBoxScenarioStepQuestRewardId.Text == "0" || string.IsNullOrEmpty(textBoxScenarioStepQuestRewardId.Text));
            textBoxScenarioStepRequiredStepId.Text     = step.BonusObjectiveRequiredStepId.ToString();
            checkBoxScenarioStepBonusObjective.Checked = (step.Flags & ScenarioStepFlag.BonusObjective) != 0;
            treeViewScenarioStepCriteriaTrees.Nodes.Clear();
            if (step.CriteriaTree != null)
            {
                treeViewScenarioStepCriteriaTrees.Nodes.AddRange(
                    step.CriteriaTree.GetChildrenTreeNodes(ProgramSettings.VerboseCriteriaTree).ToArray());
                treeViewScenarioStepCriteriaTrees.ExpandAll();
            }
        }
示例#15
0
 private void DeattachConnection()
 {
     lastClicked.RemoveConnection(secondClicked);
     secondClicked = null;
     lastClicked   = null;
     state         = EditingState.standart;
     EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
 }
示例#16
0
 public void AttachConnection()
 {
     lastClicked.AddNextStep(secondClicked.id);
     secondClicked = null;
     lastClicked   = null;
     state         = EditingState.standart;
     EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
 }
示例#17
0
 public void RemovePrevConnection(ScenarioStep toRemove)
 {
     if (prevSteps.Contains(toRemove.id))
     {
         prevSteps.Remove(toRemove.id);
         toRemove.RemoveConnection(this);
     }
 }
示例#18
0
    public override void Action(Transform interactionArea, ScenarioStep scenarioStep)
    {
        Transform temp   = scenarioStep.gameObjects[0].transform;
        Vector3   target = new Vector3(scenarioStep.floats[0], scenarioStep.floats[1], scenarioStep.floats[2]);

        temp.rotation       = Quaternion.Euler(target);
        scenarioStep.IsDone = true;
    }
示例#19
0
    public override void Action(Transform interactionArea, ScenarioStep scenarioStep)
    {
        Transform temp   = scenarioStep.gameObjects[0].transform;
        Vector3   target = new Vector3(scenarioStep.floats[0], scenarioStep.floats[1], scenarioStep.floats[2]);

        temp.localPosition  = target;
        scenarioStep.IsDone = true;
    }
示例#20
0
        public void Add(ScenarioStep scenarioStep)
        {
            if (ScenarioSteps.ContainsKey(scenarioStep.Id))
            {
                return;
            }

            ScenarioSteps.Add(scenarioStep.Id, scenarioStep);
        }
 public override void Action(Transform interactionArea, ScenarioStep scenarioStep)
 {
     if (scenarioStep.strings[0] != "" && !Input.GetKey(scenarioStep.strings[0]))
     {
         return;
     }
     scenarioStep.IsDone = true;
     scenarioStep.gameObjects[0].transform.SetParent(scenarioStep.gameObjects[1].transform);
 }
        private List <string> ClassesDeclared(TestClassGenerationContext generationContext, CodeMemberMethod testMethod,
                                              ScenarioStep scenarioStep, List <string> classesDeclared)
        {
            var result = m_stepTextAnalyzer.Analyze(scenarioStep.Text, new CultureInfo("en-GB"));

            if (scenarioStep.MultiLineTextArgument != null)
            {
                result.Parameters.Add(new AnalyzedStepParameter("String", "multilineText"));
            }

            if (scenarioStep.TableArg != null)
            {
                result.Parameters.Add(new AnalyzedStepParameter("Table", "table"));
            }
            var regex = GetSimpleRegex(result);

            try
            {
                var originalFilePath = new FileInfo(generationContext.Feature.SourceFile).Directory.Parent.FullName +
                                       @"\bin\debug";
                var newFolderPath = Path.GetTempPath() + @"\Specflowdlls\" + DateTime.Now.ToLongDateString() +
                                    DateTime.Now.Ticks;

                var newDir = new DirectoryInfo(newFolderPath);
                newDir.Create();

                string[] files = Directory.GetFiles(originalFilePath, "*.dll");

                foreach (string file in files)
                {
                    string otherFile = Path.Combine(newFolderPath, Path.GetFileName(file));
                    File.Copy(file, otherFile, true);
                }

                var dllname = new FileInfo(generationContext.Feature.SourceFile).Directory.Parent.Name + ".dll";

                var assembly = Assembly.LoadFrom(String.Concat(newFolderPath, @"\", dllname));

                var methods = assembly.GetTypes()
                              .SelectMany(t => t.GetMethods())
                              .Where(m => HasSpecflowAttribute(m.GetCustomAttributesData(), regex))
                              .ToArray();


                foreach (var methodInfo in methods)
                {
                    classesDeclared = AddStatements(testMethod, methodInfo, classesDeclared, scenarioStep, result, regex);
                }
            }
            catch (Exception exception)
            {
                throw new Exception("oops", exception);
            }
            return(classesDeclared);
        }
示例#23
0
 public virtual void Action(Transform interactionArea, ScenarioStep scenarioStep)
 {
     if (!scenarioStep.IsPreviousStepsDone())
     {
         return;
     }
     if (interactionArea != null && interactionArea == scenarioStep.gameObjects[0])
     {
         return;
     }
 }
示例#24
0
        private static ScenarioStep ConvertToCompatibleStep(SpecFlowStep step)
        {
            ScenarioStep result = null;

            if (step.StepKeyword == StepKeyword.Given)
            {
                result = new Given {
                    StepKeyword = step.StepKeyword
                }
            }
            ;
            else if (step.StepKeyword == StepKeyword.When)
            {
                result = new When {
                    StepKeyword = step.StepKeyword
                }
            }
            ;
            else if (step.StepKeyword == StepKeyword.Then)
            {
                result = new Then {
                    StepKeyword = step.StepKeyword
                }
            }
            ;
            else if (step.StepKeyword == StepKeyword.And)
            {
                result = new And {
                    StepKeyword = step.StepKeyword
                }
            }
            ;
            else if (step.StepKeyword == StepKeyword.But)
            {
                result = new But {
                    StepKeyword = step.StepKeyword
                }
            }
            ;

            if (result == null)
            {
                throw new NotSupportedException();
            }

            result.Keyword               = step.Keyword;
            result.Text                  = step.Text;
            result.ScenarioBlock         = step.ScenarioBlock;
            result.MultiLineTextArgument = step.Argument is global::Gherkin.Ast.DocString ? ((global::Gherkin.Ast.DocString)step.Argument).Content : null;
            result.TableArg              = step.Argument is global::Gherkin.Ast.DataTable ? ConvertToCompatibleTable(((global::Gherkin.Ast.DataTable)step.Argument).Rows) : null;
            result.FilePosition          = ConvertToCompatibleFilePosition(step.Location);

            return(result);
        }
示例#25
0
    public override void Action(Transform interactionArea, ScenarioStep scenarioStep)
    {
        scenarioStep.floats[1] -= Time.deltaTime;
        Debug.Log(scenarioStep.floats[1]);
        if (scenarioStep.floats[1] < 0)
        {
            scenarioStep.IsDone = true;

            scenarioStep.floats[1] = scenarioStep.floats[0];
        }
    }
示例#26
0
    public override void Action(Transform interactionArea, ScenarioStep scenarioStep)
    {
        Transform temp   = scenarioStep.gameObjects[0].transform;
        Vector3   target = new Vector3(scenarioStep.floats[0], scenarioStep.floats[1], scenarioStep.floats[2]);

        temp.localPosition = Vector3.MoveTowards(temp.localPosition, target, Time.deltaTime * scenarioStep.floats[3]);
        if (temp.localPosition.Equals(target))
        {
            scenarioStep.IsDone = true;
        }
    }
示例#27
0
    public override void Action(Transform interactionArea, ScenarioStep scenarioStep)
    {
        Transform  temp     = scenarioStep.gameObjects[0].transform;
        Quaternion rotation = Quaternion.Euler(scenarioStep.floats[0], scenarioStep.floats[1], scenarioStep.floats[2]);

        temp.localRotation = Quaternion.RotateTowards(temp.localRotation, rotation, Time.deltaTime * scenarioStep.floats[3]);
        if (temp.localRotation.Equals(rotation))
        {
            scenarioStep.IsDone = true;
        }
    }
示例#28
0
        public Scenario getScenario()
        {
            Scenario _scenario = new Scenario();

            foreach (Tuple <Entities.Action, Actor> step in scenario)
            {
                ScenarioStep s = new ScenarioStep(step.Item1, step.Item2);
                _scenario.AddScenarioStep(s);
            }
            return(_scenario);
        }
示例#29
0
 public ScenarioStep CheckContainById(ScenarioStep step)
 {
     foreach (ScenarioStep temp in scenarioSteps)
     {
         if (temp.id == step.id)
         {
             return(temp);
         }
     }
     return(null);
 }
示例#30
0
 public static StepVm CreateFromSpecFlowScenario(ScenarioStep specFlowScenarioStep)
 {
     return new StepVm
                {
                  Keyword = specFlowScenarioStep.Keyword,
                  MultiLineTextArgument = specFlowScenarioStep.MultiLineTextArgument,
                  ScenarioBlock = specFlowScenarioStep.ScenarioBlock,
                  StepKeyword = specFlowScenarioStep.StepKeyword,
                  TableArg = specFlowScenarioStep.TableArg,
                  Text = specFlowScenarioStep.Text
                };
 }
示例#31
0
 public void AddPrevStep(int step)
 {
     if (!prevSteps.Contains(step) && !nextSteps.Contains(step) && step != id)
     {
         prevSteps.Add(step);
         ScenarioStep prevStep = GetStep(step);
         if (prevStep != null)
         {
             GetStep(step).AddNextStep(id);
         }
     }
 }
示例#32
0
 public void NotifyProgress(ScenarioStep nextStep)
 {
     if (nextStep == ScenarioStep.Continue)
     {
         actualStep++;
         BeginStep();
     }
     else
     {
         RestartChapter();
     }
 }
示例#33
0
        public StepBuilder(string keyword, string text, FilePosition position, I18n i18n)
        {
            if (i18n.keywords("given").contains(keyword)) step = new Given();
            else if (i18n.keywords("when").contains(keyword)) step = new When();
            else if (i18n.keywords("then").contains(keyword)) step = new Then();
            else if (i18n.keywords("and").contains(keyword)) step = new And();
            else if (i18n.keywords("but").contains(keyword)) step = new But();
            else throw new ArgumentOutOfRangeException(string.Format("Parameter 'keyword' has value that can not be translated! Value:'{0}'", keyword));

            step.Text = text;
            step.FilePosition = position;
        }
示例#34
0
        public StepTemplateViewModel(ScenarioStep stepNode)
            : base(stepNode)
        {
            string text = stepNode.Text;

            TextElements = new List<StepTemplateTextViewModel>();
            PlaceHolderNames = new List<string>();
            bool isPlaceholder = text.StartsWith("<");
            foreach (var str in text.Split("<>".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
            {
                var s = str;
                if (isPlaceholder)
                {
                    PlaceHolderNames.Add(s);
                    s = "<" + s + ">";
                }
                TextElements.Add(new StepTemplateTextViewModel(s, isPlaceholder));
                isPlaceholder = !isPlaceholder;
            }
        }
        private static void AddStep(ScenarioStep scenarioStep, bool isScenarioOutline, StringBuilder formettedScenario)
        {
            formettedScenario.Append("<p");
            if (scenarioStep is And || scenarioStep is But)
                formettedScenario.Append(" class='gherkin-step gherkin-and-step'");
            else
                formettedScenario.Append(" class='gherkin-step'");
            formettedScenario.AppendLine(">");

            formettedScenario.AppendFormat("<span class='gherkin-keyword'>{0}</span>", scenarioStep.Keyword);

            formettedScenario.AppendFormat("<span>{0}</span>", scenarioStep.Text);
            formettedScenario.AppendLine("</p>");

            if (scenarioStep.MultiLineTextArgument != null)
            {
                //TODO
            }
            if (scenarioStep.TableArg != null)
            {
                AddTable(scenarioStep.TableArg, formettedScenario);
            }
        }
示例#36
0
 protected virtual void AppendStepLine(StringBuilder result, ScenarioStep step)
 {
     AppendNodeLine(result, step.FilePosition, "{2}{0}{1}", step.Keyword, step.Text, indent);
 }
        private ScenarioStep CloneTo(ScenarioStep step, string currentBlock)
        {
            ScenarioStep newStep = null;
            if (currentBlock == "When")
                newStep = new When();
            else if (currentBlock == "Then")
                newStep = new Then();
            else // Given or empty
                newStep = new Given();

            Debug.Assert(newStep != null);

            newStep.Text = step.Text;
            newStep.MultiLineTextArgument = step.MultiLineTextArgument;
            newStep.TableArg = Clone(step.TableArg);
            return newStep;
        }
        private ScenarioStep Clone(ScenarioStep step)
        {
            ScenarioStep newStep = null;
            if (step is Given)
                newStep = new Given();
            else if (step is When)
                newStep = new When();
            else if (step is Then)
                newStep = new Then();
            else if (step is And)
                newStep = new And();
            else if (step is But)
                newStep = new But();

            Debug.Assert(newStep != null);

            newStep.Text = step.Text;
            newStep.MultiLineTextArgument = step.MultiLineTextArgument;
            newStep.TableArg = Clone(step.TableArg);
            return newStep;
        }
示例#39
0
        public void Run(ScenarioStep scenario)
        {
            var exceptions = new List<Exception>();
            object ctx = null;
            for (var step = scenario; step != null; step = step.NextStep)
            {
                var indentLength = 0;
                var prefix = "";
                var underlineChar = '`';
                switch (step.StepType)
                {
                    case ScenarioStepType.Scenario:
                        indentLength = 0;
                        prefix = "Scenario: ";
                        underlineChar = '=';
                        break;
                    case ScenarioStepType.Given:
                        indentLength = 0;
                        prefix = "Given: ";
                        underlineChar = '~';
                        break;
                    case ScenarioStepType.AndGiven:
                        indentLength = 0;
                        prefix = "And given";
                        underlineChar = '~';
                        break;
                    case ScenarioStepType.ButGiven:
                        indentLength = 0;
                        prefix = "But given";
                        underlineChar = '~';
                        break;
                    case ScenarioStepType.When:
                        indentLength = 2;
                        prefix = "When";
                        underlineChar = '^';
                        break;
                    case ScenarioStepType.AndWhen:
                        indentLength = 2;
                        prefix = "And when";
                        break;
                    case ScenarioStepType.Then:
                        indentLength = 2;
                        prefix = "Then";
                        break;
                }
                var indent = "".PadLeft(indentLength);

                var stepPassed = true;
                try
                {
                    ctx = step.Execute(ctx);
                }
                catch (SuccessException)
                {

                }
                catch (Exception e)
                {
                    stepPassed = false;
                    ConsoleHelper.WriteLineUnderlining(underlineChar, "X: {0}{1} {2}", indent, prefix, step.Title);
                    Console.WriteLine("{0}", e.Message);
                    Console.WriteLine("{0}", e.StackTrace);
                    Console.WriteLine();
                    if (step.StepType != ScenarioStepType.Then)
                        throw;
                    exceptions.Add(e);
                }

                if (step.StepType == ScenarioStepType.Scenario)
                {
                    ConsoleHelper.WriteLineUnderlining(underlineChar, "{0}{1} {2}", indent, prefix, step.Title);
                    Console.WriteLine();
                }
                else
                {
                    if (stepPassed)
                    {
                        ConsoleHelper.WriteLineUnderlining(underlineChar, "V: {0}{1} {2}", indent, prefix, step.Title);
                    }
                }
            }

            Console.WriteLine("".PadLeft(30, '-'));

            if (exceptions.Any())
                throw new AggregateException(exceptions);
        }
示例#40
0
 /// <summary>
 /// </summary>
 /// <param name="hostid">ID of the host that the web scenario belongs to.</param>
 /// <param name="name">Name of the web scenario.</param>
 public Create(string hostid, string name, ScenarioStep[] steps)
     : base(hostid, name)
 {
     this.steps = steps;
 }
        private List<string> ClassesDeclared(TestClassGenerationContext generationContext, CodeMemberMethod testMethod,
                                     ScenarioStep scenarioStep, List<string> classesDeclared)
        {
            var result = m_stepTextAnalyzer.Analyze(scenarioStep.Text, new CultureInfo("en-GB"));

            if (scenarioStep.MultiLineTextArgument != null)
                result.Parameters.Add(new AnalyzedStepParameter("String", "multilineText"));

            if (scenarioStep.TableArg != null)
                result.Parameters.Add(new AnalyzedStepParameter("Table", "table"));
            var regex = GetSimpleRegex(result);

            try
            {
                var originalFilePath = new FileInfo(generationContext.Feature.SourceFile).Directory.Parent.FullName +
                                       @"\bin\debug";
                var newFolderPath = Path.GetTempPath() + @"\Specflowdlls\" + DateTime.Now.ToLongDateString() +
                                    DateTime.Now.Ticks;

                var newDir = new DirectoryInfo(newFolderPath);
                newDir.Create();

                string[] files = Directory.GetFiles(originalFilePath, "*.dll");

                foreach (string file in files)
                {
                    string otherFile = Path.Combine(newFolderPath, Path.GetFileName(file));
                    File.Copy(file, otherFile, true);
                }

                var dllname = new FileInfo(generationContext.Feature.SourceFile).Directory.Parent.Name + ".dll";

                var assembly = Assembly.LoadFrom(String.Concat(newFolderPath, @"\", dllname));

                var methods = assembly.GetTypes()
                                      .SelectMany(t => t.GetMethods())
                                      .Where(m => HasSpecflowAttribute(m.GetCustomAttributesData(), regex))
                                      .ToArray();


                foreach (var methodInfo in methods)
                {
                    classesDeclared = AddStatements(testMethod, methodInfo, classesDeclared, scenarioStep, result, regex);
                }
            }
            catch (Exception exception)
            {
                throw new Exception("oops", exception);
            }
            return classesDeclared;
        }
        private List<string> AddStatements(CodeMemberMethod testMethod, MethodInfo methodInfo, List<string> classesDeclared, ScenarioStep step, AnalyzedStepText stepText, string regex)
        {
            if (!HasClassBeenDeclared(classesDeclared, methodInfo.DeclaringType.ToString()))
            {
                var testRunnerField = new CodeVariableDeclarationStatement(
                    methodInfo.DeclaringType, methodInfo.DeclaringType.Name.ToLower(),
                    new CodeObjectCreateExpression(methodInfo.DeclaringType));
                testMethod.Statements.Add(testRunnerField);
                classesDeclared.Add(methodInfo.DeclaringType.ToString());
            }

            ParameterInfo[] parameters = methodInfo.GetParameters();

            if (parameters.Any())
            {
                //declare any variables needed here
                //string value = step.Text
                int i = 0;
                foreach (ParameterInfo parameterInfo in parameters) //these are the parameters needed
                {
                    string parameterValue = stepText.TextParts[i];


                    Match match = Regex.Match(step.Text,regex);
                    if (match.Success)
                    {
                         parameterValue = match.Groups[1].Value;
                    }

                    bool paramAlreadyDeclared = false;

                    //check not in test case
                    foreach (CodeParameterDeclarationExpression parameter in testMethod.Parameters) //these are the ones specified by the test case attributes
                    {
                        if (parameterInfo.Name == parameter.Name)
                        {
                            paramAlreadyDeclared = true;
                        }
                    }

                    //check not already declared in body of method
                    foreach (var preDecalredParam in m_parametersDeclaredInMethod)
                    {
                        if (preDecalredParam == parameterInfo.Name)
                        {
                            paramAlreadyDeclared = true;
                        }
                    }

                    if (!paramAlreadyDeclared)
                    {
                        m_parametersDeclaredInMethod.Add(parameterInfo.Name);//record that param declared
                        CodeVariableDeclarationStatement variable = new CodeVariableDeclarationStatement(typeof(string), parameterInfo.Name, new CodePrimitiveExpression(parameterValue));
                        testMethod.Statements.Add(variable);
                    }

                }



                testMethod.Statements.Add(new CodeMethodInvokeExpression(
                                        new CodeTypeReferenceExpression(
                                            methodInfo.DeclaringType.Name.ToLower()),
                                        methodInfo.Name,
                                        GetParameters(testMethod, methodInfo)));
            }
            else
            {
                testMethod.Statements.Add(new CodeMethodInvokeExpression(
                                              new CodeTypeReferenceExpression(
                                                  methodInfo.DeclaringType.Name.ToLower()),
                                              methodInfo.Name));
            }
            return classesDeclared;
        }
示例#43
0
 public StepViewModel(ScenarioStep scenarioStep, string formattedText = null)
     : base(scenarioStep, formattedText)
 {
 }
示例#44
0
 public StepViewModelBase(ScenarioStep stepNode, string formattedText = null)
 {
     StepNode = stepNode;
     FormattedScenarioBlock = stepNode.StepKeyword.ToString();
     FormattedText = formattedText??stepNode.Text;
 }