Esempio n. 1
0
 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);
 }
Esempio n. 2
0
        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);
        }
        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)));
        }
Esempio n. 4
0
        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);
        }
Esempio n. 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);
             }
         }
     }
 }
        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>();
        }
        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());
            }
        }
        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);
                    }
                }
            }
        }
 public abstract IFeatureGenerator CreateGenerator(SpecFlowFeature feature);
 public bool CanGenerate(SpecFlowFeature feature)
 {
     return tagFilterMatcher.MatchPrefix(registeredName, feature);
 }
Esempio n. 11
0
 private string SerializeFeature(SpecFlowFeature feature)
 {
     using (var writer = new Utf8StringWriter())
     {
         SerializeFeature(feature, writer);
         return writer.ToString();
     }
 }
 public IFeatureGenerator CreateGenerator(SpecFlowFeature feature)
 {
     return unitTestFeatureGenerator;
 }
Esempio n. 13
0
 public SpecFlowDocument(SpecFlowFeature feature, Comment[] comments, SpecFlowDocumentLocation documentLocation) : base(feature, comments)
 {
     DocumentLocation = documentLocation;
 }
Esempio n. 14
0
 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);
 }
Esempio n. 15
0
 public SpecFlowDocument(SpecFlowFeature feature, Comment[] comments, string sourceFilePath)
     : base(feature, comments)
 {
     this.SourceFilePath = sourceFilePath;
 }
Esempio n. 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);
 }
Esempio n. 17
0
 public static bool MatchPrefix(this ITagFilterMatcher tagFilterMatcher, string tagFilter, SpecFlowFeature feature)
 {
     return tagFilterMatcher.MatchPrefix(tagFilter, feature.Tags.Select(t => t.GetNameWithoutAt()));
 }
Esempio n. 18
0
 public SpecFlowDocument(SpecFlowFeature feature, Comment[] comments, string sourceFilePath) : base(feature, comments)
 {
     this.SourceFilePath = sourceFilePath;
 }
 public IFeatureGenerator CreateGenerator(SpecFlowFeature feature)
 {
     var providerItem = FindProvider(feature);
     return providerItem.Value.CreateGenerator(feature);
 }
 private KeyValuePair<string, IFeatureGeneratorProvider> FindProvider(SpecFlowFeature feature)
 {
     return providers.First(item => item.Value.CanGenerate(feature));
 }
 public bool CanGenerate(SpecFlowFeature feature)
 {
     return true;
 }
 public override IFeatureGenerator CreateGenerator(SpecFlowFeature feature)
 {
     return DummyGenerator;
 }
Esempio n. 23
0
 private void SerializeFeature(SpecFlowFeature feature, string fileName)
 {
     using (var writer = new StreamWriter(fileName, false, Encoding.UTF8))
     {
         SerializeFeature(feature, writer);
     }
 }
Esempio n. 24
0
 public SpecFlowDocument(SpecFlowFeature feature, Comment[] comments) : base(feature, comments)
 {
 }
 protected void GenerateFeature(IFeatureGenerator generator, SpecFlowFeature feature)
 {
     generator.GenerateUnitTestFixture(feature, "dummy", "dummyNS");
 }