コード例 #1
0
ファイル: ParserDriver.cs プロジェクト: z3le/SpecFlow
 private void SerializeFeature(SpecFlowFeature feature, TextWriter writer)
 {
     var oldFeature = CompatibleAstConverter.ConvertToCompatibleFeature(feature);
     oldFeature.SourceFile = null;
     XmlSerializer serializer = new XmlSerializer(typeof(Feature));
     serializer.Serialize(writer, oldFeature);
 }
コード例 #2
0
ファイル: ParserHelper.cs プロジェクト: tmulkern/SpecFlow
        public static SpecFlowDocument CreateDocument(string[] tags = null, string[] scenarioTags = null)
        {
            tags = tags ?? new string[0];

            var scenario1 = new Scenario(GetTags(scenarioTags), null, "Scenario", "scenario1 title", "", new Step[0]);

            var specFlowFeature = new SpecFlowFeature(GetTags(tags), null, "en", "feature", "title", "desc", new ScenarioDefinition[] {scenario1});
            return new SpecFlowDocument(specFlowFeature, new Comment[0], null);
        }
コード例 #3
0
        private void CheckForDuplicateScenarios(SpecFlowFeature feature, List <ParserException> errors)
        {
            // duplicate scenario name
            var duplicatedScenarios = feature.ScenarioDefinitions.GroupBy(sd => sd.Name, sd => sd).Where(g => g.Count() > 1).ToArray();

            errors.AddRange(
                duplicatedScenarios.Select(g =>
                                           new SemanticParserException(
                                               string.Format("Feature file already contains a scenario with name '{0}'", g.Key),
                                               g.ElementAt(1).Location)));
        }
コード例 #4
0
ファイル: ParserHelper.cs プロジェクト: tmulkern/SpecFlow
        public static SpecFlowDocument CreateDocumentWithScenarioOutline(string[] tags = null, string[] scenarioOutlineTags = null, string[] examplesTags = null)
        {
            tags = tags ?? new string[0];

            var scenario1 = new ScenarioOutline(GetTags(scenarioOutlineTags), null, "Scenario Outline", "scenario outline1 title", "", new Step[0], new []
            {
                new Examples(GetTags(examplesTags), null, "Examples", "examples name", "", new Gherkin.Ast.TableRow(null, new []{ new TableCell(null, "col1"), }), new Gherkin.Ast.TableRow[0])
            });

            var specFlowFeature = new SpecFlowFeature(GetTags(tags), null, "en", "feature", "title", "desc", new ScenarioDefinition[] {scenario1});
            return new SpecFlowDocument(specFlowFeature, new Comment[0], null);
        }
コード例 #5
0
 private void CheckForMissingExamples(SpecFlowFeature feature, List <ParserException> errors)
 {
     foreach (var scenarioDefinition in feature.ScenarioDefinitions)
     {
         var scenarioOutline = scenarioDefinition as ScenarioOutline;
         if (scenarioOutline != null)
         {
             if (DoesntHavePopulatedExamples(scenarioOutline))
             {
                 var message = string.Format("Scenario Outline '{0}' has no examples defined", scenarioOutline.Name);
                 var semanticParserException = new SemanticParserException(message, scenarioDefinition.Location);
                 errors.Add(semanticParserException);
             }
         }
     }
 }
コード例 #6
0
        public TestClassGenerationContext(IUnitTestGeneratorProvider unitTestGeneratorProvider, SpecFlowFeature feature, CodeNamespace ns, CodeTypeDeclaration testClass, CodeMemberField testRunnerField, CodeMemberMethod testClassInitializeMethod, CodeMemberMethod testClassCleanupMethod, CodeMemberMethod testInitializeMethod, CodeMemberMethod testCleanupMethod, CodeMemberMethod scenarioInitializeMethod, CodeMemberMethod scenarioCleanupMethod, CodeMemberMethod featureBackgroundMethod, bool generateRowTests)
        {
            UnitTestGeneratorProvider = unitTestGeneratorProvider;
            Feature = feature;
            Namespace = ns;
            TestClass = testClass;
            TestRunnerField = testRunnerField;
            TestClassInitializeMethod = testClassInitializeMethod;
            TestClassCleanupMethod = testClassCleanupMethod;
            TestInitializeMethod = testInitializeMethod;
            TestCleanupMethod = testCleanupMethod;
            ScenarioInitializeMethod = scenarioInitializeMethod;
            ScenarioCleanupMethod = scenarioCleanupMethod;
            FeatureBackgroundMethod = featureBackgroundMethod;
            GenerateRowTests = generateRowTests;

            CustomData = new Dictionary<string, object>();
        }
コード例 #7
0
        private void CheckSemanticErrors(SpecFlowFeature feature)
        {
            var errors = new List <ParserException>();

            CheckForDuplicateScenarios(feature, errors);

            CheckForDuplicateExamples(feature, errors);

            // collect
            if (errors.Count == 1)
            {
                throw errors[0];
            }
            if (errors.Count > 1)
            {
                throw new CompositeParserException(errors.ToArray());
            }
        }
