public void GenerateScenarioExampleTests()
        {
            SpecFlowLangParser parser = new SpecFlowLangParser(new CultureInfo("en-US"));
            foreach (var testFile in TestFileHelper.GetTestFiles())
            {
                using (var reader = new StreamReader(testFile))
                {
                    Feature feature = parser.Parse(reader, null);                    
                    Assert.IsNotNull(feature);

                    Console.WriteLine("Testing {0}", Path.GetFileName(testFile));

                    var sampleTestGeneratorProvider = new SimpleTestGeneratorProvider();
                    var converter = FactoryMethods.CreateUnitTestConverter(sampleTestGeneratorProvider);
                    CodeNamespace code = converter.GenerateUnitTestFixture(feature, "TestClassName", "Target.Namespace");

                    Assert.IsNotNull(code);
                  
                    // make sure name space is changed
                    Assert.AreEqual(code.Name, SimpleTestGeneratorProvider.DefaultNameSpace);

                    // make sure all method titles are changed correctly
                    List<string> methodTitles = new List<string>();
                    for (int i = 0; i < code.Types[0].Members.Count; i++)
                    {
                        methodTitles.Add(code.Types[0].Members[i].Name);
                    }

                    foreach (var title in sampleTestGeneratorProvider.newTitles)
                    {
                        Assert.IsTrue(methodTitles.Contains(title));
                    }
                }
            }
        }
