Beispiel #1
0
        public async Task Chat(CommandContext ctx)
        {
            await ctx.Message.DeleteAsync().ConfigureAwait(false);

            var inputStep    = new StringStep("Enter You Text Below To Start Speaking.", null);
            var emptyStep    = new StringStep("Please Enter Some Text Please.", null);
            var continueStep = new StringStep("Continue Chat By Typing Below.", null);

            string input = string.Empty;

            inputStep.OnValidResult += (result) =>
            {
                input = result;
            };

            var userChannel = await ctx.Member.CreateDmChannelAsync().ConfigureAwait(false);

            var inputDialogueHandler = new EmbedChatHandler(
                ctx.Client,
                userChannel,
                ctx.User,
                inputStep
                );

            bool succeeded = await inputDialogueHandler.ProcessDialogue().ConfigureAwait(false);

            if (!succeeded)
            {
                return;
            }

            await ctx.Channel.SendMessageAsync(input).ConfigureAwait(false);
        }
Beispiel #2
0
            public void ShouldFindGivenWithEmbeddedParam()
            {
                var actionStepToFind = new StringStep("Given", "a method with \"embedded\" parameter like \"this\" should work", "file");
                var action           = _actionCatalog.GetAction(actionStepToFind);

                Assert.That(action, Is.Not.Null);
            }
Beispiel #3
0
 public StepBuilder(IGherkinParserEvents gherkinEvents)
 {
     gherkinEvents.ScenarioEvent += (s, e) =>
     {
         HandlePreviousEvent();
         scenario = e.EventInfo;
     };
     gherkinEvents.StepEvent += (s, e) =>
     {
         HandlePreviousEvent();
         previousStep = e.EventInfo;
     };
     gherkinEvents.DocStringEvent  += (s, e) => HandleDocString(e.EventInfo);
     gherkinEvents.FeatureEvent    += (s, e) => HandlePreviousEventAndCleanUp();
     gherkinEvents.ExamplesEvent   += (s, e) => HandlePreviousEvent();
     gherkinEvents.BackgroundEvent += (s, e) =>
     {
         HandlePreviousEvent();
         scenario = e.EventInfo;
     };
     gherkinEvents.TableEvent += (s, e) =>
     {
         HandleTableEvent(e.EventInfo);
         previousStep = null;
     };
     gherkinEvents.TagEvent += (s, e) => HandlePreviousEvent();
     gherkinEvents.EofEvent += (s, e) => HandlePreviousEventAndCleanUp();
 }
Beispiel #4
0
            public void ShouldNotMatchLongTextAgainstTheRestrictedLengthParameter()
            {
                var actionStepToFind = new StringStep("Given", "a length restriction on the \"supplied value\" should work", "file");
                var action           = _actionCatalog.GetAction(actionStepToFind);

                Assert.That(action, Is.Null);
            }
Beispiel #5
0
            public void ShouldCallIsMatchOnInterfaceWithCorrectFileName()
            {
                var actionStepText = new StringStep("Given", "something", FileNameToMatch);

                _actionCatalog.ActionExists(actionStepText);
                Assert.That(_wasCalledWithFileName, Is.EqualTo(FileNameToMatch));
            }
Beispiel #6
0
            private void BecauseOf()
            {
                var actionText = new StringStep("Given", "abc def", "somestory.story");
                var action     = _actionCatalog.GetAction(actionText);

                (action.Action as Action).Invoke();
            }
Beispiel #7
0
        private void RunStep(ScenarioFragment currentStage, string step, StringStep stringStep)
        {
            var stepToRun = new StringStep(string.Format("{0} {1}", currentStage, step), Scenario.Source);

            StepRunner.Run(stepToRun);
            stringStep.StepResult = new StepResult(stringStep, stepToRun.StepResult.Result);
        }
Beispiel #8
0
 public object[] GetParametersForStep(StringStep stringStep, Example example)
 {
     var action = actionCatalog.GetAction(stringStep);
     Func<string, string> getValues = i => example.ColumnValues[i];
     var paramNames = action.ParameterInfo.Select(a => a.Name).ToList();
     return GetParametersForStep(action, paramNames, getValues);
 }
            public void Should_Call_afterStep_if_step_fails()
            {
                var step = new StringStep("something", "");

                runner.Run(step);
                Assert.That(_afterStepWasCalled, Is.True);
            }
Beispiel #10
0
 private void HandlePreviousEvent()
 {
     if (previousStep == null || scenario == null)
         return;
     scenario.AddStep(previousStep);
     previousStep = null;
 }
