How to use TableRow method of Gherkin.Ast.TableRow class

Best Gherkin-dotnet code snippet using Gherkin.Ast.TableRow.TableRow

ScenarioOutlineExecutorTests.cs

Source:ScenarioOutlineExecutorTests.cs Github

copy

Full Screen

...349 var output = new Mock<ITestOutputHelper>();350 featureInstance.InternalOutput = output.Object;351 _featureFileRepository.Setup(r => r.GetByFilePath($"{nameof(FeatureWithDataTableScenarioStep)}.feature"))352 .Returns(new FeatureFile(FeatureWithDataTableScenarioStep.CreateGherkinDocument(scenarioName,353 new Gherkin.Ast.DataTable(new Gherkin.Ast.TableRow[]354 {355 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]356 {357 new Gherkin.Ast.TableCell(null, "First argument"),358 new Gherkin.Ast.TableCell(null, "Second argument"),359 new Gherkin.Ast.TableCell(null, "Result"),360 }),361 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]362 {363 new Gherkin.Ast.TableCell(null, "1"),364 new Gherkin.Ast.TableCell(null, "2"),365 new Gherkin.Ast.TableCell(null, "3"),366 }),367 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]368 {369 new Gherkin.Ast.TableCell(null, "a"),370 new Gherkin.Ast.TableCell(null, "b"),371 new Gherkin.Ast.TableCell(null, "c"),372 })373 }))))374 .Verifiable();375 //act.376 await _sut.ExecuteScenarioOutlineAsync(featureInstance, scenarioName, exampleName, exampleRowIndex);377 //assert.378 _featureFileRepository.Verify();379 Assert.NotNull(featureInstance.ReceivedDataTable);380 Assert.Equal(3, featureInstance.ReceivedDataTable.Rows.Count());381 AssertDataTableCell(0, 0, "First argument");382 AssertDataTableCell(0, 1, "Second argument");383 AssertDataTableCell(0, 2, "Result");384 AssertDataTableCell(1, 0, "1");385 AssertDataTableCell(1, 1, "2");386 AssertDataTableCell(1, 2, "3");387 AssertDataTableCell(2, 0, "a");388 AssertDataTableCell(2, 1, "b");389 AssertDataTableCell(2, 2, "c");390 void AssertDataTableCell(int rowIndex, int cellIndex, string value)391 {392 Assert.True(featureInstance.ReceivedDataTable.Rows.Count() > rowIndex);393 Assert.NotNull(featureInstance.ReceivedDataTable.Rows.ElementAt(rowIndex));394 Assert.True(featureInstance.ReceivedDataTable.Rows.ElementAt(rowIndex).Cells.Count() > cellIndex);395 Assert.NotNull(featureInstance.ReceivedDataTable.Rows.ElementAt(rowIndex).Cells.ElementAt(cellIndex));396 Assert.Equal("First argument", featureInstance.ReceivedDataTable.Rows.ElementAt(0).Cells.ElementAt(0).Value);397 }398 }399 private sealed class FeatureWithDataTableScenarioStep : Feature400 {401 public Gherkin.Ast.DataTable ReceivedDataTable { get; private set; }402 public const string Steptext = @"Step text 1212121";403 [Given(Steptext)]404 public void When_DataTable_Is_Expected(Gherkin.Ast.DataTable dataTable)405 {406 ReceivedDataTable = dataTable;407 }408 public static Gherkin.Ast.GherkinDocument CreateGherkinDocument(409 string outlineName,410 Gherkin.Ast.StepArgument stepArgument = null)411 {412 return new Gherkin.Ast.GherkinDocument(413 new Gherkin.Ast.Feature(new Gherkin.Ast.Tag[0], null, null, null, null, null, new Gherkin.Ast.ScenarioDefinition[]414 {415 new Gherkin.Ast.ScenarioOutline(416 new Gherkin.Ast.Tag[0],417 null,418 null,419 outlineName,420 null,421 new Gherkin.Ast.Step[]422 {423 new Gherkin.Ast.Step(null, "Given", Steptext, stepArgument)424 },425 new Gherkin.Ast.Examples[]426 {427 new Gherkin.Ast.Examples(null, null, null, "", null,428 new Gherkin.Ast.TableRow(null,429 new Gherkin.Ast.TableCell[]430 {431 new Gherkin.Ast.TableCell(null, "a"),432 new Gherkin.Ast.TableCell(null, "b"),433 new Gherkin.Ast.TableCell(null, "sum"),434 }),435 new Gherkin.Ast.TableRow[]436 {437 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]438 {439 new Gherkin.Ast.TableCell(null, "0"),440 new Gherkin.Ast.TableCell(null, "1"),441 new Gherkin.Ast.TableCell(null, "1")442 }),443 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]444 {445 new Gherkin.Ast.TableCell(null, "1"),446 new Gherkin.Ast.TableCell(null, "9"),447 new Gherkin.Ast.TableCell(null, "10")448 })449 }),450 new Gherkin.Ast.Examples(null, null, null, "of bigger numbers", null,451 new Gherkin.Ast.TableRow(null,452 new Gherkin.Ast.TableCell[]453 {454 new Gherkin.Ast.TableCell(null, "a"),455 new Gherkin.Ast.TableCell(null, "b"),456 new Gherkin.Ast.TableCell(null, "sum"),457 }),458 new Gherkin.Ast.TableRow[]459 {460 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]461 {462 new Gherkin.Ast.TableCell(null, "99"),463 new Gherkin.Ast.TableCell(null, "1"),464 new Gherkin.Ast.TableCell(null, "100")465 }),466 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]467 {468 new Gherkin.Ast.TableCell(null, "100"),469 new Gherkin.Ast.TableCell(null, "200"),470 new Gherkin.Ast.TableCell(null, "300")471 })472 }),473 new Gherkin.Ast.Examples(null, null, null, "of large numbers", null,474 new Gherkin.Ast.TableRow(null,475 new Gherkin.Ast.TableCell[]476 {477 new Gherkin.Ast.TableCell(null, "a"),478 new Gherkin.Ast.TableCell(null, "b"),479 new Gherkin.Ast.TableCell(null, "sum"),480 }),481 new Gherkin.Ast.TableRow[]482 {483 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]484 {485 new Gherkin.Ast.TableCell(null, "999"),486 new Gherkin.Ast.TableCell(null, "1"),487 new Gherkin.Ast.TableCell(null, "1000")488 }),489 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]490 {491 new Gherkin.Ast.TableCell(null, "9999"),492 new Gherkin.Ast.TableCell(null, "1"),493 new Gherkin.Ast.TableCell(null, "10000")494 })495 })496 })497 }),498 new Gherkin.Ast.Comment[0]);499 }500 }501 [Theory]502 [InlineData("", 0)]503 [InlineData("", 1)]504 [InlineData("of bigger numbers", 0)]505 [InlineData("of bigger numbers", 1)]506 [InlineData("of large numbers", 0)]507 [InlineData("of large numbers", 1)]508 public async Task ExecuteScenarioOutlineAsync_Executes_ScenarioStep_With_DocString(509 string exampleName,510 int exampleRowIndex)511 {512 //arrange.513 var scenarioName = "scenario123";514 var featureInstance = new FeatureWithDocStringScenarioStep();515 var output = new Mock<ITestOutputHelper>();516 featureInstance.InternalOutput = output.Object;517 var docStringContent = "some content" + Environment.NewLine +518"+++" + Environment.NewLine +519"with multi lines" + Environment.NewLine +520"---" + Environment.NewLine +521"in it";522 _featureFileRepository.Setup(r => r.GetByFilePath($"{nameof(FeatureWithDocStringScenarioStep)}.feature"))523 .Returns(new FeatureFile(FeatureWithDocStringScenarioStep.CreateGherkinDocument(scenarioName,524 new Gherkin.Ast.DocString(null, null, docStringContent))))525 .Verifiable();526 //act.527 await _sut.ExecuteScenarioOutlineAsync(featureInstance, scenarioName, exampleName, exampleRowIndex);528 //assert.529 _featureFileRepository.Verify();530 Assert.NotNull(featureInstance.ReceivedDocString);531 Assert.Equal(docStringContent, featureInstance.ReceivedDocString.Content);532 }533 private sealed class FeatureWithDocStringScenarioStep : Feature534 {535 public Gherkin.Ast.DocString ReceivedDocString { get; private set; }536 public const string Steptext = @"Step text 1212121";537 [Given(Steptext)]538 public void When_DocString_Is_Expected(Gherkin.Ast.DocString docString)539 {540 ReceivedDocString = docString;541 }542 public static Gherkin.Ast.GherkinDocument CreateGherkinDocument(543 string outlineName,544 Gherkin.Ast.StepArgument stepArgument = null)545 {546 return new Gherkin.Ast.GherkinDocument(547 new Gherkin.Ast.Feature(new Gherkin.Ast.Tag[0], null, null, null, null, null, new Gherkin.Ast.ScenarioDefinition[]548 {549 new Gherkin.Ast.ScenarioOutline(550 new Gherkin.Ast.Tag[0],551 null,552 null,553 outlineName,554 null,555 new Gherkin.Ast.Step[]556 {557 new Gherkin.Ast.Step(null, "Given", Steptext, stepArgument)558 },559 new Gherkin.Ast.Examples[]560 {561 new Gherkin.Ast.Examples(null, null, null, "", null,562 new Gherkin.Ast.TableRow(null,563 new Gherkin.Ast.TableCell[]564 {565 new Gherkin.Ast.TableCell(null, "a"),566 new Gherkin.Ast.TableCell(null, "b"),567 new Gherkin.Ast.TableCell(null, "sum"),568 }),569 new Gherkin.Ast.TableRow[]570 {571 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]572 {573 new Gherkin.Ast.TableCell(null, "0"),574 new Gherkin.Ast.TableCell(null, "1"),575 new Gherkin.Ast.TableCell(null, "1")576 }),577 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]578 {579 new Gherkin.Ast.TableCell(null, "1"),580 new Gherkin.Ast.TableCell(null, "9"),581 new Gherkin.Ast.TableCell(null, "10")582 })583 }),584 new Gherkin.Ast.Examples(null, null, null, "of bigger numbers", null,585 new Gherkin.Ast.TableRow(null,586 new Gherkin.Ast.TableCell[]587 {588 new Gherkin.Ast.TableCell(null, "a"),589 new Gherkin.Ast.TableCell(null, "b"),590 new Gherkin.Ast.TableCell(null, "sum"),591 }),592 new Gherkin.Ast.TableRow[]593 {594 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]595 {596 new Gherkin.Ast.TableCell(null, "99"),597 new Gherkin.Ast.TableCell(null, "1"),598 new Gherkin.Ast.TableCell(null, "100")599 }),600 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]601 {602 new Gherkin.Ast.TableCell(null, "100"),603 new Gherkin.Ast.TableCell(null, "200"),604 new Gherkin.Ast.TableCell(null, "300")605 })606 }),607 new Gherkin.Ast.Examples(null, null, null, "of large numbers", null,608 new Gherkin.Ast.TableRow(null,609 new Gherkin.Ast.TableCell[]610 {611 new Gherkin.Ast.TableCell(null, "a"),612 new Gherkin.Ast.TableCell(null, "b"),613 new Gherkin.Ast.TableCell(null, "sum"),614 }),615 new Gherkin.Ast.TableRow[]616 {617 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]618 {619 new Gherkin.Ast.TableCell(null, "999"),620 new Gherkin.Ast.TableCell(null, "1"),621 new Gherkin.Ast.TableCell(null, "1000")622 }),623 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]624 {625 new Gherkin.Ast.TableCell(null, "9999"),626 new Gherkin.Ast.TableCell(null, "1"),627 new Gherkin.Ast.TableCell(null, "10000")628 })629 })630 })631 }),632 new Gherkin.Ast.Comment[0]);633 }634 }635 }636}...

Full Screen

Full Screen

AstBuilder.cs

Source:AstBuilder.cs Github

copy

Full Screen

...74 return CreateDocString(GetLocation(separatorToken), contentType, content, node);75 }76 case RuleType.DataTable:77 {78 var rows = GetTableRows(node);79 return CreateDataTable(rows, node);80 }81 case RuleType.Background:82 {83 var backgroundLine = node.GetToken(TokenType.BackgroundLine);84 var description = GetDescription(node);85 var steps = GetSteps(node);86 return CreateBackground(GetLocation(backgroundLine), backgroundLine.MatchedKeyword, backgroundLine.MatchedText, description, steps, node);87 }88 case RuleType.ScenarioDefinition:89 {90 var tags = GetTags(node);9192 var scenarioNode = node.GetSingle<AstNode>(RuleType.Scenario);93 var scenarioLine = scenarioNode.GetToken(TokenType.ScenarioLine);9495 var description = GetDescription(scenarioNode);96 var steps = GetSteps(scenarioNode);97 var examples = scenarioNode.GetItems<Examples>(RuleType.ExamplesDefinition).ToArray();98 return CreateScenario(tags, GetLocation(scenarioLine), scenarioLine.MatchedKeyword, scenarioLine.MatchedText, description, steps, examples, node);99 }100 case RuleType.ExamplesDefinition:101 {102 var tags = GetTags(node);103 var examplesNode = node.GetSingle<AstNode>(RuleType.Examples);104 var examplesLine = examplesNode.GetToken(TokenType.ExamplesLine);105 var description = GetDescription(examplesNode);106107 var allRows = examplesNode.GetSingle<TableRow[]>(RuleType.ExamplesTable);108 var header = allRows != null ? allRows.First() : null;109 var rows = allRows != null ? allRows.Skip(1).ToArray() : null;110 return CreateExamples(tags, GetLocation(examplesLine), examplesLine.MatchedKeyword, examplesLine.MatchedText, description, header, rows, node);111 }112 case RuleType.ExamplesTable:113 {114 return GetTableRows(node);115 }116 case RuleType.Description:117 {118 var lineTokens = node.GetTokens(TokenType.Other);119120 // Trim trailing empty lines121 lineTokens = lineTokens.Reverse().SkipWhile(t => string.IsNullOrWhiteSpace(t.MatchedText)).Reverse();122123 return string.Join(Environment.NewLine, lineTokens.Select(lt => lt.MatchedText));124 }125 case RuleType.Feature:126 {127 var header = node.GetSingle<AstNode>(RuleType.FeatureHeader);128 if(header == null) return null;129 var tags = GetTags(header);130 var featureLine = header.GetToken(TokenType.FeatureLine);131 if(featureLine == null) return null;132 var children = new List<IHasLocation> ();133 var background = node.GetSingle<Background>(RuleType.Background);134 if (background != null) 135 {136 children.Add (background);137 }138 var childrenEnumerable = children.Concat(node.GetItems<IHasLocation>(RuleType.ScenarioDefinition))139 .Concat(node.GetItems<IHasLocation>(RuleType.Rule));140 var description = GetDescription(header);141 if(featureLine.MatchedGherkinDialect == null) return null;142 var language = featureLine.MatchedGherkinDialect.Language;143144 return CreateFeature(tags, GetLocation(featureLine), language, featureLine.MatchedKeyword, featureLine.MatchedText, description, childrenEnumerable.ToArray(), node);145 }146 case RuleType.Rule:147 {148 var header = node.GetSingle<AstNode>(RuleType.RuleHeader);149 if (header == null) return null;150 var ruleLine = header.GetToken(TokenType.RuleLine);151 if (ruleLine == null) return null;152 var children = new List<IHasLocation>();153 var background = node.GetSingle<Background>(RuleType.Background);154 if (background != null)155 {156 children.Add(background);157 }158 var childrenEnumerable = children.Concat(node.GetItems<IHasLocation>(RuleType.ScenarioDefinition));159 var description = GetDescription(header);160 if (ruleLine.MatchedGherkinDialect == null) return null;161 var language = ruleLine.MatchedGherkinDialect.Language;162163 return CreateRule(GetLocation(ruleLine), ruleLine.MatchedKeyword, ruleLine.MatchedText, description, childrenEnumerable.ToArray(), node);164 }165 case RuleType.GherkinDocument:166 {167 var feature = node.GetSingle<Feature>(RuleType.Feature);168169 return CreateGherkinDocument(feature, comments.ToArray(), node);170 }171 }172173 return node;174 }175176 protected virtual Background CreateBackground(Location location, string keyword, string name, string description, Step[] steps, AstNode node)177 {178 return new Background(location, keyword, name, description, steps);179 }180181 protected virtual DataTable CreateDataTable(TableRow[] rows, AstNode node)182 {183 return new DataTable(rows);184 }185186 protected virtual Comment CreateComment(Location location, string text)187 {188 return new Comment(location, text);189 }190191 protected virtual Examples CreateExamples(Tag[] tags, Location location, string keyword, string name, string description, TableRow header, TableRow[] body, AstNode node)192 {193 return new Examples(tags, location, keyword, name, description, header, body);194 }195196 protected virtual Scenario CreateScenario(Tag[] tags, Location location, string keyword, string name, string description, Step[] steps, Examples[] examples, AstNode node)197 {198 return new Scenario(tags, location, keyword, name, description, steps, examples);199 }200201 protected virtual DocString CreateDocString(Location location, string contentType, string content, AstNode node)202 {203 return new DocString(location, contentType, content);204 }205206 protected virtual Step CreateStep(Location location, string keyword, string text, StepArgument argument, AstNode node)207 {208 return new Step(location, keyword, text, argument);209 }210211 protected virtual GherkinDocument CreateGherkinDocument(Feature feature, Comment[] gherkinDocumentComments, AstNode node) {212 return new GherkinDocument(feature, gherkinDocumentComments);213 }214215 protected virtual Feature CreateFeature(Tag[] tags, Location location, string language, string keyword, string name, string description, IHasLocation[] children, AstNode node)216 {217 return new Feature(tags, location, language, keyword, name, description, children);218 }219220 protected virtual Rule CreateRule(Location location, string keyword, string name, string description, IHasLocation[] children, AstNode node)221 {222 return new Rule(location, keyword, name, description, children);223 }224225 protected virtual Tag CreateTag(Location location, string name, AstNode node)226 {227 return new Tag(location, name);228 }229230 protected virtual Location CreateLocation(int line, int column)231 {232 return new Location(line, column);233 }234235 protected virtual TableRow CreateTableRow(Location location, TableCell[] cells, AstNode node)236 {237 return new TableRow(location, cells);238 }239240 protected virtual TableCell CreateTableCell(Location location, string value)241 {242 return new TableCell(location, value);243 }244245 private Location GetLocation(Token token, int column = 0)246 {247 return column == 0 ? token.Location : CreateLocation(token.Location.Line, column);248 }249250 private Tag[] GetTags(AstNode node)251 {252 var tagsNode = node.GetSingle<AstNode>(RuleType.Tags);253 if (tagsNode == null)254 return new Tag[0];255256 return tagsNode.GetTokens(TokenType.TagLine)257 .SelectMany(t => t.MatchedItems, (t, tagItem) =>258 CreateTag(GetLocation(t, tagItem.Column), tagItem.Text, tagsNode))259 .ToArray();260 }261262 private TableRow[] GetTableRows(AstNode node)263 {264 var rows = node.GetTokens(TokenType.TableRow).Select(token => CreateTableRow(GetLocation(token), GetCells(token), node)).ToArray();265 CheckCellCountConsistency(rows);266 return rows;267 }268269 protected virtual void CheckCellCountConsistency(TableRow[] rows)270 {271 if (rows.Length == 0)272 return;273274 int cellCount = rows[0].Cells.Count();275 foreach (var row in rows)276 {277 if (row.Cells.Count() != cellCount)278 {279 HandleAstError("inconsistent cell count within the table", row.Location);280 }281 }282 }283 ...

Full Screen

Full Screen

FeatureClassTests.cs

Source:FeatureClassTests.cs Github

copy

Full Screen

...214 new string[]215 {216 "When " + FeatureWithDataTableScenarioStep.Steptext217 },218 new Gherkin.Ast.DataTable(new Gherkin.Ast.TableRow[]219 {220 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]221 {222 new Gherkin.Ast.TableCell(null, "First argument"),223 new Gherkin.Ast.TableCell(null, "Second argument"),224 new Gherkin.Ast.TableCell(null, "Result"),225 }),226 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]227 {228 new Gherkin.Ast.TableCell(null, "1"),229 new Gherkin.Ast.TableCell(null, "2"),230 new Gherkin.Ast.TableCell(null, "3"),231 }),232 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]233 {234 new Gherkin.Ast.TableCell(null, "a"),235 new Gherkin.Ast.TableCell(null, "b"),236 new Gherkin.Ast.TableCell(null, "c"),237 })238 })).Feature.Children.First() as Gherkin.Ast.Scenario;239 //act.240 var scenario = sut.ExtractScenario(gherknScenario, null);241 //assert.242 Assert.NotNull(scenario);243 }244 private sealed class FeatureWithDataTableScenarioStep : Feature245 {246 public Gherkin.Ast.DataTable ReceivedDataTable { get; private set; }...

Full Screen

Full Screen

GherkinScenarioOutlineTests.cs

Source:GherkinScenarioOutlineTests.cs Github

copy

Full Screen

...29 null,30 null,31 "existing example",32 null,33 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]{ }),34 new Gherkin.Ast.TableRow[]35 {36 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]{ })37 })38 });39 //act / assert.40 Assert.Throws<InvalidOperationException>(() => sut.ApplyExampleRow(exampleName, exampleRowIndex));41 }42 [Fact]43 public void ApplyExampleRow_Digests_Row_Values_Into_Scenario()44 {45 //arrange.46 var sut = new Gherkin.Ast.ScenarioOutline(47 null,48 null,49 null,50 "outline123",51 null,52 new Gherkin.Ast.Step[] 53 {54 new Gherkin.Ast.Step(null, "Given", "I chose <a> as first number", null),55 new Gherkin.Ast.Step(null, "And", "I chose <b> as second number", null),56 new Gherkin.Ast.Step(null, "When", "I press add", null),57 new Gherkin.Ast.Step(null, "Then", "the result should be <sum> on the screen", null),58 },59 new Gherkin.Ast.Examples[]60 {61 new Gherkin.Ast.Examples(62 null,63 null,64 null,65 "existing example",66 null,67 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]68 {69 new Gherkin.Ast.TableCell(null, "a"),70 new Gherkin.Ast.TableCell(null, "b"),71 new Gherkin.Ast.TableCell(null, "sum")72 }),73 new Gherkin.Ast.TableRow[]74 {75 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]76 {77 new Gherkin.Ast.TableCell(null, "1"),78 new Gherkin.Ast.TableCell(null, "2"),79 new Gherkin.Ast.TableCell(null, "3")80 })81 })82 });83 //act.84 var scenario = sut.ApplyExampleRow("existing example", 0);85 //assert.86 Assert.NotNull(scenario);87 Assert.Equal(sut.Name, scenario.Name);88 Assert.Equal(sut.Steps.Count(), scenario.Steps.Count());89 Assert.Equal(4, scenario.Steps.Count());90 var sutSteps = sut.Steps.ToList();91 var scenarioSteps = scenario.Steps.ToList();92 ValidateStep(scenarioSteps[0], "Given", "I chose 1 as first number", sutSteps[0]);93 ValidateStep(scenarioSteps[1], "And", "I chose 2 as second number", sutSteps[1]);94 ValidateStep(scenarioSteps[2], "When", "I press add", sutSteps[2]);95 ValidateStep(scenarioSteps[3], "Then", "the result should be 3 on the screen", sutSteps[3]);96 void ValidateStep(Gherkin.Ast.Step step, string keyword, string text,97 Gherkin.Ast.Step other)98 {99 Assert.NotSame(other, step);100 Assert.Equal(keyword, step.Keyword);101 Assert.Equal(text, step.Text);102 }103 }104 [Fact]105 public void ApplyExampleRow_Digests_Row_Values_Into_Scenario_With_Multiple_Placeholders_Per_Step()106 {107 //arrange.108 var sut = new Gherkin.Ast.ScenarioOutline(109 null,110 null,111 null,112 "outline123",113 null,114 new Gherkin.Ast.Step[]115 {116 new Gherkin.Ast.Step(null, "Given", "I chose <a> as first number and <b> as second number", null),117 new Gherkin.Ast.Step(null, "When", "I press add", null),118 new Gherkin.Ast.Step(null, "Then", "the result should be <sum> on the screen", null),119 },120 new Gherkin.Ast.Examples[]121 {122 new Gherkin.Ast.Examples(123 null,124 null,125 null,126 "existing example",127 null,128 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]129 {130 new Gherkin.Ast.TableCell(null, "a"),131 new Gherkin.Ast.TableCell(null, "b"),132 new Gherkin.Ast.TableCell(null, "sum")133 }),134 new Gherkin.Ast.TableRow[]135 {136 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]137 {138 new Gherkin.Ast.TableCell(null, "1"),139 new Gherkin.Ast.TableCell(null, "2"),140 new Gherkin.Ast.TableCell(null, "3")141 })142 })143 });144 //act.145 var scenario = sut.ApplyExampleRow("existing example", 0);146 //assert.147 Assert.NotNull(scenario);148 Assert.Equal(sut.Name, scenario.Name);149 Assert.Equal(sut.Steps.Count(), scenario.Steps.Count());150 Assert.Equal(3, scenario.Steps.Count());...

Full Screen

Full Screen

TestAstFormatter.cs

Source:TestAstFormatter.cs Github

copy

Full Screen

...97 {98 FormatRow(tableRow, result, indent);99 }100 }101 private void FormatRow(TableRow tableRow, StringBuilder result, string indent = INDENT)102 {103 result.Append(indent);104 FormatHasLocation(tableRow, result);105 foreach (var tableCell in tableRow.Cells)106 {107 result.Append("|");108 FormatHasLocation(tableCell, result);109 result.Append(tableCell.Value);110 }111 result.AppendLine("|");112 }113 private void FormatTags(IHasTags hasTags, StringBuilder result)114 {115 if (!hasTags.Tags.Any())...

Full Screen

Full Screen

DataTableArgumentTests.cs

Source:DataTableArgumentTests.cs Github

copy

Full Screen

...26 public void DigestScenarioStepValues_Sets_Value_As_DataTable_When_Only_DataTable()27 {28 //arrange.29 var sut = new DataTableArgument();30 var dataTable = new Gherkin.Ast.DataTable(new Gherkin.Ast.TableRow[]31 {32 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]33 {34 new Gherkin.Ast.TableCell(null, "First argument"),35 new Gherkin.Ast.TableCell(null, "Second argument"),36 new Gherkin.Ast.TableCell(null, "Result"),37 }),38 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]39 {40 new Gherkin.Ast.TableCell(null, "1"),41 new Gherkin.Ast.TableCell(null, "2"),42 new Gherkin.Ast.TableCell(null, "3"),43 }),44 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]45 {46 new Gherkin.Ast.TableCell(null, "a"),47 new Gherkin.Ast.TableCell(null, "b"),48 new Gherkin.Ast.TableCell(null, "c"),49 })50 });51 //act.52 sut.DigestScenarioStepValues(new string[0], dataTable);53 //assert.54 Assert.Same(dataTable, sut.Value);55 }56 [Fact]57 public void DigestScenarioStepValues_Sets_Value_As_DataTable_When_DataTable_And_Other_Args_Present()58 {59 //arrange.60 var sut = new DataTableArgument();61 var dataTable = new Gherkin.Ast.DataTable(new Gherkin.Ast.TableRow[]62 {63 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]64 {65 new Gherkin.Ast.TableCell(null, "First argument"),66 new Gherkin.Ast.TableCell(null, "Second argument"),67 new Gherkin.Ast.TableCell(null, "Result"),68 }),69 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]70 {71 new Gherkin.Ast.TableCell(null, "1"),72 new Gherkin.Ast.TableCell(null, "2"),73 new Gherkin.Ast.TableCell(null, "3"),74 }),75 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]76 {77 new Gherkin.Ast.TableCell(null, "a"),78 new Gherkin.Ast.TableCell(null, "b"),79 new Gherkin.Ast.TableCell(null, "c"),80 })81 });82 //act.83 sut.DigestScenarioStepValues(new string[] { "1", "2", "3" }, dataTable);84 //assert.85 Assert.Same(dataTable, sut.Value);86 }87 88 [Fact]89 public void IsSameAs_Identifies_Similar_Instances()...

Full Screen

Full Screen

GherkinFeatureBuilder.cs

Source:GherkinFeatureBuilder.cs Github

copy

Full Screen

...43 return new Feature(null, null, null, null, null, null, _definitions.ToArray());44 }45 public class ExamplesBuilder46 {47 private TableRow _header;48 private List<Examples> _examples = new List<Examples>();49 public Examples[] Examples => _examples.ToArray();50 public ExamplesBuilder WithExampleHeadings(params string[] headings)51 {52 _header = new TableRow(null, headings.Select(h => new TableCell(null, h)).ToArray());53 return this;54 }55 public ExamplesBuilder WithExamples(string name, Action<TableBuilder> buildRows)56 {57 var tableBuilder = new TableBuilder();58 buildRows(tableBuilder);59 var examples = new Examples(new Tag[0], null, null, name, null, _header, tableBuilder.Rows);60 _examples.Add(examples);61 return this;62 }63 }64 public class TableBuilder65 {66 public List<TableRow> _rows = new List<TableRow>();67 public TableRow[] Rows => _rows.ToArray();68 public TableBuilder WithData(params object[] data)69 {70 _rows.Add(new TableRow(null, data.Select(d => new TableCell(null, d.ToString())).ToArray()));71 return this;72 }73 }74 public class GherkinStepBuilder75 {76 private List<Step> _steps = new List<Step>();77 public Step[] Steps => _steps.ToArray();78 public GherkinStepBuilder Given(string step, StepArgument stepArgument)79 {80 _steps.Add(new Step(null, "Given", step, stepArgument));81 return this;82 }83 public GherkinStepBuilder When(string step, StepArgument stepArgument)84 {...

Full Screen

Full Screen

GherkInspectorExample.cs

Source:GherkInspectorExample.cs Github

copy

Full Screen

...5 using System.Text;6 public class GherkInspectorExample7 {8 public GherkInspectorLocation Location { get; private set; }9 public GherkInspectorTableRow TableHeader { get; private set; }10 public IEnumerable<GherkInspectorTableRow> TableBody { get; private set; }11 public GherkInspectorExample(GherkInspectorLocation location, GherkInspectorTableRow headerRow)12 {13 Location = location;14 TableHeader = headerRow;15 TableBody = new List<GherkInspectorTableRow>();16 }17 }18 public class GherkInspectorTableRow19 {20 public GherkInspectorLocation Location { get; private set; }21 public IEnumerable<GherkInspectorTableCell> Cells { get; private set; }22 public GherkInspectorTableRow(GherkInspectorLocation location, List<GherkInspectorTableCell> cells)23 {24 Location = location;25 Cells = cells;26 }27 }28 public class GherkInspectorTableCell29 {30 public GherkInspectorLocation Location { get; private set; }31 public string Value { get; private set; }32 public GherkInspectorTableCell(GherkInspectorLocation location, string value)33 {34 Location = location;35 Value = value;36 }37 }38 /*39 * example40{Gherkin.Ast.Examples}41 Description: null42 Keyword: "Examples"43 Location: {Gherkin.Ast.Location}44 Name: ""45 TableBody: {Gherkin.Ast.TableRow[1]}46 TableHeader: {Gherkin.Ast.TableRow}47 Tags: {Gherkin.Ast.Tag[0]}48example.TableHeader49{Gherkin.Ast.TableRow}50 Cells: {Gherkin.Ast.TableCell[1]}51 Location: {Gherkin.Ast.Location}52example.TableBody53{Gherkin.Ast.TableRow[1]}54 [0]: {Gherkin.Ast.TableRow}55 */56}...

Full Screen

Full Screen

TableRow

Using AI Code Generation

copy

Full Screen

1using (var reader = new StringReader("Given I have 5 cucumbers"))2{3 var parser = new Parser();4 var feature = parser.Parse(reader);5 var steps = feature.Children[0].Steps;6 foreach (var step in steps)7 {8 var table = step.Argument as Gherkin.Ast.DataTable;9 if (table != null)10 {11 var tableRows = table.Rows;12 foreach (var tableRow in tableRows)13 {14 var tableCells = tableRow.Cells;15 foreach (var tableCell in tableCells)16 {17 var tableCellText = tableCell.Value;18 Console.WriteLine(tableCellText);19 }20 }21 }22 }23}24using (var reader = new StringReader("Given I have 5 cucumbers"))25{26 var parser = new Parser();27 var feature = parser.Parse(reader);28 var steps = feature.Children[0].Steps;29 foreach (var step in steps)30 {31 var table = step.Argument as Gherkin.Ast.DataTable;32 if (table != null)33 {34 var tableRows = table.Rows;35 foreach (var tableRow in tableRows)36 {37 var tableCells = tableRow.Cells;38 foreach (var tableCell in tableCells)39 {40 var tableCellText = tableCell.Value;41 Console.WriteLine(tableCellText);42 }43 }44 }45 }46}47using (var reader = new StringReader("Given I have 5 cucumbers"))48{49 var parser = new Parser();50 var feature = parser.Parse(reader);51 var steps = feature.Children[0].Steps;52 foreach (var step in steps)53 {54 var table = step.Argument as Gherkin.Ast.DataTable;55 if (table != null)56 {57 var tableRows = table.Rows;58 foreach (var tableRow in tableRows)59 {60 var tableCells = tableRow.Cells;61 foreach (var tableCell in tableCells)62 {63 var tableCellText = tableCell.Value;64 Console.WriteLine(tableCellText);65 }66 }67 }68 }69}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Gherkin-dotnet automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in TableRow

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful