private static ScenarioStep ConvertToCompatibleStep(SpecFlowStep step) { ScenarioStep result = null; if (step.StepKeyword == StepKeyword.Given) result = new Given {StepKeyword = step.StepKeyword }; else if (step.StepKeyword == StepKeyword.When) result = new When {StepKeyword = step.StepKeyword }; else if (step.StepKeyword == StepKeyword.Then) result = new Then {StepKeyword = step.StepKeyword }; else if (step.StepKeyword == StepKeyword.And) result = new And { StepKeyword = step.StepKeyword }; else if (step.StepKeyword == StepKeyword.But) result = new But {StepKeyword = step.StepKeyword }; if (result == null) throw new NotSupportedException(); result.Keyword = step.Keyword; result.Text = step.Text; result.ScenarioBlock = step.ScenarioBlock; result.MultiLineTextArgument = step.Argument is global::Gherkin.Ast.DocString ? ((global::Gherkin.Ast.DocString) step.Argument).Content : null; result.TableArg = step.Argument is global::Gherkin.Ast.DataTable ? ConvertToCompatibleTable(((global::Gherkin.Ast.DataTable) step.Argument).Rows) : null; result.FilePosition = ConvertToCompatibleFilePosition(step.Location); return result; }
private void AddBackgroundLineTest(SpecFlowFeature feature, SpecFlowStep step) { // Test method var testMethod = new CodeMemberMethod { Attributes = MemberAttributes.Public, Name = NamingHelper.GetTestName(feature, step) }; testMethod.Statements.Add(new CodeMethodInvokeExpression( new CodeMethodReferenceExpression( new CodeThisReferenceExpression(), NamingHelper.TestWrapperMethodName), new CodeDelegateCreateExpression(new CodeTypeReference(typeof(Action)), new CodeThisReferenceExpression(), NamingHelper.GetTestStepsName(feature, step)), new CodePrimitiveExpression(step.Location.Line))); _context.UnitTestGeneratorProvider.SetTestMethod(_context, testMethod, NamingHelper.GetTestName(feature, step)); _context.TestClass.Members.Add(testMethod); // Test steps var stepsMethod = new CodeMemberMethod { Attributes = MemberAttributes.Private, Name = NamingHelper.GetTestStepsName(feature, step) }; AddActionStatementsForBackgroundStep(feature, stepsMethod.Statements, step); _context.TestClass.Members.Add(stepsMethod); }
public static string GetTestName(SpecFlowFeature feature, SpecFlowStep step) { int digitCountInTotalLines = feature.ScenarioDefinitions.Last().Steps.Last().Location.Line.ToString().Length; string lineNumberLeadingZeros = new string('0', digitCountInTotalLines - step.Location.Line.ToString().Length); return($"TestLine{lineNumberLeadingZeros}{step.Location.Line}{step.Text.ToIdentifier()}"); }
private static ScenarioStep ConvertToCompatibleStep(SpecFlowStep step) { ScenarioStep result = null; if (step.StepKeyword == StepKeyword.Given) { result = new Given { StepKeyword = step.StepKeyword } } ; else if (step.StepKeyword == StepKeyword.When) { result = new When { StepKeyword = step.StepKeyword } } ; else if (step.StepKeyword == StepKeyword.Then) { result = new Then { StepKeyword = step.StepKeyword } } ; else if (step.StepKeyword == StepKeyword.And) { result = new And { StepKeyword = step.StepKeyword } } ; else if (step.StepKeyword == StepKeyword.But) { result = new But { StepKeyword = step.StepKeyword } } ; if (result == null) { throw new NotSupportedException(); } result.Keyword = step.Keyword; result.Text = step.Text; result.ScenarioBlock = step.ScenarioBlock; result.MultiLineTextArgument = step.Argument is global::Gherkin.Ast.DocString ? ((global::Gherkin.Ast.DocString)step.Argument).Content : null; result.TableArg = step.Argument is global::Gherkin.Ast.DataTable ? ConvertToCompatibleTable(((global::Gherkin.Ast.DataTable)step.Argument).Rows) : null; result.FilePosition = ConvertToCompatibleFilePosition(step.Location); return(result); }
private void FixStepKeyWordForScenarioStep(SpecFlowFeature feature, SpecFlowStep executionStep, SpecFlowStep testingStep, out StepKeyword stepKeyWord, out string keyWord) { stepKeyWord = executionStep.StepKeyword; keyWord = executionStep.Keyword; if (executionStep.StepKeyword == StepKeyword.And) { int scenarioStepIndex = feature.Background.Steps.ToList().IndexOf(executionStep); int stepIndex = feature.Background.Steps.ToList().IndexOf(testingStep); if (scenarioStepIndex == stepIndex + 1) { stepKeyWord = testingStep.StepKeyword; keyWord = testingStep.Keyword; } } }
private ReportStep CloneTo(SpecFlowStep step, string currentBlock, string sampleText) { ReportStep newStep = null; if (currentBlock == "When") { newStep = new ReportStep(step.Location, step.Keyword, sampleText, ConvertArgument(step.Argument), step.StepKeyword, Parser.ScenarioBlock.When); } else if (currentBlock == "Then") { newStep = new ReportStep(step.Location, step.Keyword, sampleText, ConvertArgument(step.Argument), step.StepKeyword, Parser.ScenarioBlock.Then); } else // Given or empty { newStep = new ReportStep(step.Location, step.Keyword, sampleText, ConvertArgument(step.Argument), step.StepKeyword, Parser.ScenarioBlock.Given); } Debug.Assert(newStep != null); return(newStep); }
public static Scenario CreateScenario(ScenarioOutline scenarioOutline, Examples example, TableRow exampleRow) { var parameters = GetScenarioOutlineParameters(example, exampleRow); var steps = new List <Step>(); var tags = new List <Tag>(); tags.AddRange(scenarioOutline.Tags); tags.AddRange(example.Tags); foreach (var scenarioOutlineStep in scenarioOutline.Steps.Cast <SpecFlowStep>()) { string stepText = Interpolate(scenarioOutlineStep.Text, parameters); var step = new SpecFlowStep(scenarioOutlineStep.Location, scenarioOutlineStep.Keyword, stepText, CreatePickleArguments(scenarioOutlineStep.Argument, parameters), scenarioOutlineStep.StepKeyword, scenarioOutlineStep.ScenarioBlock); steps.Add(step); } return(new Scenario(tags.ToArray(), scenarioOutline.Location, scenarioOutline.Keyword, scenarioOutline.Name, scenarioOutline.Description, steps.ToArray())); }
private void AddActionStatementsForScenarioStep( SpecFlowFeature feature, CodeStatementCollection statements, Scenario scenario, SpecFlowStep step, ParameterSubstitution paramToIdentifier) { IEnumerable <TableRow> rows = new List <TableRow> { null }; if (scenario is ScenarioOutline scenarioOutline) { rows = scenario.Examples.SelectMany(exampleSet => exampleSet.TableBody); } foreach (TableRow row in rows) { if (feature.Background != null) { foreach (SpecFlowStep backgroundStep in feature.Background.Steps) { GenerateStep(statements, backgroundStep, null, null, backgroundStep.StepKeyword, backgroundStep.Keyword); } } foreach (SpecFlowStep scenarioStep in scenario.Steps.Where(x => x != step)) { FixStepKeyWordForScenarioStep(scenario, scenarioStep, step, out StepKeyword stepKeyWord, out string keyWord); GenerateStep(statements, scenarioStep, paramToIdentifier, row, stepKeyWord, keyWord); } } AddLineDirectiveHidden(statements); }
private void ExecuteStep(SpecFlowStep step) { var docStringArg = step.Argument as DocString; string docString = docStringArg?.Content; var dataTableArg = step.Argument as DataTable; Table dataTable = null; if (dataTableArg != null && dataTableArg.Rows.Any()) { dataTable = new Table(dataTableArg.Rows.First().Cells.Select(c => c.Value).ToArray()); foreach (var row in dataTableArg.Rows.Skip(1)) { dataTable.AddRow(row.Cells.Select(c => c.Value).ToArray()); } } switch (step.StepKeyword) { case StepKeyword.Given: testRunner.Given(step.Text, docString, dataTable, step.Keyword); break; case StepKeyword.When: testRunner.When(step.Text, docString, dataTable, step.Keyword); break; case StepKeyword.Then: testRunner.Then(step.Text, docString, dataTable, step.Keyword); break; case StepKeyword.And: testRunner.And(step.Text, docString, dataTable, step.Keyword); break; case StepKeyword.But: testRunner.But(step.Text, docString, dataTable, step.Keyword); break; } }
private SpecFlowStep Clone(SpecFlowStep step, StepArgument stepArgument) { return(new SpecFlowStep(step.Location, step.Keyword, step.Text, stepArgument, step.StepKeyword, step.ScenarioBlock)); }
public static string GetTestStepsName(SpecFlowFeature feature, SpecFlowStep step) { return(GetTestName(feature, step) + "Steps"); }
private SpecFlowStep Clone(SpecFlowStep step, StepArgument stepArgument, Dictionary <string, string> paramSubst) { return(new SpecFlowStep(step.Location, step.Keyword, GetReplacedText(step.Text, paramSubst), stepArgument, step.StepKeyword, step.ScenarioBlock)); }