How to use DocString class of Gherkin.CucumberMessages.Types package

Best Gherkin-dotnet code snippet using Gherkin.CucumberMessages.Types.DocString

AstMessagesConverter.cs

Source:AstMessagesConverter.cs Github

copy

Full Screen

...10using Location = Gherkin.CucumberMessages.Types.Location;11using Rule = Gherkin.CucumberMessages.Types.Rule;12using Step = Gherkin.CucumberMessages.Types.Step;13using DataTable = Gherkin.CucumberMessages.Types.DataTable;14using DocString = Gherkin.CucumberMessages.Types.DocString;15using GherkinDocument = Gherkin.CucumberMessages.Types.GherkinDocument;16using Scenario = Gherkin.CucumberMessages.Types.Scenario;17using TableCell = Gherkin.CucumberMessages.Types.TableCell;18using TableRow = Gherkin.CucumberMessages.Types.TableRow;19using Tag = Gherkin.CucumberMessages.Types.Tag;20namespace Gherkin.CucumberMessages21{22 public class AstMessagesConverter23 {24 private readonly IIdGenerator _idGenerator;25 public AstMessagesConverter(IIdGenerator idGenerator)26 {27 _idGenerator = idGenerator;28 }29 public GherkinDocument ConvertGherkinDocumentToEventArgs(Ast.GherkinDocument gherkinDocument, string sourceEventUri)30 {31 return new GherkinDocument()32 {33 Uri = sourceEventUri,34 Feature = ConvertFeature(gherkinDocument),35 Comments = ConvertComments(gherkinDocument)36 };37 }38 private IReadOnlyCollection<Comment> ConvertComments(Ast.GherkinDocument gherkinDocument)39 {40 return gherkinDocument.Comments.Select(c =>41 new Comment()42 {43 Text = c.Text,44 Location = ConvertLocation(c.Location)45 }).ToReadOnlyCollection();46 }47 private Feature ConvertFeature(Ast.GherkinDocument gherkinDocument)48 {49 var feature = gherkinDocument.Feature;50 if (feature == null)51 {52 return null;53 }54 var children = feature.Children.Select(ConvertToFeatureChild).ToReadOnlyCollection();55 var tags = feature.Tags.Select(ConvertTag).ToReadOnlyCollection();56 return new Feature()57 {58 Name = CucumberMessagesDefaults.UseDefault(feature.Name, CucumberMessagesDefaults.DefaultName),59 Description = CucumberMessagesDefaults.UseDefault(feature.Description, CucumberMessagesDefaults.DefaultDescription),60 Keyword = feature.Keyword,61 Language = feature.Language,62 Location = ConvertLocation(feature.Location),63 Children = children,64 Tags = tags65 };66 }67 private static Location ConvertLocation(Ast.Location location)68 {69 return new Location(location.Column, location.Line);70 }71 private FeatureChild ConvertToFeatureChild(IHasLocation hasLocation)72 {73 var tuple = ConvertToChild(hasLocation);74 return new FeatureChild(tuple.Item3, tuple.Item1, tuple.Item2);75 }76 77 private RuleChild ConvertToRuleChild(IHasLocation hasLocation)78 {79 var tuple = ConvertToChild(hasLocation);80 return new RuleChild(tuple.Item1, tuple.Item3);81 }82 83 private Tuple<Background, Rule, Scenario> ConvertToChild(IHasLocation hasLocation)84 {85 switch (hasLocation)86 {87 case Gherkin.Ast.Background background:88 var backgroundSteps = background.Steps.Select(ConvertStep).ToList();89 return new Tuple<Background, Rule, Scenario>(new Background90 {91 Id = _idGenerator.GetNewId(),92 Location = ConvertLocation(background.Location),93 Name = CucumberMessagesDefaults.UseDefault(background.Name, CucumberMessagesDefaults.DefaultName),94 Description = CucumberMessagesDefaults.UseDefault(background.Description, CucumberMessagesDefaults.DefaultDescription),95 Keyword = background.Keyword,96 Steps = backgroundSteps97 }, null, null);98 case Ast.Scenario scenario:99 var steps = scenario.Steps.Select(ConvertStep).ToList();100 var examples = scenario.Examples.Select(ConvertExamples).ToReadOnlyCollection();101 var tags = scenario.Tags.Select(ConvertTag).ToReadOnlyCollection();102 return new Tuple<Background, Rule, Scenario>(null, null, new Scenario()103 {104 Id = _idGenerator.GetNewId(),105 Keyword = scenario.Keyword,106 Location = ConvertLocation(scenario.Location),107 Name = CucumberMessagesDefaults.UseDefault(scenario.Name, CucumberMessagesDefaults.DefaultName),108 Description = CucumberMessagesDefaults.UseDefault(scenario.Description, CucumberMessagesDefaults.DefaultDescription),109 Steps = steps,110 Examples = examples,111 Tags = tags112 });113 case Ast.Rule rule:114 {115 var ruleChildren = rule.Children.Select(ConvertToRuleChild).ToReadOnlyCollection();116 var ruleTags = rule.Tags.Select(ConvertTag).ToReadOnlyCollection();117 return new Tuple<Background, Rule, Scenario>(null, new Rule118 {119 Id = _idGenerator.GetNewId(),120 Name = CucumberMessagesDefaults.UseDefault(rule.Name, CucumberMessagesDefaults.DefaultName),121 Description = CucumberMessagesDefaults.UseDefault(rule.Description, CucumberMessagesDefaults.DefaultDescription),122 Keyword = rule.Keyword,123 Children = ruleChildren,124 Location = ConvertLocation(rule.Location),125 Tags = ruleTags126 }, null);127 }128 default:129 throw new NotImplementedException();130 }131 }132 private Examples ConvertExamples(Ast.Examples examples)133 {134 var header = ConvertTableHeader(examples);135 var body = ConvertToTableBody(examples);136 var tags = examples.Tags.Select(ConvertTag).ToReadOnlyCollection();137 return new Examples()138 {139 Id = _idGenerator.GetNewId(),140 Name = CucumberMessagesDefaults.UseDefault(examples.Name, CucumberMessagesDefaults.DefaultName),141 Keyword = examples.Keyword,142 Description = CucumberMessagesDefaults.UseDefault(examples.Description, CucumberMessagesDefaults.DefaultDescription),143 Location = ConvertLocation(examples.Location),144 TableHeader = header,145 TableBody = body,146 Tags = tags147 };148 }149 private IReadOnlyCollection<TableRow> ConvertToTableBody(Ast.Examples examples)150 {151 if (examples.TableBody == null)152 return new List<TableRow>();153 return ConvertToTableRow(examples.TableBody);154 }155 private IReadOnlyCollection<TableRow> ConvertToTableRow(IEnumerable<Gherkin.Ast.TableRow> rows)156 {157 return rows.Select(b =>158 new TableRow159 {160 Id = _idGenerator.GetNewId(),161 Location = ConvertLocation(b.Location),162 Cells = b.Cells.Select(ConvertCell).ToReadOnlyCollection()163 }).ToReadOnlyCollection();164 }165 private TableRow ConvertTableHeader(Ast.Examples examples)166 {167 if (examples.TableHeader == null)168 return null;169 return new TableRow170 {171 Id = _idGenerator.GetNewId(),172 Location = ConvertLocation(examples.TableHeader.Location),173 Cells = examples.TableHeader.Cells.Select(ConvertCell).ToReadOnlyCollection()174 };175 }176 private Tag ConvertTag(Ast.Tag tag)177 {178 return new Tag179 {180 Id = _idGenerator.GetNewId(),181 Location = ConvertLocation(tag.Location),182 Name = tag.Name183 };184 }185 private TableCell ConvertCell(Ast.TableCell c)186 {187 return new TableCell()188 {189 Value = CucumberMessagesDefaults.UseDefault(c.Value, CucumberMessagesDefaults.DefaultCellValue),190 Location = ConvertLocation(c.Location)191 };192 }193 private Step ConvertStep(Ast.Step step)194 {195 DataTable dataTable = null;196 if (step.Argument is Gherkin.Ast.DataTable astDataTable) 197 {198 var rows = ConvertToTableRow(astDataTable.Rows);199 dataTable = new DataTable200 {201 Rows = rows,202 Location = ConvertLocation(astDataTable.Location)203 };204 }205 DocString docString = null;206 if (step.Argument is Gherkin.Ast.DocString astDocString) 207 {208 docString = new DocString209 {210 Content = astDocString.Content,211 MediaType = astDocString.ContentType,212 Delimiter = astDocString.Delimiter ?? "\"\"\"", //TODO: store DocString delimiter in Gherkin AST213 Location = ConvertLocation(astDocString.Location)214 };215 }216 return new Step()217 {218 Id = _idGenerator.GetNewId(),219 Keyword = step.Keyword,220 Text = step.Text,221 DataTable = dataTable,222 DocString = docString,223 Location = ConvertLocation(step.Location)224 };225 }226 }227}...

Full Screen

Full Screen

PickleCompiler.cs

Source:PickleCompiler.cs Github

copy

Full Screen

...180 {181 DataTable = new PickleTable(newRows)182 };183 }184 if (step.DocString != null) {185 var ds = step.DocString;186 return187 new PickleStepArgument188 {189 DocString = new PickleDocString(190 Interpolate(ds.Content, variableCells, valueCells),191 ds.MediaType == null ? null : Interpolate(ds.MediaType, variableCells, valueCells))192 };193 } 194 195 return null;196 }197 protected virtual PickleStep[] PickleSteps(IEnumerable<Step> steps)198 {199 var result = new List<PickleStep>();200 foreach(var step in steps)201 {202 result.Add(PickleStep(step));203 }...

Full Screen

Full Screen

Step.cs

Source:Step.cs Github

copy

Full Screen

...9 public string Keyword { get; set; }10 [DataMember(Name = "text")]11 public string Text { get; set; }12 [DataMember(Name = "docString")]13 public DocString DocString { get; set; }14 [DataMember(Name = "dataTable")]15 public DataTable DataTable { get; set; }16 [DataMember(Name = "id")]17 public string Id { get; set; }18 }19}...

Full Screen

Full Screen

DocString.cs

Source:DocString.cs Github

copy

Full Screen

1using System.Runtime.Serialization;23namespace Gherkin.CucumberMessages.Types4{5 public class DocString6 {7 [DataMember(Name = "location")]8 public Location Location { get; set; }910 [DataMember(Name = "mediaType")]11 public string MediaType { get; set; }1213 [DataMember(Name = "content")]14 public string Content { get; set; }1516 [DataMember(Name = "delimiter")]17 public string Delimiter { get; set; }18 }19}

Full Screen

Full Screen

PickleStepArgument.cs

Source:PickleStepArgument.cs Github

copy

Full Screen

...3{4 public class PickleStepArgument5 {6 [DataMember(Name = "docString")]7 public PickleDocString DocString { get; set; }8 [DataMember(Name = "dataTable")]9 public PickleTable DataTable { get; set; }10 }11}...

Full Screen

Full Screen

DocString

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.CucumberMessages.Types;7{8 {9 public override string ToString()10 {11 return Content;12 }13 }14}15using System;16using System.Collections.Generic;17using System.Linq;18using System.Text;19using System.Threading.Tasks;20using Gherkin.CucumberMessages.Types;21{22 {23 public override string ToString()24 {25 StringBuilder sb = new StringBuilder();26 foreach (var row in Rows)27 {28 foreach (var cell in row.Cells)29 {30 sb.Append(cell.Value);31 }32 sb.Append(Environment.NewLine);33 }34 return sb.ToString();35 }36 }37}38using System;39using System.Collections.Generic;40using System.Linq;41using System.Text;42using System.Threading.Tasks;43using Gherkin.CucumberMessages.Types;44{45 {46 public override string ToString()47 {48 if (DocString != null)49 {50 return DocString.ToString();51 }52 else if (DataTable != null)53 {54 return DataTable.ToString();55 }56 {57 return string.Empty;58 }59 }60 }61}62using System;63using System.Collections.Generic;64using System.Linq;65using System.Text;66using System.Threading.Tasks;67using Gherkin.CucumberMessages.Types;68{69 {70 public override string ToString()71 {72 return Text + Environment.NewLine + Argument.ToString();73 }74 }75}76using System;77using System.Collections.Generic;78using System.Linq;79using System.Text;80using System.Threading.Tasks;81using Gherkin.CucumberMessages.Types;82{

Full Screen

Full Screen

DocString

Using AI Code Generation

copy

Full Screen

1using Gherkin.CucumberMessages.Types;2using System;3{4 {5 static void Main(string[] args)6 {7 DocString docString = new DocString();8 docString.ContentType = "text/plain";9 docString.Content = "Hello World";10 Console.WriteLine(docString.Content);11 }12 }13}

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful