Exemple #1
0
        public override object DoRun()
        {
            List <IAnswer> answers = new List <IAnswer>();

            var remainingSteps = Interpreter2.Plan.Count() - Interpreter.Iterator.Index;
            int count          = Math.Min(remainingSteps, Count);

            for (int i = 0; i < count; i++)
            {
                ConsoleView.Render(ConsoleColor.DarkGray, $"Starting step {Interpreter.Iterator.Index + 1})\t{Interpreter.Iterator.Current}");

                var answer = Interpreter2.Please(string.Empty);
                answers.Add(answer);

                //ConsoleView.Render(ConsoleColor.DarkGray, $"Finished step {Interpreter.Iterator.Index })\t{Interpreter.Iterator.Previous}\n{Interpreter.Iterator.Previous.Status}");
                ConsoleView.Render(Interpreter.Please("status"));

                if (UserInteropAdapter.IsKeyDown(Keys.Escape))
                {
                    Interpreter.IsDebugMode = true;
                    return("Escape pressed. Interrupting...");
                }
            }

            if (answers.Any(x => x is INegativeAnswer))
            {
                var baseAnswer = new ExceptionAnswer($"Ran {count} step{(count == 1 ? "" : "s")}.");
                baseAnswer.Children = answers;
                return(baseAnswer);
            }
            else
            {
                var baseAnswer = new SuccessAnswer($"Ran {count} step{(count == 1 ? "" : "s")}.");
                baseAnswer.Children = answers;
                return(baseAnswer);
            }
        }
Exemple #2
0
        public override object DoRun()
        {
            LoadKeywords();

            if (Technique == Technique.Show && Interpreter.IsDebugMode)
            {
                return(StepIntoScenario());
            }

            if (_plan.Any(x => x is RunScenario))
            {
                throw new ArgumentException("RunScenario cannot call underlying RunScenario keywords.");
            }

            while (!Iterator.IsEndOfList())
            {
                var keyword = Iterator.Current;

                try
                {
                    ConsoleView.Render(ConsoleColor.DarkGray, $"RunScenario: Starting step {Iterator.Index+1})\t{Iterator.Current}");

                    var result = (keyword).Execute();

                    if (result != null && result.Equals(KeywordResultSpecialCases.Skipped))
                    {
                        Console.WriteLine("Skipping " + keyword);
                    }

                    ConsoleView.Render(ConsoleColor.DarkGray, $"RunScenario: Finished step {Iterator.Index+1})\t{Iterator.Current}\n{Iterator.Current.Status}");

                    if (result is IAnswer)
                    {
                        ConsoleView.Render((IAnswer)result);
                    }
                    else
                    {
                        ConsoleView.Render(new InformativeAnswer(result));
                    }

                    Iterator.MoveNext();

                    if (UserInteropAdapter.IsKeyDown(Keys.Escape))
                    {
                        Interpreter.IsDebugMode = true;
                        return("Escape pressed. Interrupting...");
                    }
                }
                catch (Exception e)
                {
                    if (Interpreter.IsDebugMode)
                    {
                        Interpreter.Iterator.MoveBack(1);

                        var error = new CanIContinueRunScenarioEvenThoughIFoundError(this)
                        {
                            Children = new List <IAnswer>()
                            {
                                new ExceptionAnswer(e)
                            }
                        };

                        this.Iterator.MoveNext();

                        return(error);
                    }

                    Interpreter.OnScenarioFinished(new ScenarioEventArgs(Plan.ToList(), FileName));
                    Iterator.Index = 0;
                    throw;
                }
            }

            Interpreter.OnScenarioFinished(new ScenarioEventArgs(Plan.ToList(), FileName));

            Iterator.Index = 0;

            return(null);
        }