Best Gherkin-dotnet code snippet using Gherkin.Ast.DataTable.DataTable
DeveroomTagParser.cs
Source:DeveroomTagParser.cs  
...117                stepTag.AddChild(118                    new DeveroomTag(DeveroomTagTypes.StepKeyword,119                        GetTextSpan(fileSnapshot, step.Location, step.Keyword),120                        step.Keyword));121                if (step.Argument is DataTable dataTable)122                {123                    var dataTableBlockTag = new DeveroomTag(DeveroomTagTypes.DataTable,124                        GetBlockSpan(fileSnapshot, dataTable.Rows.First().Location,125                            dataTable.Rows.Last().Location.Line),126                        dataTable);127                    stepTag.AddChild(dataTableBlockTag);128                    var dataTableHeader = dataTable.Rows.FirstOrDefault();129                    if (dataTableHeader != null)130                    {131                        TagRowCells(fileSnapshot, dataTableHeader, dataTableBlockTag, DeveroomTagTypes.DataTableHeader);132                    }133                }134                else if (step.Argument is DocString docString)135                {136                    stepTag.AddChild(137                        new DeveroomTag(DeveroomTagTypes.DocString,138                            GetBlockSpan(fileSnapshot, docString.Location,139                                GetStepLastLine(step)),140                            docString));141                }142                if (scenarioDefinition is ScenarioOutline)143                {144                    AddPlaceholderTags(fileSnapshot, stepTag, step);145                }146                var match = bindingRegistry?.MatchStep(step, scenarioDefinitionTag);147                if (match != null)148                {149                    if (match.HasDefined || match.HasAmbiguous)150                    {151                        stepTag.AddChild(new DeveroomTag(DeveroomTagTypes.DefinedStep,152                            GetTextSpan(fileSnapshot, step.Location, step.Text, offset: step.Keyword.Length),153                            match));154                        if (!(scenarioDefinition is ScenarioOutline) || !step.Text.Contains("<"))155                        {156                            var parameterMatch = match.Items.FirstOrDefault(m => m.ParameterMatch != null)157                                ?.ParameterMatch;158                            AddParameterTags(fileSnapshot, parameterMatch, stepTag, step);159                        }160                    }161                    if (match.HasUndefined)162                    {163                        stepTag.AddChild(new DeveroomTag(DeveroomTagTypes.UndefinedStep,164                            GetTextSpan(fileSnapshot, step.Location, step.Text, offset: step.Keyword.Length),165                            match));166                    }167                    if (match.HasErrors)168                    {169                        stepTag.AddChild(new DeveroomTag(DeveroomTagTypes.BindingError,170                            GetTextSpan(fileSnapshot, step.Location, step.Text, offset: step.Keyword.Length),171                            match.GetErrorMessage()));172                    }173                }174            }175            if (scenarioDefinition is ScenarioOutline scenarioOutline)176            {177                foreach (var scenarioOutlineExample in scenarioOutline.Examples)178                {179                    var examplesBlockTag = CreateDefinitionBlockTag(scenarioOutlineExample,180                        DeveroomTagTypes.ExamplesBlock, fileSnapshot,181                        GetExamplesLastLine(scenarioOutlineExample), scenarioDefinitionTag);182                    if (scenarioOutlineExample.TableHeader != null)183                    {184                        TagRowCells(fileSnapshot, scenarioOutlineExample.TableHeader, examplesBlockTag,185                            DeveroomTagTypes.ScenarioOutlinePlaceholder);186                    }187                }188            }189        }190        private void TagRowCells(ITextSnapshot fileSnapshot, TableRow row, DeveroomTag parentTag, string tagType)191        {192            foreach (var cell in row.Cells)193            {194                parentTag.AddChild(new DeveroomTag(tagType,195                    GetSpan(fileSnapshot, cell.Location, cell.Value.Length),196                    cell));197            }198        }199        private void AddParameterTags(ITextSnapshot fileSnapshot, ParameterMatch parameterMatch, DeveroomTag stepTag, Step step)200        {201            foreach (var parameter in parameterMatch.StepTextParameters)202            {203                stepTag.AddChild(new DeveroomTag(DeveroomTagTypes.StepParameter,204                    GetSpan(fileSnapshot, step.Location, parameter.Length, offset: step.Keyword.Length + parameter.Index),205                    parameter));206            }207        }208        private void AddPlaceholderTags(ITextSnapshot fileSnapshot, DeveroomTag stepTag, Step step)209        {210            var placeholders = MatchedScenarioOutlinePlaceholder.MatchScenarioOutlinePlaceholders(step);211            foreach (var placeholder in placeholders)212            {213                stepTag.AddChild(new DeveroomTag(DeveroomTagTypes.ScenarioOutlinePlaceholder,214                    GetSpan(fileSnapshot, step.Location, placeholder.Length, offset: step.Keyword.Length + placeholder.Index),215                    placeholder));216            }217        }218        private DeveroomTag CreateDefinitionBlockTag(IHasDescription astNode, string tagType, ITextSnapshot fileSnapshot, int lastLine, DeveroomTag parentTag = null)219        {220            var span = GetBlockSpan(fileSnapshot, ((IHasLocation)astNode).Location, lastLine);221            var blockTag = new DeveroomTag(tagType, span, astNode);222            parentTag?.AddChild(blockTag);223            blockTag.AddChild(CreateDefinitionLineKeyword(fileSnapshot, astNode));224            if (astNode is IHasTags hasTags)225            {226                foreach (var gherkinTag in hasTags.Tags)227                {228                    blockTag.AddChild(229                        new DeveroomTag(DeveroomTagTypes.Tag,230                            GetTextSpan(fileSnapshot, gherkinTag.Location, gherkinTag.Name), 231                            gherkinTag));232                }233            }234            if (!string.IsNullOrEmpty(astNode.Description))235            {236                var startLineNumber = ((IHasLocation) astNode).Location.Line + 1;237                while (string.IsNullOrWhiteSpace(fileSnapshot.GetLineFromLineNumber(GetSnapshotLineNumber(startLineNumber, fileSnapshot)).GetText()))238                {239                    startLineNumber++;240                }241                blockTag.AddChild(242                    new DeveroomTag(DeveroomTagTypes.Description,243                        GetBlockSpan(fileSnapshot, startLineNumber,244                            CountLines(astNode.Description))));245            }246            return blockTag;247        }248        private static readonly Regex NewLineRe = new Regex(@"(\r\n|\n|\r)");249        private int CountLines(string text) =>250            NewLineRe.Matches(text).Count + 1;251        private DeveroomTag CreateDefinitionLineKeyword(ITextSnapshot fileSnapshot, IHasDescription hasDescription) =>252            new DeveroomTag(DeveroomTagTypes.DefinitionLineKeyword,253                GetTextSpan(fileSnapshot, ((IHasLocation)hasDescription).Location, hasDescription.Keyword, 1));254        private IEnumerable<DeveroomTag> GetAllTags(DeveroomTag tag)255        {256            yield return tag;257            foreach (var childTag in tag.ChildTags)258            foreach (var allChildTag in GetAllTags(childTag))259                yield return allChildTag;260        }261        private int GetScenarioDefinitionLastLine(StepsContainer stepsContainer)262        {263            if (stepsContainer is ScenarioOutline scenarioOutline)264            {265                var lastExamples = scenarioOutline.Examples.LastOrDefault();266                if (lastExamples != null)267                {268                    return GetExamplesLastLine(lastExamples);269                }270            }271            var lastStep = stepsContainer.Steps.LastOrDefault();272            if (lastStep == null)273                return stepsContainer.Location.Line;274            return GetStepLastLine(lastStep);275        }276        private static int GetExamplesLastLine(Examples examples)277        {278            var lastRow = examples.TableBody?.LastOrDefault() ?? examples.TableHeader;279            if (lastRow != null)280                return lastRow.Location.Line;281            return examples.Location.Line;282        }283        private int GetStepLastLine(Step step)284        {285            if (step.Argument is DocString docStringArg)286            {287                int lineCount = CountLines(docStringArg.Content);288                return docStringArg.Location.Line + lineCount - 1 + 2;289            }290            if (step.Argument is DataTable dataTable)291            {292                return dataTable.Rows.Last().Location.Line;293            }294            return step.Location.Line;295        }296        private SnapshotSpan GetBlockSpan(ITextSnapshot snapshot, Location startLocation, int locationEndLine)297        {298            var startLine = GetSnapshotLine(startLocation, snapshot);299            var endLine = snapshot.GetLineFromLineNumber(GetSnapshotLineNumber(locationEndLine, snapshot));300            return new SnapshotSpan(startLine.Start, endLine.End);301        }302        private SnapshotSpan GetBlockSpan(ITextSnapshot snapshot, int startLineNumber, int lineCount)303        {304            var startLine = snapshot.GetLineFromLineNumber(GetSnapshotLineNumber(startLineNumber, snapshot));...StepMethodInfoTests.cs
Source:StepMethodInfoTests.cs  
...147            [When("something")]148            public void When_Something_Method() { }149        }150        [Fact]151        public void FromMethodInfo_Creates_StepMethodInfo_With_DataTable()152        {153            //arrange.154            var featureInstance = new FeatureWithDataTableScenarioStep();155            //act.156            var sut = StepMethodInfo.FromMethodInfo(157                featureInstance.GetType().GetMethod(nameof(FeatureWithDataTableScenarioStep.When_DataTable_Is_Expected)),158                featureInstance159                );160            //assert.161            Assert.NotNull(sut);162        }163        [Fact]164        public void DigestScenarioStepValues_Sets_DataTable_Value()165        {166            //arrange.167            var featureInstance = new FeatureWithDataTableScenarioStep();168            var sut = StepMethodInfo.FromMethodInfo(169                featureInstance.GetType().GetMethod(nameof(FeatureWithDataTableScenarioStep.When_DataTable_Is_Expected)),170                featureInstance171                );172            var step = new Gherkin.Ast.Step(173                null,174                "When",175                FeatureWithDataTableScenarioStep.Steptext,176                new Gherkin.Ast.DataTable(new Gherkin.Ast.TableRow[]177            {178                new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]179                {180                    new Gherkin.Ast.TableCell(null, "First argument"),181                    new Gherkin.Ast.TableCell(null, "Second argument"),182                    new Gherkin.Ast.TableCell(null, "Result"),183                }),184                new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]185                {186                    new Gherkin.Ast.TableCell(null, "1"),187                    new Gherkin.Ast.TableCell(null, "2"),188                    new Gherkin.Ast.TableCell(null, "3"),189                }),190                new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]191                {192                    new Gherkin.Ast.TableCell(null, "a"),193                    new Gherkin.Ast.TableCell(null, "b"),194                    new Gherkin.Ast.TableCell(null, "c"),195                })196            }));197            //act.198            sut.DigestScenarioStepValues(step);199            //assert.200            var digestedText = sut.GetDigestedStepText();201            Assert.Equal(FeatureWithDataTableScenarioStep.Steptext, digestedText);202        }203        private sealed class FeatureWithDataTableScenarioStep : Feature204        {205            public Gherkin.Ast.DataTable ReceivedDataTable { get; private set; }206            public const string Steptext = "Some step text";207            [When(Steptext)]208            public void When_DataTable_Is_Expected(Gherkin.Ast.DataTable dataTable)209            {210                ReceivedDataTable = dataTable;211            }212        }213        [Fact]214        public void FromMethodInfo_Creates_StepMethodInfo_With_DocString()215        {216            //arrange.217            var featureInstance = new FeatureWithDocStringScenarioStep();218            //act.219            var sut = StepMethodInfo.FromMethodInfo(220                featureInstance.GetType().GetMethod(nameof(FeatureWithDocStringScenarioStep.Step_With_DocString_Argument)),221                featureInstance222                );223            //assert.224            Assert.NotNull(sut);...FeatureClassTests.cs
Source:FeatureClassTests.cs  
...193                CallStack.Add(new KeyValuePair<string, object[]>(nameof(NonMatchingStep4_after), null));194            }195        }196        [Fact]197        public void ExtractScnario_Extracts_Scenario_With_DataTable()198        {199            //arrange.200            var scenarioName = "scenario213";201            var featureInstance = new FeatureWithDataTableScenarioStep();202            var sut = FeatureClass.FromFeatureInstance(featureInstance);203            var gherknScenario = CreateGherkinDocument(scenarioName,204                    new string[]205                    {206                        "When " + FeatureWithDataTableScenarioStep.Steptext207                    },208                    new Gherkin.Ast.DataTable(new Gherkin.Ast.TableRow[]209                    {210                        new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]211                        {212                            new Gherkin.Ast.TableCell(null, "First argument"),213                            new Gherkin.Ast.TableCell(null, "Second argument"),214                            new Gherkin.Ast.TableCell(null, "Result"),215                        }),216                        new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]217                        {218                            new Gherkin.Ast.TableCell(null, "1"),219                            new Gherkin.Ast.TableCell(null, "2"),220                            new Gherkin.Ast.TableCell(null, "3"),221                        }),222                        new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]223                        {224                            new Gherkin.Ast.TableCell(null, "a"),225                            new Gherkin.Ast.TableCell(null, "b"),226                            new Gherkin.Ast.TableCell(null, "c"),227                        })228                    })).Feature.Children.First() as Gherkin.Ast.Scenario;229            //act.230            var scenario = sut.ExtractScenario(gherknScenario);231            //assert.232            Assert.NotNull(scenario);233        }234        private sealed class FeatureWithDataTableScenarioStep : Feature235        {236            public Gherkin.Ast.DataTable ReceivedDataTable { get; private set; }237            public const string Steptext = "Some step text";238            [When(Steptext)]239            public void When_DataTable_Is_Expected(Gherkin.Ast.DataTable dataTable)240            {241                ReceivedDataTable = dataTable;242            }243        }244        [Fact]245        public void ExtractScenario_Extracts_Scenario_With_DocString()246        {247            //arrange.248            var featureInstance = new FeatureWithDocStringScenarioStep();249            var sut = FeatureClass.FromFeatureInstance(featureInstance);250            var scenarioName = "scenario-121kh2";251            var docStringContent = @"some content252    +++253    with multi lines254    ---255    in it";...GherkinScenarioOutlineTests.cs
Source:GherkinScenarioOutlineTests.cs  
...162                Assert.Equal(text, step.Text);163            }164        }165        [Fact]166        public void ApplyExampleRow_Digests_Row_Values_Into_Scenario_With_DataTable_In_Step()167        {168            //arrange.169            var sut = new Gherkin.Ast.ScenarioOutline(170                null,171                null,172                null,173                "outline123",174                null,175                new Gherkin.Ast.Step[]176                {177                    new Gherkin.Ast.Step(null, "Given", "I pass a datatable with tokens", new DataTable(new []178                    {179                        new TableRow(null, new[] { new TableCell(null, "Column1"), new TableCell(null, "Column2") }),180                        new TableRow(null, new[] { new TableCell(null, "<a>"), new TableCell(null, "data with <b> in the middle") }),181                        new TableRow(null, new[] { new TableCell(null, "<b>"), new TableCell(null, "<a>") })182                    })),183                    new Gherkin.Ast.Step(null, "When", "I apply a sample row", null),184                    new Gherkin.Ast.Step(null, "Then", "the data table should be populated", null),185                },186                new Gherkin.Ast.Examples[]187                {188                    new Gherkin.Ast.Examples(189                        null,190                        null,191                        null,192                        "existing example",193                        null,194                        new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]195                        {196                            new Gherkin.Ast.TableCell(null, "a"),197                            new Gherkin.Ast.TableCell(null, "b"),198                        }),199                        new Gherkin.Ast.TableRow[]200                        {201                            new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]202                            {203                                new Gherkin.Ast.TableCell(null, "1"),204                                new Gherkin.Ast.TableCell(null, "2")205                            })206                        })207                });208            //act.209            var scenario = sut.ApplyExampleRow("existing example", 0);210            //assert.211            Assert.NotNull(scenario);212            Assert.Equal(sut.Name, scenario.Name);213            Assert.Equal(sut.Steps.Count(), scenario.Steps.Count());214            Assert.Equal(3, scenario.Steps.Count());215            var scenarioSteps = scenario.Steps.ToList();216            Assert.IsType<DataTable>(scenarioSteps[0].Argument);217            var dataTable = (DataTable)scenarioSteps[0].Argument;218            var rows = dataTable.Rows.ToList();219            ValidateRow(rows[0], "Column1", "Column2");220            ValidateRow(rows[1], "1", "data with 2 in the middle");221            ValidateRow(rows[2], "2", "1");222            void ValidateRow(TableRow row, string expectedColumn0Value, string expectedColumn1Value)223            {224                var cells = row.Cells.ToArray();225                Assert.Equal(cells[0].Value, expectedColumn0Value);226                Assert.Equal(cells[1].Value, expectedColumn1Value);227            }228        }229    }230}...GherkinScenarioOutlineExtensions.cs
Source:GherkinScenarioOutlineExtensions.cs  
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text.RegularExpressions;5using DataTable = Gherkin.Ast.DataTable;6using TableRow = Gherkin.Ast.TableRow;7using TableCell = Gherkin.Ast.TableCell;8namespace Xunit.Gherkin.Quick9{10    internal static class GherkinScenarioOutlineExtensions11    {12        private static readonly Regex _placeholderRegex = new Regex(@"<([^>]+)>");13        public static global::Gherkin.Ast.Scenario ApplyExampleRow(14            this global::Gherkin.Ast.ScenarioOutline @this,15            string exampleName,16            int exampleRowIndex)17        {18            var examples = @this.Examples.FirstOrDefault(e => e.Name == exampleName);19            if (examples == null)20                throw new InvalidOperationException($"Cannot find examples named `{exampleName}` in scenario outline `{@this.Name}`.");21            var exampleRow = GetExampleRow(@this, exampleRowIndex, examples);22            var rowValues = GetExampleRowValues(examples, exampleRow);23            var scenarioSteps = new List<global::Gherkin.Ast.Step>();24            foreach (var outlineStep in @this.Steps)25            {26                var scenarioStep = DigestExampleValuesIntoStep(27                    @this, 28                    exampleName, 29                    exampleRowIndex, 30                    rowValues, 31                    outlineStep);32                scenarioSteps.Add(scenarioStep);33            }34            return new global::Gherkin.Ast.Scenario(35                @this.Tags?.ToArray(),36                @this.Location,37                @this.Keyword,38                @this.Name,39                @this.Description,40                scenarioSteps.ToArray());41        }42        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)43        {44            string matchEvaluator(Match match)45            {46                var placeholderKey = match.Groups[1].Value;47                if (!rowValues.ContainsKey(placeholderKey))48                    throw new InvalidOperationException($"Examples table did not provide value for `{placeholderKey}`. Scenario outline: `{@this.Name}`. Examples: `{exampleName}`. Row index: {exampleRowIndex}.");49                var placeholderValue = rowValues[placeholderKey];50                return placeholderValue;51            }52            var stepText = _placeholderRegex.Replace(outlineStep.Text, matchEvaluator);53            var stepArgument = outlineStep.Argument;54            if (stepArgument is DataTable)55            {56                var processedHeaderRow = false;57                var digestedRows = new List<TableRow>();58                59                foreach(var row in ((DataTable)stepArgument).Rows)60                {61                    if (!processedHeaderRow)62                    {63                        digestedRows.Add(row);64                        processedHeaderRow = true;65                    }66                    else67                    {68                        var digestedCells = row.Cells.Select(r => new TableCell(r.Location, _placeholderRegex.Replace(r.Value, matchEvaluator)));69                        digestedRows.Add(new TableRow(row.Location, digestedCells.ToArray()));70                    }71                }72                stepArgument = new DataTable(digestedRows.ToArray());73            }74            var scenarioStep = new global::Gherkin.Ast.Step(75                outlineStep.Location,76                outlineStep.Keyword,77                stepText,78                stepArgument);79            return scenarioStep;80        }81        private static Dictionary<string, string> GetExampleRowValues(global::Gherkin.Ast.Examples examples, List<global::Gherkin.Ast.TableCell> exampleRowCells)82        {83            var rowValues = new Dictionary<string, string>();84            var headerCells = examples.TableHeader.Cells.ToList();85            for (int index = 0; index < headerCells.Count; index++)86            {...DataTableArgumentTests.cs
Source:DataTableArgumentTests.cs  
...3using Xunit;4using Xunit.Gherkin.Quick;5namespace UnitTests6{7    public sealed class DataTableArgumentTests8    {9        [Fact]10        public void DigestScenarioStepValues_Throws_Error_If_No_Arguments_And_No_DataTable()11        {12            //arrange.13            var sut = new DataTableArgument();14            //act / assert.15            Assert.Throws<InvalidOperationException>(() => sut.DigestScenarioStepValues(new string[0], null));16        }17        [Fact]18        public void DigestScenarioStepValues_Throws_Error_If_Arguments_Present_But_No_DataTable()19        {20            //arrange.21            var sut = new DataTableArgument();22            //act / assert.23            Assert.Throws<InvalidOperationException>(() => sut.DigestScenarioStepValues(new string[] { "1", "2", "3" }, null));24        }25        [Fact]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()90        {91            //arrange.92            var sut = new DataTableArgument();93            var other = new DataTableArgument();94            //act.95            var same = sut.IsSameAs(other);96            //assert.97            Assert.True(same);98        }99        [Fact]100        public void IsSameAs_Distinguishes_Different_Instances()101        {102            //arrange.103            var sut = new DataTableArgument();104            var other = new Mock<StepMethodArgument>().Object;105            //act.106            var same = sut.IsSameAs(other);107            //assert.108            Assert.False(same);109        }110        [Fact]111        public void Clone_Creates_Similar_Instance()112        {113            //arrange.114            var sut = new DataTableArgument();115            //act.116            var clone = sut.Clone();117            //assert.118            Assert.True(clone.IsSameAs(sut));119            Assert.NotSame(clone, sut);120        }121    }122}...GherkinDataProvider.cs
Source:GherkinDataProvider.cs  
...23                {24                    foreach (var step in scenarioDefinition.Steps)25                    {26                        var entityName = step.Text.Split('\'')[1];27                        var dataTable = step.Argument as DataTable;28                        var entityDicts = new List<Dictionary<string, string>>();29                        foreach (var row in dataTable.Rows.Skip(1))30                        {31                            var entityDict = TransformEntity(row, dataTable);32                            entityDicts.Add(entityDict);33                        }34                        entities.Add(new EntityData35                        {36                            EntityName = entityName,37                            Objects = entityDicts38                        });39                    }40                }41            }42            return entities;43        }44        private static Dictionary<string, string> TransformEntity(TableRow row, DataTable dataTable)45        {46            var entityDict = new Dictionary<string, string>();47            for (var i = 0; i < row.Cells.Count(); i++)48            {49                var cell = row.Cells.ToList()[i];50                entityDict.Add(dataTable.Rows.First().Cells.ToList()[i].Value, cell.Value);51            }52            return entityDict;53        }54    }55}...DataTableArgument.cs
Source:DataTableArgument.cs  
1using Gherkin.Ast;2using System;3namespace Xunit.Gherkin.Quick4{5    internal sealed class DataTableArgument : StepMethodArgument6    {7        public override StepMethodArgument Clone()8        {9            return new DataTableArgument();10        }11        public override void DigestScenarioStepValues(string[] argumentValues, StepArgument gherkinStepArgument)12        {13            if (!(gherkinStepArgument is DataTable dataTable))14                throw new InvalidOperationException("DataTable cannot be extracted from Gherkin.");15            Value = dataTable;16        }17        public override bool IsSameAs(StepMethodArgument other)18        {19            return other is DataTableArgument;20        }21    }22}...DataTable
Using AI Code Generation
1    [Given(@"I have entered (.*) into the calculator")]2    public void GivenIHaveEnteredIntoTheCalculator(int number)3    {4        ScenarioContext.Current.Pending();5    }6    [Given(@"I have entered the following numbers")]7    public void GivenIHaveEnteredTheFollowingNumbers(Table table)8    {9        foreach (var row in table.Rows)10        {11            Console.WriteLine(row["Number"]);12        }13    }14    [When(@"I press add")]15    public void WhenIPressAdd()16    {17        ScenarioContext.Current.Pending();18    }19    [Then(@"the result should be (.*) on the screen")]20    public void ThenTheResultShouldBeOnTheScreen(int result)21    {22        ScenarioContext.Current.Pending();23    }24}DataTable
Using AI Code Generation
1var dataTable = ScenarioContext.Current.Get<DataTable>("DataTable");2var dataTable = ScenarioContext.Current.Get<DataTable>("DataTable");3var dataTable = ScenarioContext.Current.Get<DataTable>("DataTable");4var dataTable = ScenarioContext.Current.Get<DataTable>("DataTable");5var dataTable = ScenarioContext.Current.Get<DataTable>("DataTable");6var dataTable = ScenarioContext.Current.Get<DataTable>("DataTable");7var dataTable = ScenarioContext.Current.Get<DataTable>("DataTable");8var dataTable = ScenarioContext.Current.Get<DataTable>("DataTable");9var dataTable = ScenarioContext.Current.Get<DataTable>("DataTable");10var dataTable = ScenarioContext.Current.Get<DataTable>("DataTable");DataTable
Using AI Code Generation
1var table = new Gherkin.Ast.DataTable(new List<Gherkin.Ast.TableRow>(), "keyword", "location");2var table2 = new Gherkin.Ast.DataTable(table.Rows, table.Keyword, table.Location);3var table3 = new Gherkin.Ast.DataTable(table.Rows, table.Keyword);4var table4 = new Gherkin.Ast.DataTable(table.Rows);5var table5 = new Gherkin.Ast.DataTable();6var table6 = new Gherkin.Ast.DataTable(table.Rows, table.Keyword, table.Location);7var table7 = new Gherkin.Ast.DataTable(table.Rows, table.Keyword);8var table8 = new Gherkin.Ast.DataTable(table.Rows);9var table9 = new Gherkin.Ast.DataTable();10var tableRow = new Gherkin.Ast.TableRow(new List<Gherkin.Ast.TableCell>(), "location");11var tableRow2 = new Gherkin.Ast.TableRow(tableRow.Cells, tableRow.Location);12var tableRow3 = new Gherkin.Ast.TableRow(tableRow.Cells);13var tableRow4 = new Gherkin.Ast.TableRow();14var tableRow5 = new Gherkin.Ast.TableRow(tableRow.Cells, tableRow.Location);15var tableRow6 = new Gherkin.Ast.TableRow(tableRow.Cells);16var tableRow7 = new Gherkin.Ast.TableRow();17var tableCell = new Gherkin.Ast.TableCell("value", "location");18var tableCell2 = new Gherkin.Ast.TableCell(tableCell.Value, tableCell.Location);19var tableCell3 = new Gherkin.Ast.TableCell(tableCell.Value);20var tableCell4 = new Gherkin.Ast.TableCell();21var tableCell5 = new Gherkin.Ast.TableCell(tableCell.Value, tableCell.Location);22var tableCell6 = new Gherkin.Ast.TableCell(tableCell.Value);23var tableCell7 = new Gherkin.Ast.TableCell();DataTable
Using AI Code Generation
1DataTable dt = new DataTable();2dt = table.AsDataTable();3List<List<string>> list = table.AsList();4List<TableRow> rows = table.Rows;5DataTable dt = new DataTable();6dt = table.AsDataTable();7List<List<string>> list = table.AsList();8List<TableRow> rows = table.Rows;9DataTable dt = new DataTable();10dt = table.AsDataTable();11List<List<string>> list = table.AsList();12List<TableRow> rows = table.Rows;13DataTable dt = new DataTable();14dt = table.AsDataTable();15List<List<string>> list = table.AsList();16List<TableRow> rows = table.Rows;17DataTable dt = new DataTable();18dt = table.AsDataTable();19List<List<string>> list = table.AsList();20List<TableRow> rows = table.Rows;21DataTable dt = new DataTable();22dt = table.AsDataTable();23List<List<string>> list = table.AsList();24List<TableRow> rows = table.Rows;DataTable
Using AI Code Generation
1public void TestMethod1()2{3    var dataTable = new DataTable();4    dataTable.AddRow(new string[] { "Name", "Age" });5    dataTable.AddRow(new string[] { "John", "30" });6    dataTable.AddRow(new string[] { "Mary", "35" });7    dataTable.AddRow(new string[] { "Jane", "40" });8    var table = new Gherkin.Ast.DataTable(dataTable.Rows, dataTable.Header);9    var tableArgument = new Table(table);10}11public void TestMethod2()12{13    var dataTable = new DataTable();14    dataTable.AddRow(new string[] { "Name", "Age" });15    dataTable.AddRow(new string[] { "John", "30" });16    dataTable.AddRow(new string[] { "Mary", "35" });17    dataTable.AddRow(new string[] { "Jane", "40" });18    var table = new Gherkin.Ast.DataTable(dataTable.Rows, dataTable.Header);19    var tableArgument = new Table(table);20}21public void TestMethod3()22{23    var dataTable = new DataTable();24    dataTable.AddRow(new string[] { "Name", "Age" });25    dataTable.AddRow(new string[] { "John", "30" });26    dataTable.AddRow(new string[] { "Mary", "35" });27    dataTable.AddRow(new string[] { "Jane", "40" });28    var table = new Gherkin.Ast.DataTable(dataTable.Rows, dataTable.Header);29    var tableArgument = new Table(table);30}31public void TestMethod4()32{33    var dataTable = new DataTable();34    dataTable.AddRow(new string[] { "Name", "Age" });35    dataTable.AddRow(new string[] { "John", "30" });36    dataTable.AddRow(new string[] { "Mary", "35" });37    dataTable.AddRow(new string[] { "Jane", "40" });38    var table = new Gherkin.Ast.DataTable(dataTable.Rows, dataTable.Header);39    var tableArgument = new Table(table);40}DataTable
Using AI Code Generation
1var table = new DataTable();2table.Columns.Add("Name");3table.Columns.Add("Age");4table.Rows.Add("John", 21);5table.Rows.Add("David", 22);6var dt = table.ToDataTable();7var firstRow = dt.Rows[0];8var firstColumn = dt.Columns[0];9var firstCell = dt.Rows[0][0];10var firstCell = dt.Rows[0]["Name"];11var firstCell = dt.Rows[0][0];12var firstCell = dt.Rows[0][0];13var firstCell = dt.Rows[0]["Name"];14var firstCell = dt.Rows[0]["Name"];15var firstCell = dt.Rows[0][0];16var firstCell = dt.Rows[0][0];17var firstCell = dt.Rows[0]["Name"];18var firstCell = dt.Rows[0][0];19var firstCell = dt.Rows[0][0];20var firstCell = dt.Rows[0]["Name"];21var firstCell = dt.Rows[0]["Name"];22var firstCell = dt.Rows[0][0];23var firstCell = dt.Rows[0][0];24var firstCell = dt.Rows[0]["Name"];DataTable
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using Gherkin.Ast;5using TechTalk.SpecFlow;6{7    {8        [Given(@"I have the following table")]9        public void GivenIHaveTheFollowingTable(Table table)10        {11            var dataTable = table.DataTable();12            dataTable.Print();13            Console.WriteLine(dataTable.ToMarkdown());14        }15    }16}17{18    public static DataTable DataTable(this Table table)19    {20        return new DataTable(21            table.Header.ToArray(),22            table.Rows.Select(row => row.Values.ToArray()).ToArray()23        );24    }25}26{27    public static void Print(this DataTable dataTable)28    {29            .Select(row => row.Select(cell => cell.Length))30            .Aggregate(31                dataTable.Header.Select(cell => cell.Length),32                (widths, rowWidths) => widths.Zip(rowWidths, (width, rowWidth) => Math.Max(width, rowWidth))33            );34        var header = string.Join(" | ", dataTable.Header.Zip(tableWidths, (cell, width) => cell.PadRight(width)));35        var separator = string.Join("-+-", tableWidths.Select(width => new string('-', width)));36        Console.WriteLine(header);37        Console.WriteLine(separator);38        foreach (var row in dataTable.Rows)39        {40            var line = string.Join(" | ", row.Zip(tableWidthsLearn 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!!
