public static SpecFlowProject ReadSpecFlowProject(string projectPath, SourceAssemblyProbe sourceAssemblyProbe, string defaultNameSpace = null) { var specFlowProject = new SpecFlowProject(); specFlowProject.ProjectSettings.ProjectFolder = projectPath; specFlowProject.ProjectSettings.ProjectName = sourceAssemblyProbe.AssemblyName; var projectSettings = specFlowProject.ProjectSettings; projectSettings.AssemblyName = sourceAssemblyProbe.AssemblyName; projectSettings.DefaultNamespace = defaultNameSpace ?? sourceAssemblyProbe.AssemblyName; var featureFiles = Directory .GetFiles(projectPath, "*.feature", SearchOption.AllDirectories) .Select(file => new FeatureFileInput(file) { CustomNamespace = projectSettings.DefaultNamespace + DirectoryUtils.GetContainingDirectory(file) .Replace(projectPath, string.Empty) .Replace(Path.DirectorySeparatorChar, '.') }); specFlowProject.FeatureFiles.AddRange(featureFiles); Configure(specFlowProject, sourceAssemblyProbe); return(specFlowProject); }
static void Configure(SpecFlowProject specFlowProject, SourceAssemblyProbe sourceAssemblyProbe) { const string defaultConfiguration = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <configSections> <section name=""specFlow"" type=""TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"" /> </configSections> <specFlow> <unitTestProvider name=""SpecRun"" /> <plugins> <add name=""SpecRun"" /> </plugins> </specFlow> </configuration>"; var configurationContent = sourceAssemblyProbe.HasSpecFlowConfigured ? File.ReadAllText(sourceAssemblyProbe.AssemblyPath + ".config") : defaultConfiguration; var configurationHolderFromFileContent = GetConfigurationHolderFromContent(configurationContent); specFlowProject.ProjectSettings.ConfigurationHolder = configurationHolderFromFileContent; specFlowProject.Configuration = new GeneratorConfigurationProvider().LoadConfiguration(configurationHolderFromFileContent); }