Ejemplo n.º 1
0
 private void GenerateTestFile(SpecFlowFeatureFile featureFile, CodeDomProvider codeProvider, TextWriter outputWriter)
 {
     using(var reader = new StreamReader(featureFile.GetFullPath(project)))
     {
         GenerateTestFile(featureFile, codeProvider, reader, outputWriter);
     }
 }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
0
        private string GetTargetNamespace(SpecFlowFeatureFile featureFile)
        {
            if (!string.IsNullOrEmpty(featureFile.CustomNamespace))
                return featureFile.CustomNamespace;

            if (string.IsNullOrEmpty(project.DefaultNamespace))
                return null;

            string targetNamespace = project.DefaultNamespace;
            string projectFolder = project.ProjectFolder;
            string sourceFileFolder = Path.GetDirectoryName(featureFile.GetFullPath(project));
            if (sourceFileFolder.StartsWith(sourceFileFolder, StringComparison.InvariantCultureIgnoreCase))
            {
                string extraFolders = sourceFileFolder.Substring(projectFolder.Length);
                if (extraFolders.Length > 0)
                {
                    string[] parts = extraFolders.TrimStart('\\').Split('\\');
                    targetNamespace += "." + string.Join(".",
                                                 parts.Select(p => p.ToIdentifier()).ToArray());
                }
            }
            return targetNamespace;
        }