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); }
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); }
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(); }
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); }
public void ShouldCallIsMatchOnInterfaceWithCorrectFileName() { var actionStepText = new StringStep("Given", "something", FileNameToMatch); _actionCatalog.ActionExists(actionStepText); Assert.That(_wasCalledWithFileName, Is.EqualTo(FileNameToMatch)); }
private void BecauseOf() { var actionText = new StringStep("Given", "abc def", "somestory.story"); var action = _actionCatalog.GetAction(actionText); (action.Action as Action).Invoke(); }
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); }
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); }
private void HandlePreviousEvent() { if (previousStep == null || scenario == null) return; scenario.AddStep(previousStep); previousStep = null; }
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*$")); }
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")); }
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; }
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); }
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")); }
public void StepStarted(StringStep step) { contextHandler.OnStepStartedEvent(step); if (OnStepStarted != null) { OnStepStarted(this, new EventArgs <StringStep>(step)); } }
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*$")); }
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); }
private void HandlePreviousEvent() { if (previousStep == null || scenario == null) { return; } scenario.AddStep(previousStep); previousStep = null; }
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); }
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")); }
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 }; }
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 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); }
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 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; }
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); }
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(); }
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); } }
public void OnStepStartedEvent(StringStep step) { stepContext.ClearTags(); stepContext.AddTags(scenarioContext.Tags); stepContext.StringStep = step; }
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 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")); }
private bool MatchesFileName(ActionMethodInfo action, StringStep stringStep) { return action.MatchesFileName(stringStep.Source); }
private void AfterStep(StringStep step) { context.StepFinished(step.StepResult); }
private bool IsListStep(ActionMethodInfo action, StringStep step) { return (action.MethodParametersType == MethodParametersType.TypedListStep || action.MethodParametersType == MethodParametersType.UntypedListStep) && step is StringTableStep; }
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)); }
private void BecauseOf() { var actionText = new StringStep("Given foo and bar", "somestory.story"); _action = _actionCatalog.GetAction(actionText); }
private void BecauseOf() { var actionText = new StringStep("Given abc def", "somestory.story"); var action = _actionCatalog.GetAction(actionText); (action.Action as Action).Invoke(); }
public bool ActionExists(StringStep stringStep) { return FindMatchingAction(stringStep, allActionTypes) != null; }
private void Cleanup() { scenario = null; previousStep = null; }
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 ActionMethodInfo GetAction(StringStep message) { return FindMatchingAction(message, null); }