Beispiel #11
0
            public void Same_step_text_but_different_sorce_file_should_not_be_equal()
            {
                var s1 = new StringStep("Given", "Foo", "s1");
                var s2 = new StringStep("Given", "Foo", "s2");

                Assert.That(s1, Is.Not.EqualTo(s2));
            }
 public void ShouldFindWhenStepWithWhenAttribute()
 {
     var actionStepToFind = new StringStep("Given using WhenAttribute with no regex", "file");
     var action = _actionCatalog.GetAction(actionStepToFind);
     Assert.That(action.ActionType, Is.EqualTo("When"));
     Assert.That(action.ActionStepMatcher.ToString(), Is.EqualTo(@"^using\s+WhenAttribute\s+with\s+no\s+regex\s*$"));
 }
Beispiel #13
0
 public void Should_build_string_step(string stringStep)
 {
     var step = new StringStep(stringStep, "whatever");
     var example = new Example(new ExampleColumns(new[] { new ExampleColumn("param"), }), new Dictionary<string, string> { { "param", "12" } });
     var newStep = step.BuildStep(example);
     Assert.That(newStep.Step, Is.EqualTo("Given a 12"));
 }
Beispiel #14
0
 public StepBuilder(IGherkinParserEvents gherkinEvents)
 {
     gherkinEvents.ScenarioEvent += (s, e) =>
                                        {
                                            HandlePreviousEvent();
                                            scenario = e.EventInfo;
                                        };
     gherkinEvents.StepEvent += (s, e) =>
                                    {
                                        HandlePreviousEvent();
                                        previousStep = e.EventInfo;
                                    };
     gherkinEvents.DocStringEvent += (s, e) => HandleDocString(e.EventInfo);
     gherkinEvents.FeatureEvent += (s, e) => HandlePreviousEventAndCleanUp();
     gherkinEvents.ExamplesEvent += (s, e) => HandlePreviousEvent();
     gherkinEvents.BackgroundEvent += (s, e) =>
                                          {
                                              HandlePreviousEvent();
                                              scenario = e.EventInfo;
                                          };
     gherkinEvents.TableEvent += (s, e) =>
                                     {
                                         HandleTableEvent(e.EventInfo);
                                         previousStep = null;
                                     };
     gherkinEvents.TagEvent += (s, e) => HandlePreviousEvent();
     gherkinEvents.EofEvent += (s, e) => HandlePreviousEventAndCleanUp();
 }
Beispiel #15
0
 private void AddDocStringParameter(object[] parametersForStep, StringStep stringStep)
 {
     int last = parametersForStep.Length - 1;
     if (stringStep.HasDocString == false || parametersForStep[last] != null)
         return;
     parametersForStep[last] = stringStep.DocString;
 }
        public void Step(Token keyword, Token name)
        {
            string stepText   = string.Format("{0} {1}", keyword.Content, name.Content);
            var    stringStep = new StringStep(stepText, file, keyword.LineInFile.Line);

            events.Enqueue(new StepEvent(stepText, e => StepEvent.Invoke(this, new EventArgs <StringStep>(stringStep))));
        }
 public CodeGenStep(string feature, string scenario, StringStep step, string code)
 {
     Feature  = feature;
     Scenario = scenario;
     Step     = step.Step;
     Code     = code;
 }
Beispiel #18
0
 public object[] GetParametersForStep(StringStep stringStep, Example example)
 {
     var action = _actionCatalog.GetAction(stringStep);
     Func<string, string> getValues = i => example.ColumnValues[i];
     var paramNames = action.ParameterInfo.Select(a => a.Name).ToList();
     return GetParametersForStep(action, paramNames, getValues);
 }
Beispiel #19
0
 private void AddDocStringParameter(object[] parametersForStep, StringStep stringStep)
 {
     int last = parametersForStep.Length - 1;
     if (stringStep.HasDocString == false || parametersForStep[last] != null)
         return;
     parametersForStep[last] = stringStep.DocString;
 }
Beispiel #20
0
 private object[] GetParametersForStep(StringStep stringStep, ActionMethodInfo action)
 {
     var match = action.ActionStepMatcher.Match(stringStep.MatchableStep);
     Func<string, string> getValues = _ => match.Groups[_].Value;
     var paramNames = GetParameterNames(action);
     return GetParametersForStep(action, paramNames, getValues);
 }
            public void ShouldReturnPendingIfActionGivenInTokenStringDoesntExist()
            {
                var step = new StringStep("Given this doesnt exist", "");

                runner.Run(step);
                Assert.That(step.StepResult.Result, Is.TypeOf(typeof(PendingNotImplemented)));
            }
            public void ShouldMatchShortTextAgainstTheRestrictedLengthParameter()
            {
                var actionStepToFind = new StringStep("Given a length restriction on the \"txt\" should work", "file");
                var action           = _actionCatalog.GetAction(actionStepToFind);

                Assert.That(action, Is.Not.Null);
            }
            public void RunningAStepShouldCallMostAttributedMethods()
            {
                var step = new StringStep("something", "");

                runner.Run(step);
                Assert.That(step.StepResult.Result, Is.InstanceOf <Failed>());
                Assert.That(step.StepResult.Message, Is.StringContaining("ArgumentNullException"));
            }