예제 #2
0
        private void ExecuteUsingV1Api()
        {
            // Instantiate a new parser, using the provided language
            SpecFlowLangParser parser = new SpecFlowLangParser(new CultureInfo(_options.Language ?? "en-US"));
            using (var client = new HttpClient())
            {
                // Get the base uri for all further operations
                string groupUri = $"{_options.AugurkUrl.TrimEnd('/')}/api/features/{_options.BranchName}/{_options.GroupName ?? "Default"}";

                // Clear any existing features in this group, if required
                if (_options.ClearGroup)
                {
                    Console.WriteLine($"Clearing existing features in group {_options.GroupName ?? "Default"} for branch {_options.BranchName}.");
                    client.DeleteAsync(groupUri).Wait();
                }

                // Parse and publish each of the provided feature files
                foreach (var featureFile in _options.FeatureFiles)
                {
                    try
                    {
                        using (TextReader reader = File.OpenText(featureFile))
                        {
                            // Parse the feature and convert it to the correct format
                            Feature feature = parser.Parse(reader, featureFile).ConvertToFeature();

                            // Get the uri to which the feature should be published
                            string targetUri = $"{groupUri}/{feature.Title}";

                            // Publish the feature
                            var postTask = client.PostAsJsonAsync<Feature>(targetUri, feature);
                            postTask.Wait();

                            // Process the result
                            if (postTask.Result.IsSuccessStatusCode)
                            {
                                Console.WriteLine("Succesfully published feature '{0}' to group {1} for branch {2}.",
                                                  feature.Title,
                                                  _options.GroupName ?? "Default",
                                                  _options.BranchName);

                            }
                            else
                            {
                                Console.Error.WriteLine("Publishing feature '{0}' to uri '{1}' resulted in statuscode '{2}'",
                                                        feature.Title,
                                                        targetUri,
                                                        postTask.Result.StatusCode);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.Error.WriteLine(e.ToString());
                    }
                }
            }
        }
 private static Feature ParseGherkin(string fileName)
 {
     using (var featureFileReader = new StreamReader(fileName))
     {
         var specFlowLangParser = new SpecFlowLangParser(CultureInfo.CurrentCulture);
         var feature = specFlowLangParser.Parse(featureFileReader, fileName);
         return feature;
     }
 }
        public override void Load()
	    {
            Feature feature;
            if (!contentIsCreated)
            {

		        SpecFlowLangParser specFlowLangParser = new SpecFlowLangParser(Language);
                TextReader textReader;
                if (String.IsNullOrEmpty(unparsedFeature))
                {
                    textReader = File.OpenText(SourcePath);
                }
                else
                {
                    textReader = new StringReader(unparsedFeature);
                }
                
                using (textReader)
                {
                    try
                    {
                        feature = specFlowLangParser.Parse(textReader, SourcePath);
                    }
                    catch (SpecFlowParserException ex)
                    {
                        throw new Exception(SourcePath + "\r\n" + ex.Message, ex);
                    }
                }

                if (feature.Tags != null && feature.Tags.Count > 0)
                {
                    Tag userStoryIdTag = feature.Tags.Find(aTag => { return aTag.Name.StartsWith(USER_STORY_ID_TAG_PREFIX); });
                    if (userStoryIdTag != null)
                    {
                        UserStoryId = userStoryIdTag.Name.Substring(USER_STORY_ID_TAG_PREFIX.Length);
                    }
                }

                FeatureTopicContentBuilder builder = new FeatureTopicContentBuilder(feature, Language);

                Name = builder.BuildName();
                Summary = builder.BuildSummary();
                Description = builder.BuildDescription();
                Rules = builder.BuildRules();
                GUI = builder.BuildGUI();
                Notes = builder.BuildNotes();
                Scenarios = builder.BuildBackground();
                Scenarios += builder.BuildScenarios();
                ReferencedImagesPaths = builder.BuildImages(ProjectFolder);

                contentIsCreated = true;
            }
	    }
예제 #5
0
        protected void ExecuteForFile(string fileName)
        {
            Console.WriteLine(fileName);
            SpecFlowLangParser parser = new SpecFlowLangParser(new CultureInfo("en-US"));
            using (var reader = new StreamReader(fileName))
            {
                Feature feature = parser.Parse(reader, null);
                Assert.IsNotNull(feature);

                ExecuteTests(feature, fileName);
            }
        }
예제 #6
0
        public CodeNamespace GenerateTestFileCode(SpecFlowFeatureFile featureFile, TextReader inputReader)
        {
            string targetNamespace = GetTargetNamespace(featureFile);

            SpecFlowLangParser parser = new SpecFlowLangParser(project.GeneratorConfiguration.FeatureLanguage);
            Feature feature = parser.Parse(inputReader, featureFile.GetFullPath(project));

            IUnitTestGeneratorProvider generatorProvider = ConfigurationServices.CreateInstance<IUnitTestGeneratorProvider>(project.GeneratorConfiguration.GeneratorUnitTestProviderType);

            SpecFlowUnitTestConverter testConverter = new SpecFlowUnitTestConverter(generatorProvider, project.GeneratorConfiguration.AllowDebugGeneratedFiles);

            var codeNamespace = testConverter.GenerateUnitTestFixture(feature, null, targetNamespace);
            return codeNamespace;
        }
예제 #7
0
 public static List<Feature> GetParsedFeatures(IEnumerable<string> featureFiles, CultureInfo featureLanguage)
 {
     List<Feature> parsedFeatures = new List<Feature>();
     foreach (var featureFile in featureFiles)
     {
         SpecFlowLangParser parser = new SpecFlowLangParser(featureLanguage);
         using (var reader = new StreamReader(featureFile))
         {
             Feature feature = parser.Parse(reader, featureFile);
             parsedFeatures.Add(feature);
         }
     }
     return parsedFeatures;
 }
예제 #8
0
        public void CanParseFile(string fileName)
        {
            Console.WriteLine(fileName);
            SpecFlowLangParser parser = new SpecFlowLangParser(new CultureInfo("en-US"));
            using (var reader = new StreamReader(fileName))
            {
                Feature feature = parser.Parse(reader);
                Assert.IsNotNull(feature);

                // to regenerate the expected result file:
                //SerializeFeature(feature, fileName + ".xml");

                CompareWithExpectedResult(feature, fileName + ".xml");
            }
        }
예제 #9
0
        public CodeNamespace GenerateTestFileCode(FeatureFileInput featureFile, TextReader inputReader, CodeDomProvider codeProvider, CodeDomHelper codeDomHelper)
        {
            string targetNamespace = GetTargetNamespace(featureFile);

            SpecFlowLangParser parser = new SpecFlowLangParser(project.Configuration.GeneratorConfiguration.FeatureLanguage);
            Feature feature = parser.Parse(inputReader, featureFile.GetFullPath(project.ProjectSettings));

            IUnitTestGeneratorProvider generatorProvider = ConfigurationServices.CreateInstance<IUnitTestGeneratorProvider>(project.Configuration.GeneratorConfiguration.GeneratorUnitTestProviderType);
            codeDomHelper.InjectIfRequired(generatorProvider);

            ISpecFlowUnitTestConverter testConverter = new SpecFlowUnitTestConverter(generatorProvider, codeDomHelper, project.Configuration.GeneratorConfiguration);

            var codeNamespace = testConverter.GenerateUnitTestFixture(feature, null, targetNamespace);

            return codeNamespace;
        }
예제 #10
0
        public void CanParseFile(string fileName)
        {
            Console.WriteLine(fileName);
            SpecFlowLangParser parser = new SpecFlowLangParser(new CultureInfo("en-US"));
            using (var reader = new StreamReader(fileName))
            {
                Feature feature = parser.Parse(reader, fileName);
                Assert.IsNotNull(feature);
                Assert.AreEqual(fileName, feature.SourceFile);

                feature.SourceFile = null; // cleanup source file to make the test run from other folders too

                // to regenerate the expected result file:
                //SerializeFeature(feature, fileName + ".xml");

                CompareWithExpectedResult(feature, fileName + ".xml");
            }
        }
        public void CanGenerateFromFile(string fileName)
        {
            Console.WriteLine(fileName);
            var parser = new SpecFlowLangParser(new CultureInfo("en-US"));
            using (var reader = new StreamReader(fileName))
            {
                Feature feature = parser.Parse(reader);
                Assert.IsNotNull(feature);

                string generatedCode = GenerateCodeFromFeature(feature);
                Assert.IsNotNull(generatedCode);

                // to regenerate the expected result file:
                //GenerateCodeFromFeature(feature, fileName + ".cs");

                //CompareWithExpectedResult(feature, fileName + ".cs");
            }
        }
예제 #12
0
        static void Main(string[] args)
        {
            string SourcePath = @"G:\_Tools\BlissInSoftware.Sandcastle\BlissInSoftware.Sandcastle.Gherkin\BlissInSoftware.Sandcastle.Gherkin.UnitTests\FeatureWithMultilineTextArgument.feature";
            SpecFlowLangParser specFlowLangParser = new SpecFlowLangParser(new CultureInfo("en-US"));
            TextReader textReader;
            textReader = File.OpenText(SourcePath);
            Feature feature;
            using (textReader)
            {
                try
                {
                    feature = specFlowLangParser.Parse(textReader, SourcePath);
                }
                catch (SpecFlowParserException ex)
                {
                    throw new Exception(SourcePath + "\r\n" + ex.Message, ex);
                }
            }

            FeatureTopicContentBuilder build = new FeatureTopicContentBuilder(feature, new CultureInfo("en-US")); 
            string x = build.BuildDescription();
        }
예제 #13
0
        private CodeNamespace GenerateTestFileCode(FeatureFileInput featureFileInput)
        {
            string targetNamespace = GetTargetNamespace(featureFileInput) ?? "SpecFlow.GeneratedTests";

            SpecFlowLangParser parser = new SpecFlowLangParser(generatorConfiguration.FeatureLanguage);
            Feature feature;
            using (var contentReader = featureFileInput.GetFeatureFileContentReader(projectSettings))
            {
                feature = parser.Parse(contentReader, featureFileInput.GetFullPath(projectSettings));
            }

            var featureGenerator = featureGeneratorRegistry.CreateGenerator(feature);

            var codeNamespace = featureGenerator.GenerateUnitTestFixture(feature, null, targetNamespace);
            return codeNamespace;
        }
 public SpecFlowReportGenerator(string rootPath, string featureLanguage)
 {
     this.rootPath = rootPath;
     currentCultureInfo = CultureInfo.CreateSpecificCulture(featureLanguage);
     specFlowParser = new SpecFlowLangParser(currentCultureInfo); 
 }
예제 #15
0
        /// <summary>
        /// Publishes the features provided through the <see cref="FeatureFiles"/> property 
        /// to the Augurk site hosted at the <see cref="AugurkUri"/>.
        /// </summary>
        /// <returns>
        /// true if the publish was completed successfully; otherwise, false.
        /// </returns>
        public override bool Execute()
        {
            bool result = true;

            // Instantiate a new parser, using the provided language
            SpecFlowLangParser parser = new SpecFlowLangParser(new CultureInfo(Language ?? "en-US"));
            var client = new HttpClient();

            // Get the base uri for all further operations
            string groupUri = GetGroupUri();

            // Clear any existing features in this group, if required
            if (ClearGroupBeforePublish)
            {
                Log.LogMessage("Clearing existing features in group {0} for branch {1}.", GroupName ?? "Default", BranchName);
                client.DeleteAsync(groupUri).Wait();
            }

            // Parse and publish each of the provided feature files
            foreach (var featureFile in FeatureFiles)
            {
                try
                {
                    using (TextReader reader = File.OpenText(featureFile.ItemSpec))
                    {
                        // Parse the feature and convert it to the correct format
                        Feature feature = parser.Parse(reader, featureFile.ItemSpec).ConvertToFeature();

                        // Get the uri to which the feature should be published
                        string targetUri = GetFeatureUri(groupUri, feature.Title);

                        // Publish the feature
                        var postTask = client.PostAsJsonAsync<Feature>(targetUri, feature);
                        postTask.Wait();

                        // Process the result
                        if (postTask.Result.IsSuccessStatusCode)
                        {
                            Log.LogMessage("Succesfully published feature '{0}' to group {1} for branch {2}.",
                                           feature.Title,
                                           GroupName ?? "Default",
                                           BranchName);

                        }
                        else
                        {
                            result = false;
                            Log.LogError("Publishing feature '{0}' to uri '{1}' resulted in statuscode '{2}'",
                                         feature.Title,
                                         targetUri,
                                         postTask.Result.StatusCode);
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.LogErrorFromException(e);
                }
            }

            // Parse the restresults
            IEnumerable<FeatureTestResult> testResults = ParseTestResults();

            // Publish the testresults, if present
            foreach (var featureTestResult in testResults)
            {
                try
                {
                    // Get the uri to which the test result should be published
                    string targetUri = GetTestResultUri(groupUri, featureTestResult.FeatureTitle);

                    // Publish the test result
                    var postTask = client.PostAsJsonAsync<FeatureTestResult>(targetUri, featureTestResult);
                    postTask.Wait();

                    // Process the result
                    if (postTask.Result.IsSuccessStatusCode)
                    {
                        Log.LogMessage("Succesfully published test result of feature '{0}' to group {1} for branch {2}.",
                                       featureTestResult.FeatureTitle,
                                       GroupName ?? "Default",
                                       BranchName);

                    }
                    else
                    {
                        result = false;
                        Log.LogError("Publishing test result of feature '{0}' to uri '{1}' resulted in statuscode '{2}'",
                                     featureTestResult.FeatureTitle,
                                     targetUri,
                                     postTask.Result.StatusCode);
                    }
                }
                catch (Exception e)
                {
                    Log.LogErrorFromException(e);
                }
            }

            return result;
        }
예제 #16
0
        public void CanGenerateFromFile(string fileName)
        {
            Console.WriteLine(fileName);
            SpecFlowLangParser parser = new SpecFlowLangParser(new CultureInfo("en-US"));
            using (var reader = new StreamReader(fileName))
            {
                Feature feature = parser.Parse(reader);
                Assert.IsNotNull(feature);

                ExecuteTests(feature, fileName);
            }
        }
예제 #17
0
 /// <summary>
 /// Loops through the feature files in a project and returns the feature object corresponding
 /// to the targetFeature path
 private static Feature ParseFeature(string targetFeature, SpecFlowProject specFlowProject)
 {
     SpecFlowLangParser parser = new SpecFlowLangParser(specFlowProject.Configuration.GeneratorConfiguration.FeatureLanguage);
     using (var reader = new StreamReader(targetFeature))
     {
         return parser.Parse(reader, targetFeature);
     }
 }
예제 #18
0
        private CodeNamespace GenerateTestFileCode(FeatureFileInput featureFileInput, CodeDomHelper codeDomHelper)
        {
            string targetNamespace = GetTargetNamespace(featureFileInput) ?? "SpecFlow.GeneratedTests";

            SpecFlowLangParser parser = new SpecFlowLangParser(generatorConfiguration.FeatureLanguage);
            Feature feature;
            using (var contentReader = featureFileInput.GetFeatureFileContentReader(projectSettings))
            {
                feature = parser.Parse(contentReader, featureFileInput.GetFullPath(projectSettings));
            }

            IUnitTestGeneratorProvider generatorProvider = ConfigurationServices.CreateInstance<IUnitTestGeneratorProvider>(generatorConfiguration.GeneratorUnitTestProviderType);
            codeDomHelper.InjectIfRequired(generatorProvider);

            ISpecFlowUnitTestConverter testConverter = new SpecFlowUnitTestConverter(generatorProvider, codeDomHelper, generatorConfiguration);

            var codeNamespace = testConverter.GenerateUnitTestFixture(feature, null, targetNamespace);
            return codeNamespace;
        }
 protected void AddFeature(string featureText, string sourcePath)
 {
     var parser = new SpecFlowLangParser(new CultureInfo("en-US"));
     var feature = parser.Parse(new StringReader(featureText), sourcePath);
     _viewModel.AddFeature(new FeatureViewModel(feature));
 }
예제 #20
0
        private void ExecuteUsingV2Api()
        {
            // Instantiate a new parser, using the provided language
            SpecFlowLangParser parser = new SpecFlowLangParser(new CultureInfo(_options.Language ?? "en-US"));
            using (var client = new HttpClient())
            {
                // Get the base uri for all further operations
                string groupUri = $"{_options.AugurkUrl.TrimEnd('/')}/api/v2/products/{_options.ProductName}/groups/{_options.GroupName}/features";

                // Parse and publish each of the provided feature files
                foreach (var featureFile in _options.FeatureFiles)
                {
                    try
                    {
                        using (TextReader reader = File.OpenText(featureFile))
                        {
                            // Parse the feature and convert it to the correct format
                            Feature feature = parser.Parse(reader, featureFile).ConvertToFeature();

                            // Get the uri to which the feature should be published
                            string targetUri = $"{groupUri}/{feature.Title}/versions/{_options.Version}/";

                            // Publish the feature
                            var postTask = client.PostAsJsonAsync<Feature>(targetUri, feature);
                            postTask.Wait();

                            // Process the result
                            if (postTask.Result.IsSuccessStatusCode)
                            {
                                Console.WriteLine($"Succesfully published feature '{feature.Title}' version '{_options.Version}' for product '{_options.ProductName}' to group '{_options.GroupName}'.");
                            }
                            else
                            {
                                Console.Error.WriteLine($"Publishing feature '{feature.Title}' version '{_options.Version}' to uri '{targetUri}' resulted in statuscode '{postTask.Result.StatusCode}'");
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.Error.WriteLine(e.ToString());
                    }
                }
            }
        }
예제 #21
0
파일: Program.cs 프로젝트: robfe/SpecShow
        static void Process(ProgramArguments args)
        {
            var parser = new SpecFlowLangParser(new CultureInfo("en-US"));
            var srcDir = new DirectoryInfo(args.FeatureDirectory);
            var files = srcDir.GetFiles("*.feature", SearchOption.AllDirectories);
            var startIndex = srcDir.FullName.Length;
            if (!srcDir.FullName.EndsWith("\\"))
            {
                startIndex++;
            }

            var features = files
                .Select(x => parser.Parse(x.OpenText(), x.FullName.Substring(startIndex)))
                .Where(x => x.FilePosition != null); //not parsable

            var vm = new RootViewModel()
                {
                    Title = args.PageTitle ?? Path.GetFileNameWithoutExtension(args.OutputFile),
                };

            foreach (var feature in features)
            {
                vm.AddFeature(new FeatureViewModel(feature));
            }

            if (args.XUnitResults != null)
            {
                IResultsMatcher matcher = new XUnitResultsMatcher();
                matcher.Populate(File.OpenRead(args.XUnitResults), vm);
            }
            //todo: other parsers

            PrintSummary(vm);

            /**
            var template = new SinglePageTemplate { Session = new Dictionary<string, object> { { "TemplateModel", vm } } };
            template.Initialize();
            /*/
            var template = new SinglePageRazorTemplate { TemplateModel=vm };
            /**/
            var transformText = template.TransformText();
            File.WriteAllText(args.OutputFile, transformText);
        }