Esempio n. 1
0
        public TableRow MapToTableRow(G.TableRow tableRow)
        {
            if (tableRow == null)
            {
                return null;
            }

            return new TableRow(tableRow.Cells.Select(this.MapToString));
        }
Esempio n. 2
0
        public Table MapToTable(G.DataTable dataTable)
        {
            if (dataTable == null)
            {
                return null;
            }

            var tableRows = dataTable.Rows;
            return this.MapToTable(tableRows);
        }
Esempio n. 3
0
 internal G.Scenario CreateScenario(string[] tags, string name, string description, G.Step[] steps)
 {
     G.Scenario scenario = new G.Scenario(
         tags.Select(this.CreateTag).ToArray(),
         AnyLocation,
         "Scenario",
         name,
         description,
         steps);
     return scenario;
 }
Esempio n. 4
0
        public Step MapToStep(G.Step step)
        {
            if (step == null)
            {
                return null;
            }

            return new Step
            {
                Location = this.MapToLocation(step.Location),
                DocStringArgument = step.Argument is G.DocString ? this.MapToString((G.DocString) step.Argument) : null,
                Keyword = this.MapToKeyword(step.Keyword),
                NativeKeyword = step.Keyword,
                Name = step.Text,
                TableArgument = step.Argument is G.DataTable ? this.MapToTable((G.DataTable) step.Argument) : null,
            };
        }
Esempio n. 5
0
        public Example MapToExample(G.Examples examples)
        {
            if (examples == null)
            {
                return null;
            }

            return new Example
            {
                Description = examples.Description,
                Name = examples.Name,
                TableArgument = this.MapToTable(((G.IHasRows) examples).Rows)
            };
        }
Esempio n. 6
0
        public Scenario MapToScenario(G.Scenario scenario)
        {
            if (scenario == null)
            {
                return null;
            }

            return new Scenario
            {
                Description = scenario.Description ?? string.Empty,
                Location = this.MapToLocation(scenario.Location),
                Name = scenario.Name,
                Slug = scenario.Name.ToSlug(),
                Steps = scenario.Steps.Select(this.MapToStep).ToList(),
                Tags = scenario.Tags.Select(this.MapToString).ToList()
            };
        }
Esempio n. 7
0
 public TableRow MapToTableRow(G.TableRow tableRow)
 {
     return this.mapper.Map<TableRow>(tableRow);
 }
Esempio n. 8
0
 internal G.Background CreateBackground(string name, string description, G.Step[] steps)
 {
     G.Background background = new G.Background(
         AnyLocation,
         "Background",
         name,
         description,
         steps);
     return background;
 }
Esempio n. 9
0
 public Step MapToStep(G.Step step)
 {
     return this.mapper.Map<Step>(step);
 }
Esempio n. 10
0
 public string MapToString(G.TableCell cell)
 {
     return cell?.Value;
 }
Esempio n. 11
0
        public Feature MapToFeature(G.GherkinDocument gherkinDocument)
        {
            if (gherkinDocument == null)
            {
                return null;
            }

            var feature = new Feature();

            var background = gherkinDocument.Feature.Children.SingleOrDefault(c => c is G.Background) as G.Background;
            if (background != null)
            {
                feature.AddBackground(this.MapToScenario(background));
            }

            if (this.configuration.ShouldEnableComments)
            {
                feature.Comments.AddRange((gherkinDocument.Comments ?? new G.Comment[0]).Select(this.MapToComment));
            }

            feature.Description = gherkinDocument.Feature.Description ?? string.Empty;

            foreach (var featureElement in gherkinDocument.Feature.Children.Where(c => !(c is G.Background)))
            {
                feature.AddFeatureElement(this.MapToFeatureElement(featureElement));
            }

            feature.Name = gherkinDocument.Feature.Name;

            foreach (var tag in gherkinDocument.Feature.Tags)
            {
                feature.AddTag(this.MapToString(tag));
            }

            foreach (var comment in feature.Comments.ToArray())
            {
                // Find the related feature
                var relatedFeatureElement = feature.FeatureElements.LastOrDefault(x => x.Location.Line < comment.Location.Line);
                // Find the step to which the comment is related to
                if (relatedFeatureElement != null)
                {
                    var stepAfterComment = relatedFeatureElement.Steps.FirstOrDefault(x => x.Location.Line > comment.Location.Line);
                    if (stepAfterComment != null)
                    {
                        // Comment is before a step
                        comment.Type = CommentType.StepComment;
                        stepAfterComment.Comments.Add(comment);
                    }
                    else
                    {
                        // Comment is located after the last step
                        var stepBeforeComment = relatedFeatureElement.Steps.LastOrDefault(x => x.Location.Line < comment.Location.Line);
                        if (stepBeforeComment != null && stepBeforeComment == relatedFeatureElement.Steps.Last())
                        {

                            comment.Type = CommentType.AfterLastStepComment;
                            stepBeforeComment.Comments.Add(comment);
                        }
                    }
                }
            }

            foreach (var featureElement in feature.FeatureElements.ToArray())
            {
                featureElement.Feature = feature;
            }

            if (feature.Background != null)
            {
                feature.Background.Feature = feature;
            }

            return feature;
        }
Esempio n. 12
0
 public Feature MapToFeature(G.Feature feature)
 {
     return this.mapper.Map<Feature>(feature);
 }