Beispiel #24
0
 public void StepStarted(StringStep step)
 {
     contextHandler.OnStepStartedEvent(step);
     if (OnStepStarted != null)
     {
         OnStepStarted(this, new EventArgs <StringStep>(step));
     }
 }
Beispiel #25
0
            public void ShouldFindGivenStepWithGivenAttribute()
            {
                var actionStepToFind = new StringStep("Given", "a method with tokenstring and two parameters, one int value 42 plus text thistext", "file");
                var action           = _actionCatalog.GetAction(actionStepToFind);

                Assert.That(action.ActionType, Is.EqualTo("Given"));
                Assert.That(action.ActionStepMatcher.ToString(), Is.EqualTo(@"^a\s+method\s+with\s+tokenstring\s+and\s+two\s+parameters,\s+one\s+int\s+value\s+(?<intParam>.+)\s+plus\s+text\s+(?<stringParam>.+)\s*$"));
            }
Beispiel #26
0
            public void ShouldFindWhenStepWithWhenAttribute()
            {
                var actionStepToFind = new StringStep("Given", "using WhenAttribute with no regex", "file");
                var action           = _actionCatalog.GetAction(actionStepToFind);

                Assert.That(action.ActionType, Is.EqualTo("When"));
                Assert.That(action.ActionStepMatcher.ToString(), Is.EqualTo(@"^using\s+WhenAttribute\s+with\s+no\s+regex\s*$"));
            }
        private TypeOfStep DetermineTypeOfStep(StringStep stringStep)
        {
            var step = stringStep.TypeOfStep;

            step           = (step == TypeOfStep.Unknown) ? lastTypeOfStep : step;
            lastTypeOfStep = step;
            return(step);
        }
Beispiel #28
0
 private void HandlePreviousEvent()
 {
     if (previousStep == null || scenario == null)
     {
         return;
     }
     scenario.AddStep(previousStep);
     previousStep = null;
 }
Beispiel #29
0
            public override void SetUp()
            {
                base.SetUp();
                var feature = FeatureWithOneScenarioWithOneStep();

                step = feature.Scenarios[0].Steps.First();
                hooksCatalog.Add(new DelegateHookMetaData(() => { throw new ArgumentNullException("AfterStep"); }, new AfterStepAttribute()));
                featureRunner.Run(feature);
            }
Beispiel #30
0
            public void Should_build_string_step(string stringStep)
            {
                var step    = new StringStep("Given", stringStep, "whatever");
                var example = new Example(new ExampleColumns(new[] { new ExampleColumn("param"), }), new Dictionary <string, string> {
                    { "param", "12" }
                });
                var newStep = step.BuildStep(example);

                Assert.That(newStep.Step, Is.EqualTo("Given a 12"));
            }
Beispiel #31
0
 private object[] GetParametersForListStep(ActionMethodInfo action, StringStep stringStep)
 {
     var itemType = action.ParameterInfo[0].ParameterType.GetGenericArguments()[0];
     var values = itemType.CreateInstanceOfGenericList();
     var addMethodOnList = values.GetType().GetMethod("Add");
     Func<Example, string, string> getValues = (e, name) => e.ColumnValues[name];
     var method = new ActionMethodInfo(action.ActionStepMatcher, addMethodOnList, addMethodOnList, action.ActionType);
     GetValuesFromTableStep((StringTableStep)stringStep, getValues, addMethodOnList, values, method);
     return new object[] { values };
 }
Beispiel #32
0
            public void Should_handle_spaces_in_docstring_in_ToString()
            {
                var step = new StringStep("Given step with docstring", "source");
                step.AddDocString("  hello");

                Assert.AreEqual("Given step with docstring" + Environment.NewLine +
                    "  \"\"\"" + Environment.NewLine +
                    "  hello" + Environment.NewLine +
                    "  \"\"\"" + Environment.NewLine, step.ToString());
            }
Beispiel #33
0
            public void Should_handle_spaces_in_docstring_in_ToString()
            {
                var step = new StringStep("Given", "step with docstring", "source");

                step.AddDocString("  hello");

                Assert.AreEqual("Given step with docstring" + Environment.NewLine +
                                "  \"\"\"" + Environment.NewLine +
                                "  hello" + Environment.NewLine +
                                "  \"\"\"" + Environment.NewLine, step.ToString());
            }
            public void CompletingAScenarioShouldCallAllAttributedMethods()
            {
                var actionStepText = new StringStep("something", "");
                runner.Run(actionStepText);
                runner.OnCloseScenario();

                Assert.That(_beforeScenarioWasCalled);
                Assert.That(_beforeStepWasCalled);
                Assert.That(_afterStepWasCalled);
                Assert.That(_afterScenarioWasCalled);
            }
            public void RunningAStepShouldCallMostAttributedMethods()
            {
                var actionStepText = new StringStep("something", "");

                runner.Run(actionStepText);

                Assert.That(_beforeScenarioWasCalled);
                Assert.That(_beforeStepWasCalled);
                Assert.That(_afterStepWasCalled);
                Assert.That(!_afterScenarioWasCalled);
            }
Beispiel #36
0
        public object[] GetParametersForStep(StringStep stringStep)
        {
            var action = _actionCatalog.GetAction(stringStep);

            object[] parametersForStep;
            if (IsListStep(action, stringStep))
                parametersForStep = GetParametersForListStep(action, stringStep);
            else
                parametersForStep = GetParametersForStep(stringStep, action);
            AddDocStringParameter(parametersForStep, stringStep);
            return parametersForStep;
        }
            public void CompletingAScenarioShouldCallAllAttributedMethods()
            {
                var actionStepText = new StringStep("something", "");

                runner.Run(actionStepText);
                runner.OnCloseScenario();

                Assert.That(_beforeScenarioWasCalled);
                Assert.That(_beforeStepWasCalled);
                Assert.That(_afterStepWasCalled);
                Assert.That(_afterScenarioWasCalled);
            }
Beispiel #38
0
        public object[] GetParametersForStep(StringStep stringStep)
        {
            var action = actionCatalog.GetAction(stringStep);

            object[] parametersForStep;
            if (IsListStep(action, stringStep))
                parametersForStep = GetParametersForListStep(action, stringStep);
            else
                parametersForStep = GetParametersForStep(stringStep, action);
            AddDocStringParameter(parametersForStep, stringStep);
            return parametersForStep;
        }
Beispiel #39
0
        private StringStep CreateStringStep(ScenarioFragment currentStage, string step)
        {
            string stepType = currentStage.ToString();

            if (Scenario.Steps.Any() && previousStage == currentStage)
            {
                stepType = "And";
            }
            var stringStep = new StringStep(stepType, step, Scenario.Source);

            return(stringStep);
        }
Beispiel #40
0
 private ActionMethodInfo FindMatchingAction(StringStep stringStep, List<MethodParametersType> sortMethodAfter)
 {
     sortMethodAfter = sortMethodAfter ?? stringStep.MatchableStepTypes.ToList();
     var ms = _actions
         .Select(_ => new { Action = _, Match = _.ActionStepMatcher.Match(stringStep.MatchableStep) })
         .Where(_ => _.Match.Success && MatchesFileName(_.Action, stringStep))
         .Select(_ => new
                 {
                     action = _.Action,
                     _.Match.Length,
                     Prio = sortMethodAfter.Contains(_.Action.MethodParametersType) ? sortMethodAfter.IndexOf(_.Action.MethodParametersType) : Int32.MaxValue
                 })
         .OrderByDescending(_ => _.Length).ThenBy(_ => _.Prio);
     return ms.Select(_ => _.action).FirstOrDefault();
 }
Beispiel #41
0
 public void Run(StringStep step)
 {
     try
     {
         if (!ActionCatalog.ActionExists(step))
         {
             var pendReason = string.Format("No matching Action found for \"{0}\"", step);
             step.PendNotImplemented(pendReason);
         }
         else
         {
             RunStep(step);
         }
     }
     catch (Exception e)
     {
         var realException = FindUsefulException(e);
         step.Fail(realException);
     }
 }
Beispiel #42
0
 public void OnStepStartedEvent(StringStep step)
 {
     stepContext.ClearTags();
     stepContext.AddTags(scenarioContext.Tags);
     stepContext.StringStep = step;
 }
            public void RunningAStepShouldCallMostAttributedMethods()
            {
                var actionStepText = new StringStep("something", "");
                runner.Run(actionStepText);

                Assert.That(_beforeScenarioWasCalled);
                Assert.That(_beforeStepWasCalled);
                Assert.That(_afterStepWasCalled);
                Assert.That(!_afterScenarioWasCalled);
            }
Beispiel #44
0
 private void BeforeStep(StringStep step)
 {
     context.StepStarted(step);
 }
 public void ShouldInvokeActionGivenATokenString()
 {
     var wasCalled = false;
     var docString = "";
     Action<int, string> action = (value, thisIsThedocString) =>
     {
         wasCalled = true;
         docString = thisIsThedocString;
     };
     actionCatalog.Add(new ActionMethodInfo("a value $value followed by docstring".AsRegex(), action, action.Method, "Given"));
     var stringStep = new StringStep("Given a value 42 followed by docstring", "");
     stringStep.AddDocString("docString");
     runner.Run(stringStep);
     Assert.IsTrue(wasCalled, "Action was not called");
     Assert.AreEqual("docString", docString);
 }
 public void Should_Call_afterStep_if_step_fails()
 {
     var step = new StringStep("something", "");
     runner.Run(step);
     Assert.That(_afterStepWasCalled, Is.True);
 }
 public void RunningAStepShouldCallMostAttributedMethods()
 {
     var step = new StringStep("something", "");
     runner.Run(step);
     Assert.That(step.StepResult.Result, Is.InstanceOf<Failed>());
     Assert.That(step.StepResult.Message, Is.StringContaining("ArgumentNullException"));
 }
Beispiel #48
0
 private bool MatchesFileName(ActionMethodInfo action, StringStep stringStep)
 {
     return action.MatchesFileName(stringStep.Source);
 }
Beispiel #49
0
 private void AfterStep(StringStep step)
 {
     context.StepFinished(step.StepResult);
 }
Beispiel #50
0
 private bool IsListStep(ActionMethodInfo action, StringStep step)
 {
     return (action.MethodParametersType == MethodParametersType.TypedListStep
            || action.MethodParametersType == MethodParametersType.UntypedListStep)
            && step is StringTableStep;
 }
Beispiel #51
0
 public void Same_step_text_but_different_sorce_file_should_not_be_equal()
 {
     var s1 = new StringStep("Foo", "s1");
     var s2 = new StringStep("Foo", "s2");
     Assert.That(s1, Is.Not.EqualTo(s2));
 }
Beispiel #52
0
 private object[] GetParametersForListStep(ActionMethodInfo action, StringStep stringStep)
 {
     var itemType = action.ParameterInfo[0].ParameterType.GetGenericArguments()[0];
     var values = itemType.CreateInstanceOfGenericList();
     var addMethodOnList = values.GetType().GetMethod("Add");
     Func<Example, string, string> getValues = (e, name) => e.ColumnValues[name];
     var method = new ActionMethodInfo(action.ActionStepMatcher, addMethodOnList, addMethodOnList, action.ActionType);
     GetValuesFromTableStep((StringTableStep)stringStep, getValues, addMethodOnList, values, method);
     return new object[] { values };
 }
Beispiel #53
0
 private void BecauseOf()
 {
     var actionText = new StringStep("Given foo and bar", "somestory.story");
     _action = _actionCatalog.GetAction(actionText);
 }
Beispiel #54
0
 private void BecauseOf()
 {
     var actionText = new StringStep("Given abc def", "somestory.story");
     var action = _actionCatalog.GetAction(actionText);
     (action.Action as Action).Invoke();
 }
Beispiel #55
0
 public bool ActionExists(StringStep stringStep)
 {
     return FindMatchingAction(stringStep, allActionTypes) != null;
 }
Beispiel #56
0
 private void Cleanup()
 {
     scenario = null;
     previousStep = null;
 }
 public void ShouldReturnPendingIfActionGivenInTokenStringDoesntExist()
 {
     var step = new StringStep("Given this doesnt exist", "");
     runner.Run(step);
     Assert.That(step.StepResult.Result, Is.TypeOf(typeof(PendingNotImplemented)));
 }
 public CodeGenStep(string feature, string scenario, StringStep step, string code)
 {
     Feature = feature;
     Scenario = scenario;
     Step = step.Step;
     Code = code;
 }
 public void Step(Token keyword, Token name)
 {
     string stepText = string.Format("{0} {1}", keyword.Content, name.Content);
     var stringStep = new StringStep(stepText, file, keyword.LineInFile.Line);
     events.Enqueue(new StepEvent(stepText, e => StepEvent.Invoke(this, new EventArgs<StringStep>(stringStep))));
 }
Beispiel #60
0
 public ActionMethodInfo GetAction(StringStep message)
 {
     return FindMatchingAction(message, null);
 }