Best Gherkin-dotnet code snippet using Gherkin.Ast.Examples
GherkinFeatureTests.cs
Source:GherkinFeatureTests.cs
...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}...
GherkinEntityExtensions.cs
Source:GherkinEntityExtensions.cs
...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()...
DeveroomGherkinParser.cs
Source:DeveroomGherkinParser.cs
...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;...
GherkinScenarioOutlineTests.cs
Source:GherkinScenarioOutlineTests.cs
...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[]...
CompatibleAstConverter.cs
Source:CompatibleAstConverter.cs
...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 }...
AstEventConverter.cs
Source:AstEventConverter.cs
...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,...
GherkinScenarioOutlineExtensions.cs
Source:GherkinScenarioOutlineExtensions.cs
...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}...
GherkinFeatureExtensions.cs
Source:GherkinFeatureExtensions.cs
...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}...
Examples
Using AI Code Generation
1using Gherkin.Ast;2using System;3using System.Collections.Generic;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7{8 {9 static void Main(string[] args)10 {11 Examples obj = new Examples();12 obj.ExampleMethod();13 }14 }15}16using Gherkin.Ast;17using System;18using System.Collections.Generic;19using System.Linq;20using System.Text;21using System.Threading.Tasks;22{23 {24 public void ExampleMethod()25 {26 Examples obj = new Examples();27 obj.ExampleMethod();28 }29 }30}31Error 1 The type or namespace name 'Examples' does not exist in the namespace 'Gherkin.Ast' (are you missing an assembly reference?) C:\Users\Gaurav\Desktop\Gherkin\Gherkin\Program.cs 11 7 Gherkin32using System;33{34 {35 static void Main(string[] args)36 {37 MyClass myClass = new MyClass();38 myClass.MyMethod();39 }40 }41 {42 public void MyMethod()43 {44 Console.WriteLine("Hello World!");45 }46 }47}48I have a class that has a method that is called when a button is clicked. The method is called on a different thread than the UI thread. I would like to be able to update the UI when the method is done. I have tried to use the Dispatcher.Invoke() method but I get an error saying that the thread does not have access to the dispatcher. I have also tried using the Dispatcher.BeginInvoke() method with no luck. How can I update the UI from
Examples
Using AI Code Generation
1using Gherkin.Ast;2using System;3using System.Collections.Generic;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7{8 {9 static void Main(string[] args)10 {11 Examples examples = new Examples(new List<Tag>(), "Examples", "", new List<TableRow>(), new List<TableRow>());12 Console.WriteLine("Keyword: " + examples.Keyword);13 Console.WriteLine("Name: " + examples.Name);14 Console.WriteLine("Description: " + examples.Description);15 Console.WriteLine("Header: " + examples.Header);16 Console.WriteLine("Rows: " + examples.Rows);17 Console.ReadKey();18 }19 }20}
Examples
Using AI Code Generation
1using Gherkin.Ast;2using System;3{4 {5 static void Main(string[] args)6 {7 Console.WriteLine("Hello World!");8 Examples examples = new Examples();9 Console.WriteLine(examples.GetType().Name);10 Console.ReadLine();11 }12 }13}14using Gherkin.Ast;15using System;16{17 {18 static void Main(string[] args)19 {20 Console.WriteLine("Hello World!");21 Examples examples = new Examples();22 Console.WriteLine(examples.GetType().Name);23 Console.WriteLine(examples.GetTableHeader());24 Console.WriteLine(examples.GetTableBody());25 Console.ReadLine();26 }
Examples
Using AI Code Generation
1using Gherkin.Ast;2using System;3{4 {5 static void Main(string[] args)6 {7 Examples ex = new Examples();8 List<TableRow> rows = new List<TableRow>();9 TableRow row = new TableRow();10 row.AddCell(new TableCell("cell1"));11 row.AddCell(new TableCell("cell2"));12 row.AddCell(new TableCell("cell3"));13 row.AddCell(new TableCell("cell4"));14 rows.Add(row);15 ex.SetRows(rows);16 rows = ex.GetRows();17 foreach (TableRow r in rows)18 {19 Console.WriteLine(r);20 }21 }22 }23}
Examples
Using AI Code Generation
1using Gherkin.Ast;2{3 {4 public static void Main()5 {6 var table = new Table(new List<TableRow>7 {8 new TableRow(new List<TableCell>{new TableCell("a"), new TableCell("b")}),9 new TableRow(new List<TableCell>{new TableCell("c"), new TableCell("d")}),10 new TableRow(new List<TableCell>{new TableCell("e"), new TableCell("f")})11 });12 Console.WriteLine(table.ToString());13 }14 }15}16using Gherkin.Ast;17{18 {19 public static void Main()20 {21 var table = new Table(new List<TableRow>22 {23 new TableRow(new List<TableCell>{new TableCell("a"), new TableCell("b")}),24 new TableRow(new List<TableCell>{new TableCell("c"), new TableCell("d")}),25 new TableRow(new List<TableCell>{new TableCell("e"), new TableCell("f")})26 }, new TableRow(new List<TableCell>{new TableCell("h1"), new TableCell("h2")}));27 Console.WriteLine(table.ToString());28 }29 }30}31using Gherkin.Ast;32{33 {34 public static void Main()35 {36 var table = new Table(new Location(1, 1), new List<TableRow>37 {38 new TableRow(new List<TableCell>{new TableCell("a"), new TableCell("b")}),39 new TableRow(new List<TableCell>{new TableCell("c"), new TableCell("d")}),40 new TableRow(new List<TableCell>{new TableCell("e"), new TableCell("f")})41 }, new TableRow(new List<TableCell>{new TableCell("
Examples
Using AI Code Generation
1using Gherkin.Ast;2{3 {4 public static void Main(string[] args)5 {6 Examples examples = new Examples();7 TableHeader tableHeader = new TableHeader();8 TableRow tableRow = new TableRow();9 TableCell tableCell = new TableCell();10 Location location = new Location();11 Tag tag = new Tag();12 GherkinDocument gherkinDocument = new GherkinDocument();13 Feature feature = new Feature();14 Background background = new Background();15 Scenario scenario = new Scenario();16 Step step = new Step();17 DocString docString = new DocString();18 DataTable dataTable = new DataTable();19 Comment comment = new Comment();20 Language language = new Language();21 Pickle pickle = new Pickle();22 PickleStep pickleStep = new PickleStep();23 PickleTable pickleTable = new PickleTable();24 PickleDocString pickleDocString = new PickleDocString();25 PickleLocation pickleLocation = new PickleLocation();26 PickleArgument pickleArgument = new PickleArgument();27 PickleTag pickleTag = new PickleTag();28 PickleRow pickleRow = new PickleRow();29 PickleCell pickleCell = new PickleCell();
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!