Ejemplo n.º 1
0
        private SpecFlowProject CreateSpecFlowProjectFrom(IProject project)
        {
            var specFlowProject = new SpecFlowProject();

            specFlowProject.ProjectSettings.ProjectFolder    = project.Directory;
            specFlowProject.ProjectSettings.ProjectName      = project.Name;
            specFlowProject.ProjectSettings.AssemblyName     = project.AssemblyName;
            specFlowProject.ProjectSettings.DefaultNamespace = project.RootNamespace;

            var generatorConfig = specFlowProject.Configuration.GeneratorConfiguration;

            foreach (var projectFile in project.Items.OfType <FileProjectItem>().Where(IsFeatureOrAppConfigFile))
            {
                string extension = Path.GetExtension(projectFile.FileName);
                if (extension != null && extension.Equals(".feature", StringComparison.InvariantCultureIgnoreCase))
                {
                    string fileName    = FileUtilities.GetRelativePath(projectFile.FileName, project.Directory);
                    var    featureFile = new FeatureFileInput(fileName);

                    specFlowProject.FeatureFiles.Add(featureFile);
                }

                if (extension != null && extension.Equals(".config", StringComparison.InvariantCultureIgnoreCase))
                {
                    string configContent = File.ReadAllText(projectFile.FileName);
                    GeneratorConfigurationReader.UpdateConfigFromFileContent(generatorConfig, configContent);
                }
            }

            return(specFlowProject);
        }
        public static SpecFlowProject LoadSpecFlowProjectFromDteProject(Project project)
        {
            string projectFolder = Path.GetDirectoryName(project.FullName);

            SpecFlowProject specFlowProject = new SpecFlowProject();

            specFlowProject.ProjectSettings.ProjectFolder    = projectFolder;
            specFlowProject.ProjectSettings.ProjectName      = Path.GetFileNameWithoutExtension(project.FullName);
            specFlowProject.ProjectSettings.AssemblyName     = project.Properties.Item("AssemblyName").Value as string;
            specFlowProject.ProjectSettings.DefaultNamespace = project.Properties.Item("DefaultNamespace").Value as string;

            foreach (ProjectItem projectItem in GetAllProjectItem(project).Where(IsPhysicalFile))
            {
                var fileName = GetRelativePath(GetFileName(projectItem), projectFolder);

                var extension = Path.GetExtension(fileName);
                if (extension.Equals(".feature", StringComparison.InvariantCultureIgnoreCase))
                {
                    var featureFile = new FeatureFileInput(fileName);
                    var ns          = projectItem.Properties.Item("CustomToolNamespace").Value as string;
                    if (!String.IsNullOrEmpty(ns))
                    {
                        featureFile.CustomNamespace = ns;
                    }
                    specFlowProject.FeatureFiles.Add(featureFile);
                }

                if (Path.GetFileName(fileName).Equals("app.config", StringComparison.InvariantCultureIgnoreCase))
                {
                    GeneratorConfigurationReader.UpdateConfigFromFileContent(specFlowProject.Configuration.GeneratorConfiguration, GetFileContent(projectItem));
                }
            }
            return(specFlowProject);
        }
Ejemplo n.º 3
0
        private static SpecFlowProjectConfiguration LoadSpecFlowConfigurationFromDteProjectInternal(Project project)
        {
            SpecFlowProjectConfiguration configuration = new SpecFlowProjectConfiguration();
            ProjectItem projectItem = VsxHelper.FindProjectItemByProjectRelativePath(project, "app.config");

            if (projectItem != null)
            {
                string configFileContent = VsxHelper.GetFileContent(projectItem);
                GeneratorConfigurationReader.UpdateConfigFromFileContent(configuration.GeneratorConfiguration, configFileContent);
                RuntimeConfigurationReader.UpdateConfigFromFileContent(configuration.RuntimeConfiguration, configFileContent);
            }
            return(configuration);
        }
Ejemplo n.º 4
0
        public static SpecFlowProject CreateSpecFlowProjectFrom(Project project)
        {
            var specFlowProject = new SpecFlowProject();

            specFlowProject.ProjectSettings.ProjectFolder = project.BaseDirectory;
            specFlowProject.ProjectSettings.ProjectName   = project.Name;

            string defaultNamespace = "Namespace";

            if (project is DotNetProject)
            {
                defaultNamespace = ((DotNetProject)project).GetDefaultNamespace(project.Name);
            }

            // No way to get AssemblyName right now, therefore we'll just use DefaultNamespace
            specFlowProject.ProjectSettings.AssemblyName     = defaultNamespace;
            specFlowProject.ProjectSettings.DefaultNamespace = defaultNamespace;

            // TODO: Find out if we really need to add all the feature files everytime we generate
            foreach (ProjectFile projectFile in project.Files.Where(IsFeatureOrAppConfigFile))
            {
                string extension = Path.GetExtension(projectFile.Name);

                if (extension.Equals(".feature", StringComparison.InvariantCultureIgnoreCase))
                {
                    string fileName            = projectFile.FilePath.ToRelative(project.BaseDirectory);
                    var    featureFile         = new FeatureFileInput(fileName);
                    var    customToolNamespace = projectFile.CustomToolNamespace;

                    if (!String.IsNullOrEmpty(customToolNamespace))
                    {
                        featureFile.CustomNamespace = customToolNamespace;
                    }

                    specFlowProject.FeatureFiles.Add(featureFile);
                }

                if (extension.Equals(".config", StringComparison.InvariantCultureIgnoreCase))
                {
                    string configContent = File.ReadAllText(projectFile.FilePath);
                    GeneratorConfigurationReader.UpdateConfigFromFileContent(specFlowProject.Configuration.GeneratorConfiguration, configContent);
                }
            }

            return(specFlowProject);
        }
Ejemplo n.º 5
0
        public static SpecFlowProject LoadSpecFlowProjectFromMsBuild(string projectFile)
        {
            projectFile = Path.GetFullPath(projectFile);
            Project project = new Project();

            project.Load(projectFile, ProjectLoadSettings.IgnoreMissingImports);

            string projectFolder = Path.GetDirectoryName(projectFile);

            SpecFlowProject specFlowProject = new SpecFlowProject();

            specFlowProject.ProjectFolder    = projectFolder;
            specFlowProject.ProjectName      = Path.GetFileNameWithoutExtension(projectFile);
            specFlowProject.AssemblyName     = project.GetEvaluatedProperty("AssemblyName");
            specFlowProject.DefaultNamespace = project.GetEvaluatedProperty("RootNamespace");

            var items = project.GetEvaluatedItemsByName("None").Cast <BuildItem>()
                        .Concat(project.GetEvaluatedItemsByName("Content").Cast <BuildItem>());

            foreach (BuildItem item in items)
            {
                var extension = Path.GetExtension(item.FinalItemSpec);
                if (extension.Equals(".feature", StringComparison.InvariantCultureIgnoreCase))
                {
                    var featureFile = new SpecFlowFeatureFile(item.FinalItemSpec);
                    var ns          = item.GetEvaluatedMetadata("CustomToolNamespace");
                    if (!String.IsNullOrEmpty(ns))
                    {
                        featureFile.CustomNamespace = ns;
                    }
                    specFlowProject.FeatureFiles.Add(featureFile);
                }

                if (Path.GetFileName(item.FinalItemSpec).Equals("app.config", StringComparison.InvariantCultureIgnoreCase))
                {
                    GeneratorConfigurationReader.UpdateConfigFromFile(specFlowProject.GeneratorConfiguration, Path.Combine(projectFolder, item.FinalItemSpec));
                }
            }
            return(specFlowProject);
        }