Esempio n. 13
0
 public Scenario MapToScenario(G.Background background)
 {
     return this.mapper.Map<Scenario>(background);
 }
Esempio n. 14
0
 public ScenarioOutline MapToScenarioOutline(G.ScenarioOutline scenarioOutline)
 {
     return this.mapper.Map<ScenarioOutline>(scenarioOutline);
 }
Esempio n. 15
0
 public Example MapToExample(G.Examples examples)
 {
     return this.mapper.Map<Example>(examples);
 }
Esempio n. 16
0
 public Scenario MapToScenario(G.Scenario scenario)
 {
     return this.mapper.Map<Scenario>(scenario);
 }
Esempio n. 17
0
 public string MapToString(G.Tag tag)
 {
     return this.mapper.Map<string>(tag);
 }
Esempio n. 18
0
        public ScenarioOutline MapToScenarioOutline(G.ScenarioOutline scenarioOutline)
        {
            if (scenarioOutline == null)
            {
                return null;
            }

            return new ScenarioOutline
            {
                Description = scenarioOutline.Description ?? string.Empty,
                Examples = (scenarioOutline.Examples ?? new G.Examples[0]).Select(this.MapToExample).ToList(),
                Location = this.MapToLocation(scenarioOutline.Location),
                Name = scenarioOutline.Name,
                Slug = scenarioOutline.Name.ToSlug(),
                Steps = scenarioOutline.Steps.Select(this.MapToStep).ToList(),
                Tags = scenarioOutline.Tags.Select(this.MapToString).ToList()
            };
        }
Esempio n. 19
0
        public Scenario MapToScenario(G.Background background)
        {
            if (background == null)
            {
                return null;
            }

            return new Scenario
            {
                Description = background.Description ?? string.Empty,
                Location = this.MapToLocation(background.Location),
                Name = background.Name,
                Steps = background.Steps.Select(this.MapToStep).ToList(),
            };
        }
Esempio n. 20
0
 internal G.Feature CreateFeature(string name, string description, string[] tags = null, G.Background background = null, G.ScenarioDefinition[] scenarioDefinitions = null)
 {
     return new G.Feature((tags ?? new string[0]).Select(this.CreateTag).ToArray(), null, null, "Feature", name, description, background, scenarioDefinitions, null);
 }
Esempio n. 21
0
        private IFeatureElement MapToFeatureElement(G.ScenarioDefinition sd)
        {
            if (sd == null)
            {
                return null;
            }

            var scenario = sd as G.Scenario;
            if (scenario != null)
            {
                return this.MapToScenario(scenario);
            }

            var scenarioOutline = sd as G.ScenarioOutline;
            if (scenarioOutline != null)
            {
                return this.MapToScenarioOutline(scenarioOutline);
            }

            var background = sd as G.Background;
            if (background != null)
            {
                return this.MapToScenario(background);
            }

            throw new ArgumentException("Only arguments of type Scenario, ScenarioOutline and Background are supported.");
        }
Esempio n. 22
0
 public Table MapToTable(G.DataTable dataTable)
 {
     return this.mapper.Map<Table>(dataTable);
 }
Esempio n. 23
0
 public string MapToString(G.Tag tag)
 {
     return tag?.Name;
 }
Esempio n. 24
0
 public string MapToString(G.DocString docString)
 {
     return this.mapper.Map<string>(docString);
 }
Esempio n. 25
0
 public string MapToString(G.DocString docString)
 {
     return docString?.Content;
 }
Esempio n. 26
0
        public Comment MapToComment(G.Comment comment)
        {
            if (comment == null)
            {
                return null;
            }

            return new Comment
            {
                Text = comment.Text.Trim(),
                Location = this.MapToLocation(comment.Location)
            };
        }
Esempio n. 27
0
 internal G.ScenarioOutline CreateScenarioOutline(string[] tags, string name, string description, G.Step[] steps, G.Examples[] examples)
 {
     G.ScenarioOutline scenarioOutline = new G.ScenarioOutline(
         tags.Select(this.CreateTag).ToArray(),
         AnyLocation,
         "Scenario",
         name,
         description,
         steps,
         examples);
     return scenarioOutline;
 }
Esempio n. 28
0
 public Location MapToLocation(G.Location location)
 {
     return location != null ? new Location { Column = location.Column, Line = location.Line } : null;
 }
Esempio n. 29
0
 internal G.GherkinDocument CreateGherkinDocument(string name, string description, string[] tags = null, G.Background background = null, G.ScenarioDefinition[] scenarioDefinitions = null, G.Comment[] comments = null, G.Location location = null)
 {
     var nonNullScenarioDefinitions = scenarioDefinitions ?? new G.ScenarioDefinition[0];
     return new G.GherkinDocument(
         new G.Feature(
             (tags ?? new string[0]).Select(this.CreateTag).ToArray(),
             location,
             null,
             "Feature",
             name,
             description,
             background != null ? new G.ScenarioDefinition[] { background }.Concat(nonNullScenarioDefinitions).ToArray() : nonNullScenarioDefinitions),
         comments);
 }
Esempio n. 30
0
 public string MapToString(G.TableCell cell)
 {
     return this.mapper.Map<string>(cell);
 }