コード例 #8
0
        private void CheckForDuplicateExamples(SpecFlowFeature feature, List <ParserException> errors)
        {
            foreach (var scenarioDefinition in feature.ScenarioDefinitions)
            {
                var scenarioOutline = scenarioDefinition as ScenarioOutline;
                if (scenarioOutline != null)
                {
                    var duplicateExamples = scenarioOutline.Examples
                                            .Where(e => !String.IsNullOrWhiteSpace(e.Name))
                                            .Where(e => e.Tags.All(t => t.Name != "ignore"))
                                            .GroupBy(e => e.Name, e => e).Where(g => g.Count() > 1);

                    foreach (var duplicateExample in duplicateExamples)
                    {
                        var message = string.Format("Scenario Outline '{0}' already contains an example with name '{1}'", scenarioOutline.Name, duplicateExample.Key);
                        var semanticParserException = new SemanticParserException(message, duplicateExample.ElementAt(1).Location);
                        errors.Add(semanticParserException);
                    }
                }
            }
        }
コード例 #9
0
 public abstract IFeatureGenerator CreateGenerator(SpecFlowFeature feature);
コード例 #10
0
 public bool CanGenerate(SpecFlowFeature feature)
 {
     return tagFilterMatcher.MatchPrefix(registeredName, feature);
 }
コード例 #11
0
ファイル: ParserDriver.cs プロジェクト: z3le/SpecFlow
 private string SerializeFeature(SpecFlowFeature feature)
 {
     using (var writer = new Utf8StringWriter())
     {
         SerializeFeature(feature, writer);
         return writer.ToString();
     }
 }
コード例 #12
0
 public IFeatureGenerator CreateGenerator(SpecFlowFeature feature)
 {
     return unitTestFeatureGenerator;
 }
コード例 #13
0
 public SpecFlowDocument(SpecFlowFeature feature, Comment[] comments, SpecFlowDocumentLocation documentLocation) : base(feature, comments)
 {
     DocumentLocation = documentLocation;
 }
コード例 #14
0
ファイル: ParserHelper.cs プロジェクト: tmulkern/SpecFlow
 public static SpecFlowDocument CreateAnyDocument(string[] tags = null)
 {
     var specFlowFeature = new SpecFlowFeature(GetTags(tags), null, null, null, null, null, null);
     return new SpecFlowDocument(specFlowFeature, new Comment[0], null);
 }
コード例 #15
0
ファイル: SpecFlowDocument.cs プロジェクト: tmulkern/SpecFlow
 public SpecFlowDocument(SpecFlowFeature feature, Comment[] comments, string sourceFilePath)
     : base(feature, comments)
 {
     this.SourceFilePath = sourceFilePath;
 }
コード例 #16
0
 public static bool GetTagValue(this ITagFilterMatcher tagFilterMatcher, string tagFilter, SpecFlowFeature feature, out string value)
 {
     return tagFilterMatcher.GetTagValue(tagFilter, feature.Tags.Select(t => t.GetNameWithoutAt()), out value);
 }
コード例 #17
0
 public static bool MatchPrefix(this ITagFilterMatcher tagFilterMatcher, string tagFilter, SpecFlowFeature feature)
 {
     return tagFilterMatcher.MatchPrefix(tagFilter, feature.Tags.Select(t => t.GetNameWithoutAt()));
 }
コード例 #18
0
 public SpecFlowDocument(SpecFlowFeature feature, Comment[] comments, string sourceFilePath) : base(feature, comments)
 {
     this.SourceFilePath = sourceFilePath;
 }
コード例 #19
0
 public IFeatureGenerator CreateGenerator(SpecFlowFeature feature)
 {
     var providerItem = FindProvider(feature);
     return providerItem.Value.CreateGenerator(feature);
 }
コード例 #20
0
 private KeyValuePair<string, IFeatureGeneratorProvider> FindProvider(SpecFlowFeature feature)
 {
     return providers.First(item => item.Value.CanGenerate(feature));
 }
コード例 #21
0
 public bool CanGenerate(SpecFlowFeature feature)
 {
     return true;
 }
コード例 #22
0
 public override IFeatureGenerator CreateGenerator(SpecFlowFeature feature)
 {
     return DummyGenerator;
 }
コード例 #23
0
ファイル: ParserDriver.cs プロジェクト: z3le/SpecFlow
 private void SerializeFeature(SpecFlowFeature feature, string fileName)
 {
     using (var writer = new StreamWriter(fileName, false, Encoding.UTF8))
     {
         SerializeFeature(feature, writer);
     }
 }
コード例 #24
0
ファイル: SpecFlowDocument.cs プロジェクト: avonwyss/SpecFlow
 public SpecFlowDocument(SpecFlowFeature feature, Comment[] comments) : base(feature, comments)
 {
 }
コード例 #25
0
 protected void GenerateFeature(IFeatureGenerator generator, SpecFlowFeature feature)
 {
     generator.GenerateUnitTestFixture(feature, "dummy", "dummyNS");
 }