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

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

GherkinFeatureTests.cs

Source:GherkinFeatureTests.cs Github

copy

Full Screen

...147 var isIgnored = feature.IsScenarioIgnored(scenarioName);148 //assert.149 Assert.True(isIgnored);150 }151 public static object[][] DataFor_Feature_And_ScenarioOutline_And_Examples_Null_Arguments152 {153 get154 {155 return new object[][]156 {157 new object[]{ null, "scenario outline name", "examples name" },158 new object[]{ new Gherkin.Ast.Feature(null, null, null, null, null, null, null), null, "examples name" },159 new object[]{ new Gherkin.Ast.Feature(null, null, null, null, null, null, null), "scenario outline name", null }160 };161 }162 }163 [Theory]164 [MemberData(nameof(DataFor_Feature_And_ScenarioOutline_And_Examples_Null_Arguments))]165 public void GetExamplesTags_Requires_Arguments(166 Gherkin.Ast.Feature feature,167 string scenarioOutlineName,168 string examplesName169 )170 {171 //act / assert.172 Assert.Throws<ArgumentNullException>(() => feature.GetExamplesTags(173 scenarioOutlineName,174 examplesName));175 }176 [Fact]177 public void GetExamplesTags_Retrieves_Tags_Of_Feature_And_OutLine_And_Examples_Combined()178 {179 //arrange.180 var featureTags = new Gherkin.Ast.Tag[]181 {182 new Gherkin.Ast.Tag(null, "featuretag-1"),183 new Gherkin.Ast.Tag(null, "featuretag-2")184 };185 var outlineTags = new Gherkin.Ast.Tag[]186 {187 new Gherkin.Ast.Tag(null, "outlinetag-1"),188 new Gherkin.Ast.Tag(null, "outlinetag-2"),189 new Gherkin.Ast.Tag(null, "outlinetag-3")190 };191 var examplesTags = new Gherkin.Ast.Tag[]192 {193 new Gherkin.Ast.Tag(null, "examplestag-1"),194 new Gherkin.Ast.Tag(null, "examplestag-2"),195 new Gherkin.Ast.Tag(null, "examplestag-2"),196 new Gherkin.Ast.Tag(null, "examplestag-3")197 };198 var scenarioOutlineName = "scenario name 123";199 var examplesName = "examples name 123";200 var feature = new Gherkin.Ast.Feature(201 featureTags, null, null, null, null, null,202 new Gherkin.Ast.ScenarioDefinition[]203 {204 new Gherkin.Ast.ScenarioOutline(outlineTags, null, null, scenarioOutlineName, null, null,205 new Gherkin.Ast.Examples[]206 {207 new Gherkin.Ast.Examples(examplesTags, null, null, examplesName, null, null, null)208 })209 });210 //act.211 var examplesTagNames = feature.GetExamplesTags(scenarioOutlineName, examplesName);212 //assert.213 Assert.NotNull(examplesTagNames);214 var expectedTagNames = featureTags.Union(outlineTags).Union(examplesTags).Select(t => t.Name);215 Assert.Equal(expectedTagNames, examplesTagNames);216 }217 [Theory]218 [MemberData(nameof(DataFor_Feature_And_ScenarioOutline_And_Examples_Null_Arguments))]219 public void IsExamplesIgnored_Requires_Arguments(220 Gherkin.Ast.Feature feature,221 string scenarioOutlineName,222 string examplesName223 )224 {225 //act / assert.226 Assert.Throws<ArgumentNullException>(() => feature.IsExamplesIgnored(scenarioOutlineName, examplesName));227 }228 [Fact]229 public void IsExamplesIgnored_Does_Not_Treat_Ignored_If_No_Ignore_Tag()230 {231 //arrange.232 var featureTags = new Gherkin.Ast.Tag[]233 {234 new Gherkin.Ast.Tag(null, "featuretag-1"),235 new Gherkin.Ast.Tag(null, "featuretag-2")236 };237 var outlineTags = new Gherkin.Ast.Tag[]238 {239 new Gherkin.Ast.Tag(null, "outlinetag-1"),240 new Gherkin.Ast.Tag(null, "outlinetag-2"),241 new Gherkin.Ast.Tag(null, "outlinetag-3")242 };243 var examplesTags = new Gherkin.Ast.Tag[]244 {245 new Gherkin.Ast.Tag(null, "examplestag-1"),246 new Gherkin.Ast.Tag(null, "examplestag-2"),247 new Gherkin.Ast.Tag(null, "examplestag-2"),248 new Gherkin.Ast.Tag(null, "examplestag-3")249 };250 var scenarioOutlineName = "scenario name 123";251 var examplesName = "examples name 123";252 var feature = new Gherkin.Ast.Feature(253 featureTags, null, null, null, null, null,254 new Gherkin.Ast.ScenarioDefinition[]255 {256 new Gherkin.Ast.ScenarioOutline(outlineTags, null, null, scenarioOutlineName, null, null,257 new Gherkin.Ast.Examples[]258 {259 new Gherkin.Ast.Examples(examplesTags, null, null, examplesName, null, null, null)260 })261 });262 //act.263 var isIgnored = feature.IsExamplesIgnored(scenarioOutlineName, examplesName);264 //assert.265 Assert.False(isIgnored);266 }267 [Fact]268 public void IsExamplesIgnored_Treats_Ignored_If_Feature_Is_Ignored()269 {270 //arrange.271 var featureTags = new Gherkin.Ast.Tag[]272 {273 new Gherkin.Ast.Tag(null, "featuretag-1"),274 new Gherkin.Ast.Tag(null, GherkinFeatureExtensions.IgnoreTag)275 };276 var outlineTags = new Gherkin.Ast.Tag[]277 {278 new Gherkin.Ast.Tag(null, "outlinetag-1"),279 new Gherkin.Ast.Tag(null, "outlinetag-2"),280 new Gherkin.Ast.Tag(null, "outlinetag-3")281 };282 var examplesTags = new Gherkin.Ast.Tag[]283 {284 new Gherkin.Ast.Tag(null, "examplestag-1"),285 new Gherkin.Ast.Tag(null, "examplestag-2"),286 new Gherkin.Ast.Tag(null, "examplestag-2"),287 new Gherkin.Ast.Tag(null, "examplestag-3")288 };289 var scenarioOutlineName = "scenario name 123";290 var examplesName = "examples name 123";291 var feature = new Gherkin.Ast.Feature(292 featureTags, null, null, null, null, null,293 new Gherkin.Ast.ScenarioDefinition[]294 {295 new Gherkin.Ast.ScenarioOutline(outlineTags, null, null, scenarioOutlineName, null, null,296 new Gherkin.Ast.Examples[]297 {298 new Gherkin.Ast.Examples(examplesTags, null, null, examplesName, null, null, null)299 })300 });301 //act.302 var isIgnored = feature.IsExamplesIgnored(scenarioOutlineName, examplesName);303 //assert.304 Assert.True(isIgnored);305 }306 [Fact]307 public void IsExamplesIgnored_Treats_Ignored_If_ScenarioOutline_Is_Ignored()308 {309 //arrange.310 var featureTags = new Gherkin.Ast.Tag[]311 {312 new Gherkin.Ast.Tag(null, "featuretag-1"),313 new Gherkin.Ast.Tag(null, "featuretag-1")314 };315 var outlineTags = new Gherkin.Ast.Tag[]316 {317 new Gherkin.Ast.Tag(null, "outlinetag-1"),318 new Gherkin.Ast.Tag(null, GherkinFeatureExtensions.IgnoreTag),319 new Gherkin.Ast.Tag(null, "outlinetag-3")320 };321 var examplesTags = new Gherkin.Ast.Tag[]322 {323 new Gherkin.Ast.Tag(null, "examplestag-1"),324 new Gherkin.Ast.Tag(null, "examplestag-2"),325 new Gherkin.Ast.Tag(null, "examplestag-2"),326 new Gherkin.Ast.Tag(null, "examplestag-3")327 };328 var scenarioOutlineName = "scenario name 123";329 var examplesName = "examples name 123";330 var feature = new Gherkin.Ast.Feature(331 featureTags, null, null, null, null, null,332 new Gherkin.Ast.ScenarioDefinition[]333 {334 new Gherkin.Ast.ScenarioOutline(outlineTags, null, null, scenarioOutlineName, null, null,335 new Gherkin.Ast.Examples[]336 {337 new Gherkin.Ast.Examples(examplesTags, null, null, examplesName, null, null, null)338 })339 });340 //act.341 var isIgnored = feature.IsExamplesIgnored(scenarioOutlineName, examplesName);342 //assert.343 Assert.True(isIgnored);344 }345 [Fact]346 public void IsExamplesIgnored_Treats_Ignored_If_Examples_Is_Ignored()347 {348 //arrange.349 var featureTags = new Gherkin.Ast.Tag[]350 {351 new Gherkin.Ast.Tag(null, "featuretag-1"),352 new Gherkin.Ast.Tag(null, "featuretag-2")353 };354 var outlineTags = new Gherkin.Ast.Tag[]355 {356 new Gherkin.Ast.Tag(null, "outlinetag-1"),357 new Gherkin.Ast.Tag(null, "outlinetag-2"),358 new Gherkin.Ast.Tag(null, "outlinetag-3")359 };360 var examplesTags = new Gherkin.Ast.Tag[]361 {362 new Gherkin.Ast.Tag(null, "examplestag-1"),363 new Gherkin.Ast.Tag(null, "examplestag-2"),364 new Gherkin.Ast.Tag(null, GherkinFeatureExtensions.IgnoreTag),365 new Gherkin.Ast.Tag(null, "examplestag-3")366 };367 var scenarioOutlineName = "scenario name 123";368 var examplesName = "examples name 123";369 var feature = new Gherkin.Ast.Feature(370 featureTags, null, null, null, null, null,371 new Gherkin.Ast.ScenarioDefinition[]372 {373 new Gherkin.Ast.ScenarioOutline(outlineTags, null, null, scenarioOutlineName, null, null,374 new Gherkin.Ast.Examples[]375 {376 new Gherkin.Ast.Examples(examplesTags, null, null, examplesName, null, null, null)377 })378 });379 //act.380 var isIgnored = feature.IsExamplesIgnored(scenarioOutlineName, examplesName);381 //assert.382 Assert.True(isIgnored);383 }384 }385}...

Full Screen

Full Screen

GherkinEntityExtensions.cs

Source:GherkinEntityExtensions.cs Github

copy

Full Screen

...93 Title = scenario.Name,94 Description = scenario.Description,95 Tags = scenario.Tags.ConvertToStrings(),96 Steps = scenario.Steps.ConvertToSteps(dialect),97 ExampleSets = scenario.Examples.ConvertToExampleSets(),98 Location = scenario.Location.ConvertToSourceLocation()99 };100 }101 /// <summary>102 /// Converts the provided <see cref=" Gherkin.Ast.Background"/> instance into a <see cref="Augurk.Entities.Background"/> instance.103 /// </summary>104 /// <param name="background">The <see cref=" Gherkin.Ast.Background"/> instance that should be converted.</param>105 /// <param name="dialect">The <see cref="GherkinDialect"/> that is being used for this feature.</param>106 /// <returns>The converted <see cref="Augurk.Entities.Background"/> instance.</returns>107 public static Background ConvertToBackground(this Gherkin.Ast.Background background, GherkinDialect dialect)108 {109 if (background == null)110 {111 return null;112 }113 return new Background()114 {115 Title = background.Name,116 Keyword = background.Keyword,117 Steps = background.Steps.ConvertToSteps(dialect),118 Location = background.Location.ConvertToSourceLocation()119 };120 }121 /// <summary>122 /// Converts the provided <see cref="Gherkin.Ast.Examples"/> instances into an enumerable collection of <see cref="Augurk.Entities.ExampleSet"/> instances.123 /// </summary>124 /// <param name="examples">The <see cref="Gherkin.Ast.Examples"/> instances that should be converted.</param>125 /// <returns>An enumerable collection of <see cref="Augurk.Entities.ExampleSet"/> instances.</returns>126 public static IEnumerable<ExampleSet> ConvertToExampleSets(this IEnumerable<Gherkin.Ast.Examples> examples)127 {128 if (examples == null)129 {130 throw new ArgumentNullException("examples");131 }132 return examples.Select(exampleSet => exampleSet.ConvertToExampleSet()).ToArray();133 }134 /// <summary>135 /// Converts the provided <see cref="Gherkin.Ast.Examples"/> instance into a<see cref="Augurk.Entities.ExampleSet"/> instance.136 /// </summary>137 /// <param name="examples">The <see cref="Gherkin.Ast.Examples"/> instance that should be converted.</param>138 /// <returns>The converted <see cref="Augurk.Entities.ExampleSet"/> instance.</returns>139 public static ExampleSet ConvertToExampleSet(this Gherkin.Ast.Examples examples)140 {141 if (examples == null)142 {143 throw new ArgumentNullException("exampleSet");144 }145 return new ExampleSet()146 {147 Title = examples.Name,148 Description = examples.Description,149 Keyword = examples.Keyword,150 Tags = examples.Tags.ConvertToStrings(),151 Columns = examples.TableHeader.Cells.Select(cell => cell.Value).ToArray(),152 Rows = examples.TableBody.Select(row => row.Cells.Select(cell => cell.Value).ToArray()).ToArray(),153 Location = examples.Location.ConvertToSourceLocation()...

Full Screen

Full Screen

DeveroomGherkinParser.cs

Source:DeveroomGherkinParser.cs Github

copy

Full Screen

...119 errors.AddRange(((DeveroomGherkinAstBuilder)_astBuilder).Errors);120 if (specFlowDocument?.Feature != null)121 {122 CheckForDuplicateScenarios(specFlowDocument.Feature, errors);123 CheckForDuplicateExamples(specFlowDocument.Feature, errors);124 CheckForMissingExamples(specFlowDocument.Feature, errors);125 CheckForRulesPreSpecFlow31(specFlowDocument.Feature, errors);126 }127 // collect128 if (errors.Count == 1)129 throw errors[0];130 if (errors.Count > 1)131 throw new CompositeParserException(errors.ToArray());132 }133 private void CheckForRulesPreSpecFlow31(Feature feature, List<ParserException> errors)134 {135 //TODO: Show error when Rule keyword is used in SpecFlow v3.0 or earlier136 }137 private void CheckForDuplicateScenarios(Feature feature, List<ParserException> errors)138 {139 // duplicate scenario name140 var duplicatedScenarios = feature.FlattenScenarioDefinitions().GroupBy(sd => sd.Name, sd => sd).Where(g => g.Count() > 1).ToArray();141 errors.AddRange(142 duplicatedScenarios.Select(g =>143 new SemanticParserException(144 $"Feature file already contains a scenario with name '{g.Key}'",145 g.ElementAt(1).Location)));146 }147 private void CheckForDuplicateExamples(Feature feature, List<ParserException> errors)148 {149 foreach (var scenarioOutline in feature.FlattenScenarioDefinitions().OfType<ScenarioOutline>())150 {151 var duplicateExamples = scenarioOutline.Examples152 .Where(e => !String.IsNullOrWhiteSpace(e.Name))153 .Where(e => e.Tags.All(t => t.Name != "ignore"))154 .GroupBy(e => e.Name, e => e).Where(g => g.Count() > 1);155 foreach (var duplicateExample in duplicateExamples)156 {157 var message = $"Scenario Outline '{scenarioOutline.Name}' already contains an example with name '{duplicateExample.Key}'";158 var semanticParserException = new SemanticParserException(message, duplicateExample.ElementAt(1).Location);159 errors.Add(semanticParserException);160 }161 }162 }163 private void CheckForMissingExamples(Feature feature, List<ParserException> errors)164 {165 foreach (var scenarioOutline in feature.FlattenScenarioDefinitions().OfType<ScenarioOutline>())166 {167 if (DoesntHavePopulatedExamples(scenarioOutline))168 {169 var message = $"Scenario Outline '{scenarioOutline.Name}' has no examples defined";170 var semanticParserException = new SemanticParserException(message, scenarioOutline.Location);171 errors.Add(semanticParserException);172 }173 }174 }175 private static bool DoesntHavePopulatedExamples(ScenarioOutline scenarioOutline)176 {177 return !scenarioOutline.Examples.Any() || scenarioOutline.Examples.Any(x => x.TableBody == null || !x.TableBody.Any());178 }179 #endregion180 #region Expected tokens181 class NullAstBuilder : IAstBuilder<DeveroomGherkinDocument>182 {183 public void Build(Token token)184 {185 }186 public void StartRule(RuleType ruleType)187 {188 }189 public void EndRule(RuleType ruleType)190 {191 }192 public DeveroomGherkinDocument GetResult()193 {194 return null;195 }196 public void Reset()197 {198 }199 }200 class AllFalseTokenMatcher : ITokenMatcher201 {202 public bool Match_EOF(Token token)203 {204 return false;205 }206 public bool Match_Empty(Token token)207 {208 return false;209 }210 public bool Match_Comment(Token token)211 {212 return false;213 }214 public bool Match_TagLine(Token token)215 {216 return false;217 }218 public bool Match_FeatureLine(Token token)219 {220 return false;221 }222 public bool Match_RuleLine(Token token)223 {224 return false;225 }226 public bool Match_BackgroundLine(Token token)227 {228 return false;229 }230 public bool Match_ScenarioLine(Token token)231 {232 return false;233 }234 public bool Match_ExamplesLine(Token token)235 {236 return false;237 }238 public bool Match_StepLine(Token token)239 {240 return false;241 }242 public bool Match_DocStringSeparator(Token token)243 {244 return false;245 }246 public bool Match_TableRow(Token token)247 {248 return false;...

Full Screen

Full Screen

GherkinScenarioOutlineTests.cs

Source:GherkinScenarioOutlineTests.cs Github

copy

Full Screen

...21 null,22 "outline123",23 null,24 new Gherkin.Ast.Step[] { },25 new Gherkin.Ast.Examples[] 26 {27 new Gherkin.Ast.Examples(28 null,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[]...

Full Screen

Full Screen

CompatibleAstConverter.cs

Source:CompatibleAstConverter.cs Github

copy

Full Screen

...4using Gherkin.Ast;5using TechTalk.SpecFlow.Parser.SyntaxElements;6using Background = TechTalk.SpecFlow.Parser.SyntaxElements.Background;7using Comment = TechTalk.SpecFlow.Parser.SyntaxElements.Comment;8using Examples = TechTalk.SpecFlow.Parser.SyntaxElements.Examples;9using Feature = TechTalk.SpecFlow.Parser.SyntaxElements.Feature;10using Scenario = TechTalk.SpecFlow.Parser.SyntaxElements.Scenario;11using ScenarioOutline = TechTalk.SpecFlow.Parser.SyntaxElements.ScenarioOutline;12using Tag = TechTalk.SpecFlow.Parser.SyntaxElements.Tag;13namespace TechTalk.SpecFlow.Parser.Compatibility14{15 public class CompatibleAstConverter16 {17 public static Feature ConvertToCompatibleFeature(SpecFlowDocument specFlowDocument)18 {19 var specFlowFeature = specFlowDocument.SpecFlowFeature;20 return new Feature(specFlowFeature.Keyword, specFlowFeature.Name, 21 ConvertToCompatibleTags(specFlowFeature.Tags),22 specFlowFeature.Description, 23 ConvertToCompatibleBackground(specFlowFeature.Background), 24 ConvertToCompatibleScenarios(specFlowFeature.ScenarioDefinitions), 25 ConvertToCompatibleComments(specFlowDocument.Comments))26 {27 FilePosition = ConvertToCompatibleFilePosition(specFlowFeature.Location),28 Language = specFlowFeature.Language,29 SourceFile = specFlowDocument.SourceFilePath30 };31 }32 private static Comment[] ConvertToCompatibleComments(IEnumerable<global::Gherkin.Ast.Comment> comments)33 {34 return comments.Select(ConvertToCompatibleComment).Where(c => c != null).ToArray();35 }36 private static Comment ConvertToCompatibleComment(global::Gherkin.Ast.Comment c)37 {38 var trimmedText = c.Text.TrimStart('#', ' ', '\t');39 if (trimmedText.Length == 0)40 return null;41 return new Comment(trimmedText, ConvertToCompatibleFilePosition(c.Location, c.Text.Length - trimmedText.Length));42 }43 private static Scenario[] ConvertToCompatibleScenarios(IEnumerable<Gherkin.Ast.ScenarioDefinition> scenarioDefinitions)44 {45 return scenarioDefinitions.Select(ConvertToCompatibleScenario).ToArray();46 }47 private static Scenario ConvertToCompatibleScenario(Gherkin.Ast.ScenarioDefinition sd)48 {49 var convertToCompatibleTags = ConvertToCompatibleTags(sd.GetTags());50 var result = sd is global::Gherkin.Ast.ScenarioOutline51 ? new ScenarioOutline(sd.Keyword, sd.Name, sd.Description, convertToCompatibleTags, ConvertToCompatibleSteps(sd.Steps), ConvertToCompatibleExamples(((global::Gherkin.Ast.ScenarioOutline)sd).Examples))52 : new Scenario(sd.Keyword, sd.Name, sd.Description, convertToCompatibleTags, ConvertToCompatibleSteps(sd.Steps));53 result.FilePosition = ConvertToCompatibleFilePosition(sd.Location);54 return result;55 }56 private static Examples ConvertToCompatibleExamples(IEnumerable<global::Gherkin.Ast.Examples> examples)57 {58 return new Examples(examples.Select(e => new ExampleSet(e.Keyword, e.Name, e.Description, ConvertToCompatibleTags(e.Tags), ConvertToCompatibleExamplesTable(e))).ToArray());59 }60 private static GherkinTable ConvertToCompatibleExamplesTable(global::Gherkin.Ast.Examples examples)61 {62 return new GherkinTable(ConvertToCompatibleRow(examples.TableHeader), examples.TableBody.Select(ConvertToCompatibleRow).ToArray());63 }64 private static GherkinTableRow ConvertToCompatibleRow(global::Gherkin.Ast.TableRow tableRow)65 {66 return new GherkinTableRow(tableRow.Cells.Select(c => new GherkinTableCell(c.Value)).ToArray())67 {68 FilePosition = ConvertToCompatibleFilePosition(tableRow.Location)69 };70 }71 private static ScenarioSteps ConvertToCompatibleSteps(IEnumerable<global::Gherkin.Ast.Step> steps)72 {73 return new ScenarioSteps(steps.Select(s => ConvertToCompatibleStep((SpecFlowStep)s)).ToArray());74 }...

Full Screen

Full Screen

AstEventConverter.cs

Source:AstEventConverter.cs Github

copy

Full Screen

...3using System.Linq;4using Gherkin.Ast;5using Gherkin.Events.Args.Ast;6using Comment = Gherkin.Events.Args.Ast.Comment;7using Examples = Gherkin.Events.Args.Ast.Examples;8using Feature = Gherkin.Events.Args.Ast.Feature;9using Location = Gherkin.Events.Args.Ast.Location;10using Rule = Gherkin.Events.Args.Ast.Rule;11using Step = Gherkin.Events.Args.Ast.Step;12using StepsContainer = Gherkin.Events.Args.Ast.StepsContainer;13namespace Gherkin.Stream.Converter14{15 public class AstEventConverter16 {17 public GherkinDocumentEventArgs ConvertGherkinDocumentToEventArgs(GherkinDocument gherkinDocument, string sourceEventUri)18 {19 return new GherkinDocumentEventArgs()20 {21 Uri = sourceEventUri,22 Feature = ConvertFeature(gherkinDocument),23 Comments = ConvertComments(gherkinDocument)24 };25 }26 private IReadOnlyCollection<Comment> ConvertComments(GherkinDocument gherkinDocument)27 {28 return gherkinDocument.Comments.Select(c =>29 new Comment()30 {31 Text = c.Text,32 Location = ConvertLocation(c.Location)33 }).ToReadOnlyCollection();34 }35 private Feature ConvertFeature(GherkinDocument gherkinDocument)36 {37 var feature = gherkinDocument.Feature;38 if (feature == null)39 {40 return null;41 }42 return new Feature()43 {44 Name = feature.Name == string.Empty ? null : feature.Name,45 Keyword = feature.Keyword,46 Language = feature.Language,47 Location = ConvertLocation(feature.Location),48 Children = feature.Children.Select(ConvertToChildren).ToReadOnlyCollection()49 };50 }51 private static Location ConvertLocation(Ast.Location location)52 {53 return new Location(location.Column, location.Line);54 }55 private Children ConvertToChildren(IHasLocation hasLocation)56 {57 switch (hasLocation)58 {59 case Background background:60 return new Children()61 {62 Background = new StepsContainer()63 {64 Location = ConvertLocation(background.Location),65 Name = background.Name == string.Empty ? null : background.Name,66 Keyword = background.Keyword,67 Steps = background.Steps.Select(s => ConvertStep(s)).ToList()68 }69 };70 case Scenario scenario:71 return new Children()72 {73 Scenario = new StepsContainer()74 {75 Keyword = scenario.Keyword,76 Location = ConvertLocation(scenario.Location),77 Name = scenario.Name == string.Empty ? null : scenario.Name,78 Steps = scenario.Steps.Select(s => ConvertStep(s)).ToList(),79 Examples = scenario.Examples.Select(ConvertExamples).ToReadOnlyCollection(),80 }81 };82 case Ast.Rule rule:83 {84 return new Children()85 {86 Rule = new Rule()87 {88 Name = rule.Name == string.Empty ? null : rule.Name,89 Keyword = rule.Keyword,90 Children = rule.Children.Select(ConvertToChildren).ToReadOnlyCollection(),91 Location = ConvertLocation(rule.Location)92 }93 };94 }95 default:96 throw new NotImplementedException();97 }98 }99 private Examples ConvertExamples(Ast.Examples examples)100 {101 return new Examples()102 {103 Name = examples.Name == string.Empty ? null : examples.Name,104 Keyword = examples.Keyword,105 Description = examples.Description,106 Location = ConvertLocation(examples.Location),107 TableHeader = ConvertTableHeader(examples),108 TableBody = ConvertToTableBody(examples)109 };110 }111 private IReadOnlyCollection<TableBody> ConvertToTableBody(Ast.Examples examples)112 {113 if (examples.TableBody == null)114 return new List<TableBody>();115 return examples.TableBody.Select(b =>116 new TableBody()117 {118 Location = ConvertLocation(b.Location),119 Cells = b.Cells.Select(ConvertCell).ToReadOnlyCollection()120 }).ToReadOnlyCollection();121 }122 private TableHeader ConvertTableHeader(Ast.Examples examples)123 {124 if (examples.TableHeader == null)125 return null;126 return new TableHeader()127 {128 Location = ConvertLocation(examples.TableHeader.Location),129 Cells = examples.TableHeader.Cells.Select(ConvertCell).ToReadOnlyCollection()130 };131 }132 private Cell ConvertCell(TableCell c)133 {134 return new Cell()135 {136 Value = c.Value,...

Full Screen

Full Screen

GherkinScenarioOutlineExtensions.cs

Source:GherkinScenarioOutlineExtensions.cs Github

copy

Full Screen

...11 this global::Gherkin.Ast.ScenarioOutline @this,12 string exampleName,13 int exampleRowIndex)14 {15 var examples = @this.Examples.FirstOrDefault(e => e.Name == exampleName);16 if (examples == null)17 throw new InvalidOperationException($"Cannot find examples named `{exampleName}` in scenario outline `{@this.Name}`.");18 var exampleRow = GetExampleRow(@this, exampleRowIndex, examples);19 var rowValues = GetExampleRowValues(examples, exampleRow);20 var scenarioSteps = new List<global::Gherkin.Ast.Step>();21 foreach (var outlineStep in @this.Steps)22 {23 var scenarioStep = DigestExampleValuesIntoStep(24 @this, 25 exampleName, 26 exampleRowIndex, 27 rowValues, 28 outlineStep);29 scenarioSteps.Add(scenarioStep);30 }31 return new global::Gherkin.Ast.Scenario(32 @this.Tags?.ToArray(),33 @this.Location,34 @this.Keyword,35 @this.Name,36 @this.Description,37 scenarioSteps.ToArray());38 }39 private static global::Gherkin.Ast.Step DigestExampleValuesIntoStep(global::Gherkin.Ast.ScenarioOutline @this, string exampleName, int exampleRowIndex, Dictionary<string, string> rowValues, global::Gherkin.Ast.Step outlineStep)40 {41 var stepText = _placeholderRegex.Replace(outlineStep.Text,42 match =>43 {44 var placeholderKey = match.Groups[1].Value;45 if (!rowValues.ContainsKey(placeholderKey))46 throw new InvalidOperationException($"Examples table did not provide value for `{placeholderKey}`. Scenario outline: `{@this.Name}`. Examples: `{exampleName}`. Row index: {exampleRowIndex}.");47 var placeholderValue = rowValues[placeholderKey];48 return placeholderValue;49 });50 var scenarioStep = new global::Gherkin.Ast.Step(51 outlineStep.Location,52 outlineStep.Keyword,53 stepText,54 outlineStep.Argument);55 return scenarioStep;56 }57 private static Dictionary<string, string> GetExampleRowValues(global::Gherkin.Ast.Examples examples, List<global::Gherkin.Ast.TableCell> exampleRowCells)58 {59 var rowValues = new Dictionary<string, string>();60 var headerCells = examples.TableHeader.Cells.ToList();61 for (int index = 0; index < headerCells.Count; index++)62 {63 rowValues.Add(headerCells[index].Value, exampleRowCells[index].Value);64 }65 return rowValues;66 }67 private static List<global::Gherkin.Ast.TableCell> GetExampleRow(global::Gherkin.Ast.ScenarioOutline @this, int exampleRowIndex, global::Gherkin.Ast.Examples examples)68 {69 var exampleRows = examples.TableBody.ToList();70 if (!(exampleRowIndex < exampleRows.Count))71 throw new InvalidOperationException($"Index out of range. Cannot retrieve example row at index `{exampleRowIndex}`. Example: `{examples.Name}`. Scenario outline: `{@this.Name}`.");72 var exampleRow = exampleRows[exampleRowIndex];73 var exampleRowCells = exampleRow.Cells.ToList();74 return exampleRowCells;75 }76 }77}...

Full Screen

Full Screen

GherkinFeatureExtensions.cs

Source:GherkinFeatureExtensions.cs Github

copy

Full Screen

...32 {33 var scenarioTags = feature.GetScenarioTags(scenarioName);34 return scenarioTags.Contains(IgnoreTag);35 }36 public static List<string> GetExamplesTags(37 this global::Gherkin.Ast.Feature feature,38 string scenarioOutlineName,39 string examplesName)40 {41 if (feature == null)42 throw new ArgumentNullException(nameof(feature));43 if (string.IsNullOrWhiteSpace(scenarioOutlineName))44 throw new ArgumentNullException(nameof(scenarioOutlineName));45 46 var scenarioOutline = feature.Children.OfType<global::Gherkin.Ast.ScenarioOutline>()47 .FirstOrDefault(o => o.Name == scenarioOutlineName);48 if (scenarioOutline == null)49 throw new InvalidOperationException($"Cannot find scenario outline `{scenarioOutlineName}` under feature `{feature.Name}`.");50 var examples = scenarioOutline.Examples.FirstOrDefault(e => e.Name == examplesName);51 if (examples == null)52 throw new InvalidOperationException($"Cannot find examples `{examplesName}` under scenario outline `{scenarioOutlineName}` and feature `{feature.Name}`.");53 var examplesTags = feature.Tags54 ?.Union(scenarioOutline.Tags ?? new List<global::Gherkin.Ast.Tag>())55 ?.Union(examples.Tags ?? new List<global::Gherkin.Ast.Tag>())56 ?.Select(t => t.Name)57 ?.ToList();58 return examplesTags ?? new List<string>();59 }60 public static bool IsExamplesIgnored(61 this global::Gherkin.Ast.Feature feature,62 string scenarioOutlineName,63 string examplesName)64 {65 var examplesTags = feature.GetExamplesTags(scenarioOutlineName, examplesName);66 return examplesTags.Contains(IgnoreTag);67 }68 }69}...

Full Screen

Full Screen

Examples

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Gherkin.Ast;7{8 {9 static void Main(string[] args)10 {11 var examples = new Examples(new List<TableRow>(), new List<Tag>(), "title", "keyword", "description", 1, 1);12 var examplesList = examples.GetExamples();13 foreach (var example in examplesList)14 {15 Console.WriteLine(example.ToString());16 }17 Console.ReadLine();18 }19 }20}

Full Screen

Full Screen

Examples

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Gherkin.Ast;7using Gherkin;8{9 {10 static void Main(string[] args)11 {12 Parser parser = new Parser();13 Feature feature = parser.Parse(@"C:\Users\mohit\Documents\Visual Studio 2015\Projects\GherkinExample\GherkinExample\Features\GherkinFeature.feature");14 IEnumerable<Examples> examples = feature.Children[0].Examples;15 Table table = examples.ElementAt(0).TableBody;16 IEnumerable<TableRow> rows = table.Rows;17 TableRow row = rows.ElementAt(0);18 IEnumerable<TableCell> cells = row.Cells;19 TableCell cell = cells.ElementAt(0);20 string value = cell.Value;21 Console.WriteLine(value);22 Console.ReadKey();23 }24 }25}

Full Screen

Full Screen

Examples

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Gherkin.Ast;7using System.IO;8using System.Text.RegularExpressions;9{10 {11 static void Main(string[] args)12 {13 | -3 |";14 var parser = new Parser();15 var feature = parser.Parse(gherkin);16 var examples = feature.Children[0].Steps[0].Examples;17 foreach (var example in examples)18 {19 Console.WriteLine(example.Name);20 }21 }22 }23}

Full Screen

Full Screen

Examples

Using AI Code Generation

copy

Full Screen

1var examples = new Gherkin.Ast.Examples();2examples.Name = "test";3examples.TableHeader = null;4examples.TableBody = null;5examples.Description = null;6examples.Tags = null;7examples.Keyword = "Examples";8examples.Location = null;9examples.Id = "examples-1";10examples.Comments = null;11examples.KeywordType = Gherkin.Ast.KeywordType.Examples;12examples.ToString();13examples.GetType();14var examplesBuilder = new Gherkin.Ast.ExamplesBuilder();15examplesBuilder.SetName("test");16examplesBuilder.SetTableHeader(null);17examplesBuilder.SetTableBody(null);18examplesBuilder.SetDescription(null);19examplesBuilder.SetTags(null);20examplesBuilder.SetKeyword("Examples");21examplesBuilder.SetLocation(null);22examplesBuilder.SetId("examples-1");23examplesBuilder.SetComments(null);24examplesBuilder.SetKeywordType(Gherkin.Ast.KeywordType.Examples);25examplesBuilder.Build();26var examples = new Gherkin.Ast.Examples();27examples.Name = "test";28examples.TableHeader = null;29examples.TableBody = null;30examples.Description = null;31examples.Tags = null;32examples.Keyword = "Examples";33examples.Location = null;34examples.Id = "examples-1";35examples.Comments = null;36examples.KeywordType = Gherkin.Ast.KeywordType.Examples;37examples.ToString();38examples.GetType();39var examplesBuilder = new Gherkin.Ast.ExamplesBuilder();40examplesBuilder.SetName("test");41examplesBuilder.SetTableHeader(null);42examplesBuilder.SetTableBody(null);43examplesBuilder.SetDescription(null);44examplesBuilder.SetTags(null);45examplesBuilder.SetKeyword("Examples");46examplesBuilder.SetLocation(null);47examplesBuilder.SetId("examples-1");48examplesBuilder.SetComments(null);49examplesBuilder.SetKeywordType(Gherkin.Ast.KeywordType.Examples);50examplesBuilder.Build();51var examples = new Gherkin.Ast.Examples();52examples.Name = "test";53examples.TableHeader = null;54examples.TableBody = null;55examples.Description = null;

Full Screen

Full Screen

Examples

Using AI Code Generation

copy

Full Screen

1Examples examples = new Examples();2examples.Name = "test";3examples.Description = "test description";4examples.Keyword = "test keyword";5examples.TableHeader = new TableRow();6examples.TableHeader.Cells = new List<TableCell>() { new TableCell() { Value = "test" } };7examples.TableBody = new List<TableRow>() { new TableRow() { Cells = new List<TableCell>() { new TableCell() { Value = "test" } } } };8examples.Tags = new List<Tag>() { new Tag() { Name = "test" } };9examples.Id = "test";10examples.Location = new Location();11examples.Location.Column = 1;12examples.Location.Line = 1;13examples.Keyword = "test keyword";14Examples examples = new Examples();15examples.Name = "test";16examples.Description = "test description";17examples.Keyword = "test keyword";18examples.TableHeader = new TableRow();19examples.TableHeader.Cells = new List<TableCell>() { new TableCell() { Value = "test" } };20examples.TableBody = new List<TableRow>() { new TableRow() { Cells = new List<TableCell>() { new TableCell() { Value = "test" } } } };21examples.Tags = new List<Tag>() { new Tag() { Name = "test" } };22examples.Id = "test";23examples.Location = new Location();24examples.Location.Column = 1;25examples.Location.Line = 1;26examples.Keyword = "test keyword";27Examples examples = new Examples();28examples.Name = "test";29examples.Description = "test description";30examples.Keyword = "test keyword";31examples.TableHeader = new TableRow();32examples.TableHeader.Cells = new List<TableCell>() { new TableCell() { Value = "test" } };33examples.TableBody = new List<TableRow>() { new TableRow() { Cells = new List<TableCell>() { new TableCell() { Value = "test" } } } };34examples.Tags = new List<Tag>() { new Tag() { Name = "test" } };

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 Examples

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful