private void GenerateTestFile(FeatureFileInput featureFile, CodeDomProvider codeProvider, TextWriter outputWriter)
 {
     using(var reader = new StreamReader(featureFile.GetFullPath(project.ProjectSettings)))
     {
         GenerateTestFile(featureFile, codeProvider, reader, outputWriter);
     }
 }
        private bool IsUpToDateByModificationTimeAndGeneratorVersion(FeatureFileInput featureFileInput, string generatedTestFullPath)
        {
            if (generatedTestFullPath == null)
                return false;

            // check existance of the target file
            if (!File.Exists(generatedTestFullPath))
                return false;

            // check modification time of the target file
            try
            {
                var featureFileModificationTime = File.GetLastWriteTime(featureFileInput.GetFullPath(projectSettings));
                var codeFileModificationTime = File.GetLastWriteTime(generatedTestFullPath);

                if (featureFileModificationTime > codeFileModificationTime)
                    return false;

                // check tools version
                var codeFileVersion = testHeaderWriter.DetectGeneratedTestVersion(featureFileInput.GetGeneratedTestContent(generatedTestFullPath));
                if (codeFileVersion == null || codeFileVersion != generatorInfo.GeneratorVersion)
                    return false;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                return false;
            }

            return true;
        }
Exemple #3
0
        public string GetTestFullPath(FeatureFileInput featureFileInput)
        {
            var path = featureFileInput.GetGeneratedTestFullPath(projectSettings);
            if (path != null)
                return path;

            return featureFileInput.GetFullPath(projectSettings) + GenerationTargetLanguage.GetExtension(projectSettings.ProjectPlatformSettings.Language);
        }
        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;
        }
        private CodeNamespace GenerateTestFileCode(FeatureFileInput featureFileInput)
        {
            string targetNamespace = GetTargetNamespace(featureFileInput) ?? "SpecFlow.GeneratedTests";

            var parser = new SpecFlowGherkinParser(generatorConfiguration.FeatureLanguage);
            SpecFlowFeature 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;
        }
        private string GetTargetNamespace(FeatureFileInput featureFile)
        {
            if (!string.IsNullOrEmpty(featureFile.CustomNamespace))
                return featureFile.CustomNamespace;

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

            string targetNamespace = project.ProjectSettings.DefaultNamespace;
            string projectFolder = project.ProjectSettings.ProjectFolder;
            string sourceFileFolder = Path.GetDirectoryName(featureFile.GetFullPath(project.ProjectSettings));
            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;
        }
Exemple #7
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;
        }