public void GenerateScenarioExampleTests()
        {
            SpecFlowLangParser parser = new SpecFlowLangParser(new CultureInfo("en-US"));

            using (var reader = new StringReader(SampleFeatureFile))
            {
                Feature feature = parser.Parse(reader, null);
                Assert.IsNotNull(feature);

                var           sampleTestGeneratorProvider = new SimpleTestGeneratorProvider();
                var           converter = 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));
                }
            }
        }
Ejemplo n.º 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());
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private static void DefaultGherkinParserTest(SpecFlowLangParser parser, string file)
        {
            Feature feature;

            using (StreamReader reader = new StreamReader(file))
            {
                feature = parser.Parse(reader, file);
            }
        }
Ejemplo n.º 4
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, null);
                Assert.IsNotNull(feature);

                ExecuteTests(feature, fileName);
            }
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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());
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public Feature ParseGherkinFile(string fileContent, string sourceFileName, CultureInfo defaultLanguage)
        {
            try
            {
                SpecFlowLangParser specFlowLangParser = new SpecFlowLangParser(defaultLanguage);

                StringReader featureFileReader = new StringReader(fileContent);

                var feature = specFlowLangParser.Parse(featureFileReader, sourceFileName);

                return(feature);
            }
            catch (Exception)
            {
                vsProjectScope.Tracer.Trace("Invalid feature file: " + sourceFileName, "ProjectFeatureFilesTracker");
                return(null);
            }
        }
Ejemplo n.º 9
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 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, null);
                Assert.IsNotNull(feature);

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

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

                //CompareWithExpectedResult(feature, fileName + ".cs");
            }
        }
Ejemplo n.º 11
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");
            }
        }
Ejemplo n.º 12
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.AllowDebugGeneratedFiles, generatorConfiguration.AllowRowTests);

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

            return(codeNamespace);
        }
Ejemplo n.º 13
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"));

            using (var client = CreateHttpClient())
            {
                // 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);
        }