Esempio n. 1
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;
            }

            feature.Language = gherkinDocument.Feature.Language ?? "en";

            return(feature);
        }
Esempio n. 2
0
 public Feature MapToFeature(G.GherkinDocument gherkinDocument)
 {
     return(this.mapper.Map <Feature>(gherkinDocument));
 }