public void Ctor_Initializes_Properties() { //arrange. var featureInstance = new FeatureForCtorTest(); //act. var sut = StepMethodInfo.FromMethodInfo(featureInstance.GetType().GetMethod(nameof(FeatureForCtorTest.When_Something)), featureInstance); //assert. Assert.NotNull(sut); Assert.NotNull(sut.ScenarioStepPatterns); Assert.Single(sut.ScenarioStepPatterns); Assert.Equal(PatternKind.When, sut.ScenarioStepPatterns[0].Kind); Assert.Equal(FeatureForCtorTest.WhenStepText, sut.ScenarioStepPatterns[0].Pattern); }
public void GetMatchingPattern_Finds_Match_For_Step(string keyword) { //arrange. var featureInstance = new FeatureForMatch(); var sut = StepMethodInfo.FromMethodInfo( typeof(FeatureForMatch).GetMethod(nameof(FeatureForMatch.Method1)), featureInstance); //act. var match = sut.GetMatchingPattern(new Gherkin.Ast.Step(null, keyword, "this matches", null)); //assert. Assert.NotNull(match); Assert.Equal(PatternKind.When, match.Kind); Assert.Equal("this matches", match.OriginalPattern); }
public void FromStepMethodInfo_Creates_Instance() { //arrange. var featureInstance = new Feature_For_FromStepMethodInfo(); var stepMethodInfo = StepMethodInfo.FromMethodInfo( featureInstance.GetType().GetMethod(nameof(Feature_For_FromStepMethodInfo.Step_With_Multiple_Patterns)), featureInstance ); //act. var sut = StepMethod.FromStepMethodInfo(stepMethodInfo, new Gherkin.Ast.Step(null, "Given", "something 123 else", null)); //assert. Assert.NotNull(sut); Assert.Equal(stepMethodInfo.ScenarioStepPatterns[1].Kind, sut.Kind); Assert.Equal(stepMethodInfo.ScenarioStepPatterns[1].Pattern, sut.Pattern); Assert.Equal("something 123 else", sut.StepText); }
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_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)); }