public SpecFlowProject ReadSpecFlowProject(string projectFilePath, string rootNamespace) { try { var projectFolder = Path.GetDirectoryName(projectFilePath); var specFlowProject = new SpecFlowProject(); specFlowProject.ProjectSettings.ProjectFolder = projectFolder; specFlowProject.ProjectSettings.ProjectName = Path.GetFileNameWithoutExtension(projectFilePath); specFlowProject.ProjectSettings.DefaultNamespace = rootNamespace; specFlowProject.ProjectSettings.ProjectPlatformSettings.Language = _languageReader.GetLanguage(projectFilePath); specFlowProject.ProjectSettings.ConfigurationHolder = GetSpecFlowConfigurationHolder(projectFolder); if (specFlowProject.ProjectSettings.ConfigurationHolder != null) { specFlowProject.Configuration = _configurationLoader.LoadConfiguration(specFlowProject.ProjectSettings.ConfigurationHolder); } return(specFlowProject); } catch (Exception e) { throw new Exception("Error when reading project file.", e); } }
private SpecFlowProject LoadProjectSettings(SpecFlowProject specFlowProject, XDocument xDocument, string projectFolder, string projectFilePath, bool newProjectSystem) { var projectSettings = specFlowProject.ProjectSettings; projectSettings.ProjectFolder = projectFolder; projectSettings.ProjectName = Path.GetFileNameWithoutExtension(projectFilePath); projectSettings.DefaultNamespace = GetMsBuildProperty(xDocument, newProjectSystem, "RootNamespace"); projectSettings.AssemblyName = GetMsBuildProperty(xDocument, newProjectSystem, "AssemblyName"); if (newProjectSystem) { if (string.IsNullOrWhiteSpace(projectSettings.AssemblyName)) { projectSettings.AssemblyName = projectSettings.ProjectName; } if (string.IsNullOrWhiteSpace(projectSettings.DefaultNamespace)) { projectSettings.DefaultNamespace = projectSettings.ProjectName; } } projectSettings.ProjectPlatformSettings.Language = GetLanguage(xDocument, newProjectSystem); return(specFlowProject); }
private SpecFlowProject LoadAppConfig(SpecFlowProject specFlowProject, XDocument xDocument, string projectFolder, bool newProjectSystem) { var appConfigFile = GetAppConfigFile(xDocument, newProjectSystem, projectFolder); SpecFlowConfigurationHolder configurationHolder = null; if (!string.IsNullOrWhiteSpace(appConfigFile)) { var configFilePath = Path.Combine(projectFolder, appConfigFile); var configFileContent = File.ReadAllText(configFilePath); configurationHolder = GetConfigurationHolderFromFileContent(configFileContent); } var jsonConfigFile = GetJsonConfigFile(xDocument, newProjectSystem, projectFolder); if (!string.IsNullOrWhiteSpace(jsonConfigFile)) { var configFilePath = Path.Combine(projectFolder, jsonConfigFile); var configFileContent = File.ReadAllText(configFilePath); configurationHolder = new SpecFlowConfigurationHolder(ConfigSource.Json, configFileContent); } if (configurationHolder != null) { specFlowProject.ProjectSettings.ConfigurationHolder = configurationHolder; specFlowProject.Configuration = _configurationLoader.LoadConfiguration(configurationHolder); } return(specFlowProject); }
private SpecFlowProject LoadFeatureFiles(SpecFlowProject specFlowProject, XDocument xDocument, string projectFolder, bool newProjectSystem) { foreach (var item in GetFeatureFiles(xDocument, newProjectSystem, projectFolder)) { specFlowProject.FeatureFiles.Add(item); } return(specFlowProject); }
protected override FeatureFileInput CreateFeatureFileInput(FeatureFileInput featureFile, ITestGenerator generator, SpecFlowProject specFlowProject) { var featureFileInput = base.CreateFeatureFileInput(featureFile, generator, specFlowProject); outputFile = task.PrepareOutputFile(generator.GetTestFullPath(featureFileInput)); featureFileInput.GeneratedTestProjectRelativePath = FileSystemHelper.GetRelativePath(outputFile.FilePathForWriting, specFlowProject.ProjectSettings.ProjectFolder); return featureFileInput; }
public SpecFlowProject ReadSpecFlowProject(string projectFilePath) { var specFlowProject = new SpecFlowProject(); Microsoft.Build.Evaluation.Project project = null; string projectFolder = Path.GetDirectoryName(projectFilePath); try { var reader = XmlReader.Create(projectFilePath); project = ProjectCollection.GlobalProjectCollection.LoadProject(reader); specFlowProject.ProjectSettings.ProjectFolder = projectFolder; specFlowProject.ProjectSettings.ProjectName = Path.GetFileNameWithoutExtension(projectFilePath); specFlowProject.ProjectSettings.AssemblyName = project.AllEvaluatedProperties.First(x => x.Name == "AssemblyName").EvaluatedValue; specFlowProject.ProjectSettings.DefaultNamespace = project.AllEvaluatedProperties.First(x => x.Name == "RootNamespace").EvaluatedValue; } catch (Exception ex) { Debug.WriteLine(ex, "Project load error"); return(new SpecFlowProject()); } specFlowProject.ProjectSettings.ProjectPlatformSettings.Language = GetLanguage(project); foreach (ProjectItem item in project.FeatureFiles()) { var featureFile = new FeatureFileInput(item.EvaluatedInclude); var ns = item.GetMetadataValue("CustomToolNamespace"); if (!String.IsNullOrEmpty(ns)) { featureFile.CustomNamespace = ns; } specFlowProject.FeatureFiles.Add(featureFile); } ProjectItem appConfigItem = project.ApplicationConfigurationFile(); if (appConfigItem != null) { var configFilePath = Path.Combine(projectFolder, appConfigItem.EvaluatedInclude); var configFileContent = File.ReadAllText(configFilePath); var configurationHolder = GetConfigurationHolderFromFileContent(configFileContent); specFlowProject.ProjectSettings.ConfigurationHolder = configurationHolder; specFlowProject.Configuration = configurationLoader.LoadConfiguration(configurationHolder); } return(specFlowProject); }
public SpecFlowProject ReadSpecFlowProject(IProjectReference projectReference) { var projectFilePath = FileProjectReference.AssertFileProjectReference(projectReference).ProjectFilePath; var project = Engine.GlobalEngine.GetLoadedProject(projectFilePath); if (project == null) { project = new Microsoft.Build.BuildEngine.Project(); project.Load(projectFilePath, ProjectLoadSettings.IgnoreMissingImports); } string projectFolder = Path.GetDirectoryName(projectFilePath); SpecFlowProject specFlowProject = new SpecFlowProject(); specFlowProject.ProjectSettings.ProjectFolder = projectFolder; specFlowProject.ProjectSettings.ProjectName = Path.GetFileNameWithoutExtension(projectFilePath); specFlowProject.ProjectSettings.AssemblyName = project.GetEvaluatedProperty("AssemblyName"); specFlowProject.ProjectSettings.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 FeatureFileInput(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)) { var configFilePath = Path.Combine(projectFolder, item.FinalItemSpec); var configFileContent = File.ReadAllText(configFilePath); var configurationHolder = GetConfigurationHolderFromFileContent(configFileContent); specFlowProject.ProjectSettings.ConfigurationHolder = configurationHolder; specFlowProject.Configuration = configurationLoader.LoadConfiguration(configurationHolder, projectReference); } } return(specFlowProject); }
public SpecFlowProject ReadSpecFlowProject(string projectFilePath) { var projectFolder = Path.GetDirectoryName(projectFilePath); using (var filestream = new FileStream(projectFilePath, FileMode.Open)) { var xDocument = XDocument.Load(filestream); var newProjectSystem = IsNewProjectSystem(xDocument); var specFlowProject = new SpecFlowProject(); specFlowProject = LoadProjectSettings(specFlowProject, xDocument, projectFolder, projectFilePath, newProjectSystem); specFlowProject = LoadFeatureFiles(specFlowProject, xDocument, projectFolder, newProjectSystem); specFlowProject = LoadAppConfig(specFlowProject, xDocument, projectFolder, newProjectSystem); return(specFlowProject); } }
public static List<SpecFlowDocument> GetParsedFeatures(SpecFlowProject specFlowProject) { return GetParsedFeatures(specFlowProject.FeatureFiles.Select(ff => ff.GetFullPath(specFlowProject.ProjectSettings)), specFlowProject.Configuration.GeneratorConfiguration.FeatureLanguage); }
/// <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); } }
private static IEnumerable<string> GetStepAssemblies(SpecFlowProject specFlowProject) { yield return specFlowProject.ProjectSettings.AssemblyName; foreach (var stepAssembly in specFlowProject.Configuration.RuntimeConfiguration.AdditionalStepAssemblies) { yield return stepAssembly; } }
internal static List<BindingInfo> CollectBindings(SpecFlowProject specFlowProject, string basePath) { var reportingFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); AppDomainSetup appDomainSetup = new AppDomainSetup(); appDomainSetup.ApplicationBase = reportingFolder; AppDomain appDomain = AppDomain.CreateDomain("CollectBindings", null, appDomainSetup); AssemblyServices.SubscribeAssemblyResolve(appDomain, basePath); BindingCollector bindingCollector = (BindingCollector)appDomain.CreateInstanceAndUnwrap( Assembly.GetExecutingAssembly().GetName().FullName, typeof(BindingCollector).FullName); var stepAssemblies = GetStepAssemblies(specFlowProject); List<BindingInfo> bindings = stepAssemblies.SelectMany(bindingCollector.CollectBindings).ToList(); AppDomain.Unload(appDomain); return bindings; }