public void DigestScenarioStepValues_Sets_DocString_Value() { //arrange. var featureInstance = new FeatureWithDocStringScenarioStep(); var sut = StepMethodInfo.FromMethodInfo( featureInstance.GetType().GetMethod(nameof(FeatureWithDocStringScenarioStep.Step_With_DocString_Argument)), featureInstance ); var docStringContent = @"some content +++ with multi lines --- in it"; var step = new Gherkin.Ast.Step( null, "Given", FeatureWithDocStringScenarioStep.StepWithDocStringText, new Gherkin.Ast.DocString(null, null, docStringContent)); //act. sut.DigestScenarioStepValues(step); //assert. var digestedText = sut.GetDigestedStepText(); Assert.Equal(FeatureWithDocStringScenarioStep.StepWithDocStringText, digestedText); }
public void DigestScenarioStepValues_Sets_Primitive_Values(string keyword) { //arrange. var featureInstance = new FeatureForApplyArgumentValues(); var sut = StepMethodInfo.FromMethodInfo( featureInstance.GetType().GetMethod(nameof(FeatureForApplyArgumentValues.Method_With_Arguments)), featureInstance); var number = 123; var text = "Ana"; var date = new DateTime(2018, 5, 23); var stepText = FeatureForApplyArgumentValues.StepMethodText .Replace(@"(\d+)", $"{number}") .Replace(@"(\w+)", $"{text}") .Replace(@"([\d/]+)", $"{date.Month}/{date.Day}/{date.Year}"); var step = new Gherkin.Ast.Step(null, keyword, stepText, null); //act. sut.DigestScenarioStepValues(step); //assert. var digestedText = sut.GetDigestedStepText(); Assert.Equal(stepText, digestedText); }
private static Gherkin.Ast.Scenario CreateTestScenario() { var tags = new Gherkin.Ast.Tag[] { new Gherkin.Ast.Tag(null, "test") }; var location = new Gherkin.Ast.Location(1, 1); var steps = new Gherkin.Ast.Step[] { new Gherkin.Ast.Step(null, null, "step", null) }; return new Gherkin.Ast.Scenario(tags, location, "keyword", "name", "description", steps); }
/// <summary> /// Converts the provided <see cref="Gherkin.Ast.Step"/> instance into a <see cref="Augurk.Entities.Step"/> instance. /// </summary> /// <param name="step">The <see cref="Gherkin.Ast.Step"/> instance that should be converted.</param> /// <param name="blockKeyword">Current block of keywords being converted.</param> /// <param name="dialect">The <see cref="GherkinDialect"/> that is being used for this feature.</param> /// <returns>The converted <see cref="Augurk.Entities.Step"/> instance.</returns> public static Step ConvertToStep(this Gherkin.Ast.Step step, GherkinDialect dialect) { if (step == null) { throw new ArgumentNullException("step"); } return(new Step() { StepKeyword = step.Keyword.ConvertToStepKeyword(dialect), Keyword = step.Keyword, Content = step.Text, TableArgument = step.Argument.ConvertToTable(), Location = step.Location.ConvertToSourceLocation() }); }
public void ApplyBackground_WithBackground_PrependsBackgroundSteps() { var scenario = CreateTestScenario(); var backgroundSteps = new Gherkin.Ast.Step[] { new Gherkin.Ast.Step(null, null, "background", null) }; var background = new Gherkin.Ast.Background(null, null, null, null, backgroundSteps); var modified = scenario.ApplyBackground(background); Assert.Equal(scenario.Location, modified.Location); Assert.Equal(scenario.Keyword, modified.Keyword); Assert.Equal(scenario.Name, modified.Name); Assert.Equal(scenario.Description, modified.Description); Assert.Equal(2, modified.Steps.Count()); Assert.Equal("background", modified.Steps.ElementAt(0).Text); Assert.Equal("step", modified.Steps.ElementAt(1).Text); }
public void DigestScenarioStepValues_Sets_DataTable_Value() { //arrange. var featureInstance = new FeatureWithDataTableScenarioStep(); var sut = StepMethodInfo.FromMethodInfo( featureInstance.GetType().GetMethod(nameof(FeatureWithDataTableScenarioStep.When_DataTable_Is_Expected)), featureInstance ); var step = new Gherkin.Ast.Step( null, "When", FeatureWithDataTableScenarioStep.Steptext, new Gherkin.Ast.DataTable(new Gherkin.Ast.TableRow[] { new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[] { new Gherkin.Ast.TableCell(null, "First argument"), new Gherkin.Ast.TableCell(null, "Second argument"), new Gherkin.Ast.TableCell(null, "Result"), }), new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[] { new Gherkin.Ast.TableCell(null, "1"), new Gherkin.Ast.TableCell(null, "2"), new Gherkin.Ast.TableCell(null, "3"), }), new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[] { new Gherkin.Ast.TableCell(null, "a"), new Gherkin.Ast.TableCell(null, "b"), new Gherkin.Ast.TableCell(null, "c"), }) })); //act. sut.DigestScenarioStepValues(step); //assert. var digestedText = sut.GetDigestedStepText(); Assert.Equal(FeatureWithDataTableScenarioStep.Steptext, digestedText); }
public void DigestScenarioStepValues_Takes_Value_By_Index(int index) { //arrange. var sut = new PrimitiveTypeArgument(GetParamAt(index), index); var arguments = new dynamic[] { 123, "Ana", new DateTime(2018, 5, 23) }; var argumentsAsString = new string[] { $"{arguments[0]}", $"{arguments[1]}", $"{arguments[2].Month}/{arguments[2].Day}/{arguments[2].Year}" }; var step = new Gherkin.Ast.Step( null, "Then", $@"I should have {argumentsAsString[0]} apples from {argumentsAsString[1]} by {argumentsAsString[2]}", null); //act. sut.DigestScenarioStepValues(argumentsAsString, step.Argument); //assert. Assert.Equal(arguments[index], sut.Value); }
public void DigestScenarioStepValues_Expects_Exact_Number_Of_Groups_Not_Less() { //arrange. var featureInstance = new FeatureForApplyArgumentValues_LessThanNeededGroups(); var sut = StepMethodInfo.FromMethodInfo( featureInstance.GetType().GetMethod(nameof(FeatureForApplyArgumentValues_LessThanNeededGroups.Method_With_Arguments)), featureInstance); var number = 123; var text = "Ana"; var date = new DateTime(2018, 5, 23); var stepText = FeatureForApplyArgumentValues_LessThanNeededGroups.StepMethodText .Replace(@"(\d+)", $"{number}") .Replace(@"(\w+)", $"{text}"); var step = new Gherkin.Ast.Step(null, "Then", stepText, null); //act / assert. Assert.Throws <InvalidOperationException>(() => sut.DigestScenarioStepValues(step)); }