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 scenarioName = "scenario ajshas a"; var docStringContent = @"some content +++ with multi lines --- in it"; var step = CreateGherkinDocument(scenarioName, "Given " + FeatureWithDocStringScenarioStep.StepWithDocStringText + @" " + @""""""" " + docStringContent + @" """"""").Feature.Children.First().Steps.First(); //act. sut.DigestScenarioStepValues(step); //assert. var digestedText = sut.GetDigestedStepText(); Assert.Equal(FeatureWithDocStringScenarioStep.StepWithDocStringText, digestedText); }
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 = CreateGherkinDocument("some scenario 1212", "When " + FeatureWithDataTableScenarioStep.Steptext + Environment.NewLine + @" | First argument | Second argument | Result | | 1 | 2 | 3| | a | b | c | " ).Feature.Children.First().Steps.First(); //act. sut.DigestScenarioStepValues(step); //assert. var digestedText = sut.GetDigestedStepText(); Assert.Equal(FeatureWithDataTableScenarioStep.Steptext, digestedText); }
public async Task Execute_Invokes_All_StepMethods() { //arrange. var featureInstance = new FeatureWithStepMethodsToInvoke(); var sut = new Scenario(new List <StepMethod> { new StepMethod(StepMethodInfo.FromMethodInfo(featureInstance.GetType().GetMethod(nameof(FeatureWithStepMethodsToInvoke.ScenarioStep1)), featureInstance), FeatureWithStepMethodsToInvoke.ScenarioStep1Text), new StepMethod(StepMethodInfo.FromMethodInfo(featureInstance.GetType().GetMethod(nameof(FeatureWithStepMethodsToInvoke.ScenarioStep2)), featureInstance), FeatureWithStepMethodsToInvoke.ScenarioStep2Text), new StepMethod(StepMethodInfo.FromMethodInfo(featureInstance.GetType().GetMethod(nameof(FeatureWithStepMethodsToInvoke.ScenarioStep3)), featureInstance), FeatureWithStepMethodsToInvoke.ScenarioStep3Text), new StepMethod(StepMethodInfo.FromMethodInfo(featureInstance.GetType().GetMethod(nameof(FeatureWithStepMethodsToInvoke.ScenarioStep4)), featureInstance), FeatureWithStepMethodsToInvoke.ScenarioStep4Text) }, featureInstance); var output = new Mock <IScenarioOutput>(); //act. await sut.ExecuteAsync(output.Object); //assert. Assert.NotNull(featureInstance.CallStack); Assert.Equal(4, featureInstance.CallStack.Count); Assert.Equal(nameof(FeatureWithStepMethodsToInvoke.ScenarioStep1), featureInstance.CallStack[0]); output.Verify(o => o.StepPassed("Given " + FeatureWithStepMethodsToInvoke.ScenarioStep1Text), Times.Once); Assert.Equal(nameof(FeatureWithStepMethodsToInvoke.ScenarioStep2), featureInstance.CallStack[1]); output.Verify(o => o.StepPassed("And " + FeatureWithStepMethodsToInvoke.ScenarioStep2Text), Times.Once); Assert.Equal(nameof(FeatureWithStepMethodsToInvoke.ScenarioStep3), featureInstance.CallStack[2]); output.Verify(o => o.StepPassed("When " + FeatureWithStepMethodsToInvoke.ScenarioStep3Text), Times.Once); Assert.Equal(nameof(FeatureWithStepMethodsToInvoke.ScenarioStep4), featureInstance.CallStack[3]); output.Verify(o => o.StepPassed("Then " + FeatureWithStepMethodsToInvoke.ScenarioStep4Text), Times.Once); }
public void DigestScenarioStepValues_Sets_Primitive_Values() { //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 = CreateGherkinDocument("some scenario", "Then " + stepText) .Feature.Children.First().Steps.First(); //act. sut.DigestScenarioStepValues(step); //assert. var digestedText = sut.GetDigestedStepText(); Assert.Equal(stepText, digestedText); }
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 FromMethodInfo_Creates_StepMethodInfo_With_Multiple_Patterns() { //arrange. var featureInstance = new FeatureWithMultipleStepPatterns(); //act. var sut = StepMethodInfo.FromMethodInfo( featureInstance.GetType().GetMethod(nameof(FeatureWithMultipleStepPatterns.Step_With_Multiple_Patterns)), featureInstance); //assert. Assert.NotNull(sut); Assert.Equal(10, sut.ScenarioStepPatterns.Count); AssertPattern(0, PatternKind.Given, "something"); AssertPattern(1, PatternKind.Given, "something else"); AssertPattern(2, PatternKind.And, "something"); AssertPattern(3, PatternKind.And, "something else"); AssertPattern(4, PatternKind.When, "something"); AssertPattern(5, PatternKind.When, "something else"); AssertPattern(6, PatternKind.And, "something"); AssertPattern(7, PatternKind.And, "something else"); AssertPattern(8, PatternKind.But, "something"); AssertPattern(9, PatternKind.But, "something else"); void AssertPattern(int index, PatternKind patternKind, string pattern) { var thePattern = sut.ScenarioStepPatterns[index]; Assert.NotNull(thePattern); Assert.Equal(patternKind, thePattern.Kind); Assert.Equal(pattern, thePattern.Pattern); } }
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); }
public async Task Execute_Invokes_Successfult_StepMethods_And_Skips_The_Rest() { //arrange. var featureInstance = new FeatureWithStepMethodsToInvoke_And_Throwing(); var sut = new Scenario(new List <StepMethod> { new StepMethod(StepMethodInfo.FromMethodInfo(featureInstance.GetType().GetMethod(nameof(FeatureWithStepMethodsToInvoke_And_Throwing.ScenarioStep1)), featureInstance), FeatureWithStepMethodsToInvoke_And_Throwing.ScenarioStep1Text), new StepMethod(StepMethodInfo.FromMethodInfo(featureInstance.GetType().GetMethod(nameof(FeatureWithStepMethodsToInvoke_And_Throwing.ScenarioStep2)), featureInstance), FeatureWithStepMethodsToInvoke_And_Throwing.ScenarioStep2Text), new StepMethod(StepMethodInfo.FromMethodInfo(featureInstance.GetType().GetMethod(nameof(FeatureWithStepMethodsToInvoke_And_Throwing.ScenarioStep3)), featureInstance), FeatureWithStepMethodsToInvoke_And_Throwing.ScenarioStep3Text), new StepMethod(StepMethodInfo.FromMethodInfo(featureInstance.GetType().GetMethod(nameof(FeatureWithStepMethodsToInvoke_And_Throwing.ScenarioStep4)), featureInstance), FeatureWithStepMethodsToInvoke_And_Throwing.ScenarioStep4Text) }, featureInstance); var output = new Mock <IScenarioOutput>(); //act. var exception = await Assert.ThrowsAsync <TargetInvocationException>(async() => await sut.ExecuteAsync(output.Object)); Assert.IsType <InvalidOperationException>(exception.InnerException); //assert. Assert.NotNull(featureInstance.CallStack); Assert.Equal(2, featureInstance.CallStack.Count); Assert.Equal(nameof(FeatureWithStepMethodsToInvoke_And_Throwing.ScenarioStep1), featureInstance.CallStack[0]); output.Verify(o => o.StepPassed("Given " + FeatureWithStepMethodsToInvoke_And_Throwing.ScenarioStep1Text), Times.Once); Assert.Equal(nameof(FeatureWithStepMethodsToInvoke_And_Throwing.ScenarioStep2), featureInstance.CallStack[1]); output.Verify(o => o.StepFailed("And " + FeatureWithStepMethodsToInvoke_And_Throwing.ScenarioStep2Text), Times.Once); output.Verify(o => o.StepSkipped("When " + FeatureWithStepMethodsToInvoke_And_Throwing.ScenarioStep3Text), Times.Once); output.Verify(o => o.StepSkipped("Then " + FeatureWithStepMethodsToInvoke_And_Throwing.ScenarioStep4Text), Times.Once); }
public void FromMethodInfo_DoesNotAllow_AsyncAvoid_Steps() { //arrange. var featureInstance = new FeatureWithAsyncVoidStep(); var methodInfo = typeof(FeatureWithAsyncVoidStep).GetMethod(nameof(FeatureWithAsyncVoidStep.StepWithAsyncVoid)); //act / assert. Assert.Throws <InvalidOperationException>(() => StepMethodInfo.FromMethodInfo(methodInfo, featureInstance)); }
public void GetDigestedStepText_Throws_Error_If_Not_Yet_Digested() { //arrange. var featureInstance = new Feature_For_GetDigestedStepTextTest(); var sut = StepMethodInfo.FromMethodInfo(featureInstance.GetType().GetMethod(nameof(Feature_For_GetDigestedStepTextTest.When_Something_Method)), featureInstance); //act / assert. Assert.Throws <InvalidOperationException>(() => sut.GetDigestedStepText()); }
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.Equal(StepMethodKind.When, sut.Kind); Assert.Equal(FeatureForCtorTest.WhenStepText, sut.Pattern); }
public async Task Execute_Invokes_StepMethod() { //arrange. var featureInstance = new FeatureForExecuteTest(); var sut = StepMethodInfo.FromMethodInfo(featureInstance.GetType().GetMethod(nameof(FeatureForExecuteTest.Call_This_Method)), featureInstance); //act. await sut.ExecuteAsync(); //assert. Assert.True(featureInstance.Called); }
public void FromStepMethodInfo_Throws_When_Method_Cannot_Match_Pattern() { //arrange. var featureInstance = new Feature_For_FromStepMethodInfo(); var stepMethodInfo = StepMethodInfo.FromMethodInfo( featureInstance.GetType().GetMethod(nameof(Feature_For_FromStepMethodInfo.Step_With_Multiple_Patterns)), featureInstance ); //act / assert. Assert.Throws <InvalidOperationException>(() => StepMethod.FromStepMethodInfo(stepMethodInfo, new Gherkin.Ast.Step(null, "Given", "something else NOT", null))); }
public void Ctor_Initializes_Properties() { //arrange. var featureInstance = new Feature_For_Ctor_Test(); var stepMethodInfo = StepMethodInfo.FromMethodInfo(featureInstance.GetType().GetMethod(nameof(Feature_For_Ctor_Test.But_This_Method)), featureInstance); var stepText = "some step text"; var sut = new StepMethod(stepMethodInfo, stepText); //act. Assert.Same(stepText, sut.StepText); Assert.Equal(stepMethodInfo.Kind, sut.Kind); }
public void IsSameAs_Identifies_Similar_Instances() { //arrange. var featureInstance = new FeatureForCtorTest(); var sut = StepMethodInfo.FromMethodInfo(featureInstance.GetType().GetMethod(nameof(FeatureForCtorTest.When_Something)), featureInstance); var clone = StepMethodInfo.FromMethodInfo(featureInstance.GetType().GetMethod(nameof(FeatureForCtorTest.When_Something)), featureInstance); //act. var same = sut.IsSameAs(clone) && clone.IsSameAs(sut); //assert. Assert.True(same); }
public async Task ExecuteAsync_Executes_StepMethodInfo() { //arrange. var featureInstance = new Feature_For_ExecuteAsync_Test(); var stepMethodInfo = StepMethodInfo.FromMethodInfo(featureInstance.GetType().GetMethod(nameof(Feature_For_ExecuteAsync_Test.But_This_Method)), featureInstance); var sut = new StepMethod(stepMethodInfo, "some step text"); //act. await sut.ExecuteAsync(); //assert. Assert.True(featureInstance.Called); }
public void Clone_Creates_Similar_Instance() { //arrange. var featureInstance = new FeatureForCtorTest(); var sut = StepMethodInfo.FromMethodInfo(featureInstance.GetType().GetMethod(nameof(FeatureForCtorTest.When_Something)), featureInstance); //act. var clone = sut.Clone(); //assert. Assert.NotNull(clone); Assert.True(clone.IsSameAs(sut)); }
public async Task ExecuteAsync_Executes_StepMethodInfo() { //arrange. var featureInstance = new Feature_For_ExecuteAsync_Test(); var stepMethodInfo = StepMethodInfo.FromMethodInfo(featureInstance.GetType().GetMethod(nameof(Feature_For_ExecuteAsync_Test.But_This_Method)), featureInstance); var sut = StepMethod.FromStepMethodInfo(stepMethodInfo, new Gherkin.Ast.Step(null, "But", "what 123 exactly", null)); //act. await sut.ExecuteAsync(); //assert. Assert.True(featureInstance.Called); Assert.Equal(123, featureInstance.Value); }
public void FromMethodInfo_Creates_StepMethodInfo_With_DocString() { //arrange. var featureInstance = new FeatureWithDocStringScenarioStep(); //act. var sut = StepMethodInfo.FromMethodInfo( featureInstance.GetType().GetMethod(nameof(FeatureWithDocStringScenarioStep.Step_With_DocString_Argument)), featureInstance ); //assert. Assert.NotNull(sut); }
public void FromMethodInfo_Creates_StepMethodInfo_With_DataTable() { //arrange. var featureInstance = new FeatureWithDataTableScenarioStep(); //act. var sut = StepMethodInfo.FromMethodInfo( featureInstance.GetType().GetMethod(nameof(FeatureWithDataTableScenarioStep.When_DataTable_Is_Expected)), featureInstance ); //assert. Assert.NotNull(sut); }
public void Match_IsNegative_For_Different_Step() { //arrange. var featureInstance = new FeatureForMatch(); var sut = StepMethodInfo.FromMethodInfo( typeof(FeatureForMatch).GetMethod(nameof(FeatureForMatch.Method1)), featureInstance); //act. var match = sut.Matches(new Gherkin.Ast.Step(null, "When", "this does not matches", null)); //assert. Assert.False(match); }
public void Match_IsPositive_For_Corresponding_Step(string keyword) { //arrange. var featureInstance = new FeatureForMatch(); var sut = StepMethodInfo.FromMethodInfo( typeof(FeatureForMatch).GetMethod(nameof(FeatureForMatch.Method1)), featureInstance); //act. var match = sut.Matches(new Gherkin.Ast.Step(null, keyword, "this matches", null)); //assert. Assert.True(match); }
public void GetMatchingPattern_Finds_Nothing_When_No_Match() { //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, "When", "this does not matches", null)); //assert. Assert.Null(match); }
public void GetMethodName_Returns_Wrapped_Method_Name() { //arrange. var featureInstance = new FeatureForMethodName(); var sut = StepMethodInfo.FromMethodInfo( featureInstance.GetType().GetMethod(nameof(FeatureForMethodName.Step_Name_Must_Be_This)), featureInstance ); //act. var methodName = sut.GetMethodName(); //assert. Assert.Equal(nameof(FeatureForMethodName.Step_Name_Must_Be_This), methodName); }
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].OriginalPattern); }
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.Pattern); }
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)); }