public void CanLoadConfigFromString(string configString) { var runtimeConfig = ConfigurationLoader.GetDefault(); var configurationLoader = new AppConfigConfigurationLoader(); var configurationSectionHandler = ConfigurationSectionHandler.CreateFromXml(configString); configurationLoader.LoadAppConfig(runtimeConfig, configurationSectionHandler); }
public void Configure() { var configuration = ConfigurationSectionHandler.GetConfiguration(); if (configuration.Components.Count == 0) { throw new ConfigurationErrorsException("There are no components defined to externally configure the container in the application configuration file."); } this.RegisterInternal(configuration); }
public void Check_Plugins_Parameters() { string config = @"<specflow><plugins><add name=""testEntry"" parameters=""pluginParameter""/></plugins></specflow>"; var configSection = ConfigurationSectionHandler.CreateFromXml(config); var runtimeConfig = new AppConfigConfigurationLoader().LoadAppConfig(ConfigurationLoader.GetDefault(), configSection); runtimeConfig.Plugins.Count.Should().Be(1); runtimeConfig.Plugins.First().Parameters.Should().Be("pluginParameter"); }
public void Check_CucumberMessages_NotConfigured_EnabledIsFalse() { string config = @"<specflow> </specflow>"; var configSection = ConfigurationSectionHandler.CreateFromXml(config); var runtimeConfig = new AppConfigConfigurationLoader().LoadAppConfig(ConfigurationLoader.GetDefault(), configSection); runtimeConfig.CucumberMessagesConfiguration.Enabled.Should().BeFalse(); }
public void Check_Plugins_PluginType_GeneratorAndRuntime() { string config = @"<specflow><plugins><add name=""testEntry"" type=""GeneratorAndRuntime""/></plugins></specflow>"; var configSection = ConfigurationSectionHandler.CreateFromXml(config); var runtimeConfig = new AppConfigConfigurationLoader().LoadAppConfig(ConfigurationLoader.GetDefault(), configSection); runtimeConfig.Plugins.Count.Should().Be(1); runtimeConfig.Plugins.First().Type.Should().Be(PluginType.GeneratorAndRuntime); }
private void btnChooseServerCert_Click(object sender, EventArgs e) { var cert = ConfigurationSectionHandler.ChooseCertificate((StoreName)cbxServerStore.SelectedItem, (StoreLocation)cbxServerStoreLocation.SelectedItem, true); if (cert == null) { return; } txtServerCert.Text = cert.Thumbprint; txtServerCert.Tag = cert; }
public void Check_StepAssemblies_OneEntry() { string config = @"<specflow><stepAssemblies><stepAssembly assembly=""testEntry""/></stepAssemblies></specflow>"; var configSection = ConfigurationSectionHandler.CreateFromXml(config); var runtimeConfig = new AppConfigConfigurationLoader().LoadAppConfig(ConfigurationLoader.GetDefault(), configSection); runtimeConfig.AdditionalStepAssemblies.Count.Should().Be(1); runtimeConfig.AdditionalStepAssemblies.First().Should().Be("testEntry"); }
static void TestConfig() { ConfigurationSectionHandler v = new ConfigurationSectionHandler(); var filtersSection = (ConfigurationSectionHandler)ConfigurationManager.GetSection("csvDataImport"); foreach (Field field in filtersSection.Fields) { Console.WriteLine("Field index {0} and type: {1}", field.Index, field.Type); } }
public void CanLoadConfigWithParallelCodeGenerationOptionsFromString(string configString) { var generatorConfiguration = new GeneratorConfiguration(); generatorConfiguration.UpdateFromConfigFile(ConfigurationSectionHandler.CreateFromXml(configString)); Assert.IsTrue(generatorConfiguration.MarkFeaturesParallelizable); Assert.IsNotEmpty(generatorConfiguration.SkipParallelizableMarkerForTags); Assert.Contains("mySpecialTag1", generatorConfiguration.SkipParallelizableMarkerForTags); Assert.Contains("mySpecialTag2", generatorConfiguration.SkipParallelizableMarkerForTags); }
public IEnumerable <PluginDescriptor> GetPlugins() { ConfigurationSectionHandler section = GetSection(); if (section == null || section.Plugins == null) { return(Enumerable.Empty <PluginDescriptor>()); } return(section.Plugins.Select(pce => new PluginDescriptor(pce.Name))); }
public void Check_Plugins_TwoSameNameEntry() { string config = @"<specflow><plugins> <add name=""testEntry""/> <add name=""testEntry""/> </plugins></specflow>"; var configSection = ConfigurationSectionHandler.CreateFromXml(config); var runtimeConfig = new AppConfigConfigurationLoader().LoadAppConfig(ConfigurationLoader.GetDefault(), configSection); runtimeConfig.Plugins.Count.Should().Be(1); runtimeConfig.Plugins[0].Name.Should().Be("testEntry"); }
public void Check_Trace_Listener() { string config = @"<specflow><trace listener=""TraceListener"" /></specflow>"; var configSection = ConfigurationSectionHandler.CreateFromXml(config); var runtimeConfig = new AppConfigConfigurationLoader().LoadAppConfig(ConfigurationLoader.GetDefault(), configSection); runtimeConfig.CustomDependencies.Count.Should().Be(1); foreach (ContainerRegistrationConfigElement containerRegistrationConfigElement in runtimeConfig.CustomDependencies) { containerRegistrationConfigElement.Implementation.Should().Be("TraceListener"); } }
private ConfigurationSectionHandler GetSection() { XmlDocument configDocument = new XmlDocument(); configDocument.LoadXml(configFileContent); var specFlowNode = configDocument.SelectSingleNode("/configuration/specFlow"); if (specFlowNode == null) { throw new InvalidOperationException("invalid config file content"); } return(ConfigurationSectionHandler.CreateFromXml(specFlowNode)); }
public void Check_CucumberMessages_Sinks_EmptyList() { string config = @"<specflow> <cucumber-messages enabled=""false""> <sinks> </sinks> </cucumber-messages> </specflow>"; var configSection = ConfigurationSectionHandler.CreateFromXml(config); var runtimeConfig = new AppConfigConfigurationLoader().LoadAppConfig(ConfigurationLoader.GetDefault(), configSection); runtimeConfig.CucumberMessagesConfiguration.Sinks.Should().BeEmpty(); }
public SpecFlowConfiguration LoadConfiguration(SpecFlowConfiguration specFlowConfiguration) { if (IsJsonConfig) { var jsonConfigurationLoader = new JsonConfigurationLoader(); return(jsonConfigurationLoader.LoadJson(specFlowConfiguration, configFileContent)); } ConfigurationSectionHandler section = GetSection(); var runtimeConfigurationLoader = new AppConfigConfigurationLoader(); return(runtimeConfigurationLoader.LoadAppConfig(specFlowConfiguration, section)); }
public void TestCheckForScreenshotWithNoErrorButSettingEnabledTakesSuccessfulScreenshot() { var listener = new Mock <ITraceListener>(MockBehavior.Strict); listener.Setup(l => l.WriteTestOutput(It.Is <string>(s => s.Contains("TestFileName.jpg")))); var scenarioContext = new Mock <IScenarioContextHelper>(MockBehavior.Strict); scenarioContext.Setup(s => s.GetError()).Returns((Exception)null); scenarioContext.Setup(s => s.GetStepFileName(false)).Returns("TestFileName"); var browser = new Mock <IBrowser>(MockBehavior.Strict); browser.Setup(b => b.TakeScreenshot(It.IsAny <string>(), "TestFileName")).Returns("TestFileName.jpg"); browser.Setup(b => b.SaveHtml(It.IsAny <string>(), "TestFileName")).Returns((string)null); browser.Setup(b => b.Close(true)); browser.Setup(b => b.IsCreated).Returns(true); var container = new Mock <IObjectContainer>(MockBehavior.Strict); container.Setup(c => c.Resolve <IScenarioContextHelper>()).Returns(scenarioContext.Object); container.Setup(c => c.Resolve <ITraceListener>()).Returns(listener.Object); WebDriverSupport.Browser = browser.Object; var driverSupport = new WebDriverSupport(container.Object); // Setup Configuration var config = new ConfigurationSectionHandler { BrowserFactory = new BrowserFactoryConfigurationElement { CreateScreenshotOnExit = true } }; WebDriverSupport.ConfigurationMethod = new Lazy <ConfigurationSectionHandler>(() => config); driverSupport.CheckForScreenshot(); config.BrowserFactory.CreateScreenshotOnExit = false; WebDriverSupport.ConfigurationMethod = new Lazy <ConfigurationSectionHandler>(() => config); container.VerifyAll(); browser.VerifyAll(); scenarioContext.VerifyAll(); listener.VerifyAll(); }
public void AddFromXmlSpecFlowSection(string specFlowSection) { ProjectBuilder project = _solutionDriver.DefaultProject; var configSection = ConfigurationSectionHandler.CreateFromXml(specFlowSection); var appConfigConfigurationLoader = new AppConfigConfigurationLoader(); var specFlowConfiguration = appConfigConfigurationLoader.LoadAppConfig(ConfigurationLoader.GetDefault(), configSection); foreach (string stepAssemblyName in specFlowConfiguration.AdditionalStepAssemblies) { _configurationDriver.AddStepAssembly(new StepAssembly(stepAssemblyName)); } _configurationDriver.SetBindingCulture(project, specFlowConfiguration.BindingCulture); _configurationDriver.SetFeatureLanguage(project, specFlowConfiguration.FeatureLanguage); }
public void Check_CucumberMessages_Sinks_ListOneEntry() { string config = @"<specflow> <cucumber-messages enabled=""false""> <sinks> <sink type=""file"" path=""C:\temp\testrun.cm"" /> </sinks> </cucumber-messages> </specflow>"; var configSection = ConfigurationSectionHandler.CreateFromXml(config); var runtimeConfig = new AppConfigConfigurationLoader().LoadAppConfig(ConfigurationLoader.GetDefault(), configSection); runtimeConfig.CucumberMessagesConfiguration.Sinks.Count.Should().Be(1); }
public virtual SpecFlowProjectConfiguration LoadConfiguration(SpecFlowConfigurationHolder configurationHolder, IProjectReference projectReference) { SpecFlowProjectConfiguration configuration = new SpecFlowProjectConfiguration(); if (configurationHolder != null && configurationHolder.HasConfiguration) { ConfigurationSectionHandler specFlowConfigSection = ConfigurationSectionHandler.CreateFromXml(configurationHolder.XmlString); if (specFlowConfigSection != null) { configuration.GeneratorConfiguration.UpdateFromConfigFile(specFlowConfigSection); configuration.RuntimeConfiguration.UpdateFromConfigFile(specFlowConfigSection); } } configuration.GeneratorConfiguration.GeneratorVersion = GetGeneratorVersion(projectReference); return(configuration); }
public SpecFlowConfiguration Load(SpecFlowConfiguration specFlowConfiguration, IConfigurationHolder configurationHolder) { switch (configurationHolder.ConfigSource) { case ConfigSource.AppConfig: return(LoadAppConfig(specFlowConfiguration, ConfigurationSectionHandler.CreateFromXml(configurationHolder.Content))); case ConfigSource.Json: return(LoadJson(specFlowConfiguration, configurationHolder.Content)); case ConfigSource.Default: return(GetDefault()); default: throw new ArgumentOutOfRangeException(); } }
public void CanLoadConfigWithParallelCodeGenerationOptionsFromString(string configString) { var specFlowConfiguration = ConfigurationLoader.GetDefault(); var configurationLoader = new AppConfigConfigurationLoader(); var configurationSectionHandler = ConfigurationSectionHandler.CreateFromXml(configString); specFlowConfiguration = configurationLoader.LoadAppConfig(specFlowConfiguration, configurationSectionHandler); Assert.IsTrue(specFlowConfiguration.MarkFeaturesParallelizable); Assert.IsNotEmpty(specFlowConfiguration.SkipParallelizableMarkerForTags); Assert.Contains("mySpecialTag1", specFlowConfiguration.SkipParallelizableMarkerForTags); Assert.Contains("mySpecialTag2", specFlowConfiguration.SkipParallelizableMarkerForTags); }
internal void UpdateFromConfigFile(ConfigurationSectionHandler configSection, bool loadPlugins) { if (configSection == null) { throw new ArgumentNullException("configSection"); } if (configSection.Language != null) { FeatureLanguage = CultureInfo.GetCultureInfo(configSection.Language.Feature); ToolLanguage = string.IsNullOrEmpty(configSection.Language.Tool) ? FeatureLanguage : CultureInfo.GetCultureInfo(configSection.Language.Tool); } if (configSection.UnitTestProvider != null) { SetUnitTestDefaultsByName(configSection.UnitTestProvider.Name); if (!string.IsNullOrEmpty(configSection.UnitTestProvider.GeneratorProvider)) { if (loadPlugins) { GeneratorUnitTestProviderType = GetTypeConfig(configSection.UnitTestProvider.GeneratorProvider); } UsesPlugins = true; } //TODO: config.CheckUnitTestConfig(); } if (configSection.Generator != null) { AllowDebugGeneratedFiles = configSection.Generator.AllowDebugGeneratedFiles; AllowRowTests = configSection.Generator.AllowRowTests; GenerateAsyncTests = configSection.Generator.GenerateAsyncTests; GeneratorPath = configSection.Generator.GeneratorPath; } if (configSection.Generator != null && configSection.Generator.Dependencies != null) { CustomDependencies = configSection.Generator.Dependencies; UsesPlugins = true; //TODO: this calculation can be refined later } }
/// <summary> /// Gets the configuration section. /// </summary> /// <returns>The located configuration section, otherwise <c>null</c>.</returns> private ConfigurationSectionHandler GetConfigurationSection() { // Reflect content for now WriteLine("Project Folder: {0}", this.projectSettings != null ? this.projectSettings.ProjectFolder : "NONE"); if (this.projectSettings == null || string.IsNullOrEmpty(this.projectSettings.ProjectFolder)) { return(null); } var directory = new DirectoryInfo(this.projectSettings.ProjectFolder); var file = directory.GetFiles("app.config", SearchOption.TopDirectoryOnly).FirstOrDefault(); if (file == null) { WriteLine(@"Cannot find app.config in directory: {0}", directory.FullName); return(null); } WriteLine("Found Configuration File: {0}", file.FullName); string content; using (var streamReader = file.OpenText()) { content = streamReader.ReadToEnd(); } var configDocument = new XmlDocument(); configDocument.LoadXml(content); var node = configDocument.SelectSingleNode("/configuration/specBind"); if (node == null) { WriteLine("Could not locate specBind configuration node"); return(null); } var xml = node.OuterXml; WriteLine("Creating configuration from XML: {0}", xml); return(ConfigurationSectionHandler.CreateFromXml(xml)); }
public static TypeResolver ReadConfiguration(string location) { XmlDocument doc = new XmlDocument(); if (!File.Exists(location)) { throw new FileNotFoundException("The configuration file does not exist", location); } doc.Load(location); XmlNode node = doc.SelectSingleNode("configuration/PressPlay/FFWD"); if (node == null) { throw new Exception("The configuration needs a node at the path configuration/PressPlay/FFWD to read from."); } ConfigurationSectionHandler handler = new ConfigurationSectionHandler(); return((TypeResolver)handler.Create(null, null, node)); }
public IEnumerable <PluginDescriptor> GetPlugins(SpecFlowConfigurationHolder configurationHolder) { try { if (configurationHolder != null && configurationHolder.HasConfiguration) { ConfigurationSectionHandler section = ConfigurationSectionHandler.CreateFromXml(configurationHolder.XmlString); if (section != null && section.Plugins != null) { return(section.Plugins.Select(pce => pce.ToPluginDescriptor())); } } return(Enumerable.Empty <PluginDescriptor>()); } catch (Exception ex) { throw new ConfigurationErrorsException("SpecFlow configuration error", ex); } }
public virtual void LoadConfiguration(SpecFlowConfigurationHolder configurationHolder, SpecFlowProjectConfiguration configuration) { try { if (configurationHolder != null && configurationHolder.HasConfiguration) { ConfigurationSectionHandler specFlowConfigSection = ConfigurationSectionHandler.CreateFromXml(configurationHolder.XmlString); if (specFlowConfigSection != null) { UpdateGeneratorConfiguration(configuration, specFlowConfigSection); UpdateRuntimeConfiguration(configuration, specFlowConfigSection); } } } catch (Exception ex) { throw new ConfigurationErrorsException("SpecFlow configuration error", ex); } }
public void CanLoadConfigWithNonParallelizableTagsProvided() { var config = @"<specFlow> <generator> <addNonParallelizableMarkerForTags> <tag value=""tag1""/> <tag value=""tag2""/> </addNonParallelizableMarkerForTags> </generator> </specFlow>"; var specFlowConfiguration = ConfigurationLoader.GetDefault(); var configurationLoader = new AppConfigConfigurationLoader(); var configurationSectionHandler = ConfigurationSectionHandler.CreateFromXml(config); specFlowConfiguration = configurationLoader.LoadAppConfig(specFlowConfiguration, configurationSectionHandler); specFlowConfiguration.AddNonParallelizableMarkerForTags.Should().BeEquivalentTo("tag1", "tag2"); }
public SpecFlowConfiguration Load(SpecFlowConfiguration specFlowConfiguration) { if (_configFilePath == null) { return(LoadDefaultConfiguration(specFlowConfiguration)); } var extension = Path.GetExtension(_configFilePath); var configFileContent = File.ReadAllText(_configFilePath); switch (extension.ToLowerInvariant()) { case ".config": { var configDocument = new XmlDocument(); configDocument.LoadXml(configFileContent); var specFlowNode = configDocument.SelectSingleNode("/configuration/specFlow"); if (specFlowNode == null) { return(LoadDefaultConfiguration(specFlowConfiguration)); } var configSection = ConfigurationSectionHandler.CreateFromXml(specFlowNode); var loader = new AppConfigConfigurationLoader(); return(loader.LoadAppConfig(specFlowConfiguration, configSection)); } case ".json": { if (_jsonSpecFlow2Mode) { configFileContent = ConvertToJsonSpecFlow2Style(configFileContent); } var loader = new JsonConfigurationLoader(); return(loader.LoadJson(specFlowConfiguration, configFileContent)); } } throw new ConfigurationErrorsException($"Invalid config type: {_configFilePath}"); }
/// <summary> /// Static constructor for this persistence service /// </summary> static DatabasePersistenceService() { m_configuration = ConfigurationManager.GetSection("marc.hi.ehrs.cr.persistence.data") as ConfigurationSectionHandler; m_persisters = new Dictionary <Type, IComponentPersister>(); // Verify that the database can be used foreach (var cm in new ConnectionManager[] { m_configuration.ConnectionManager, m_configuration.ReadonlyConnectionManager }) { var conn = cm.GetConnection(); try { var dbVer = DbUtil.GetSchemaVersion(conn); if (dbVer.CompareTo(typeof(DatabasePersistenceService).Assembly.GetName().Version) < 0) { throw new DataException(String.Format("The schema version '{0}' is less than the expected version of '{1}'", dbVer, typeof(DatabasePersistenceService).Assembly.GetName().Version)); } else { Trace.TraceInformation("Using Client Registry Schem Version '{0}'", dbVer); } } finally { conn.Close(); } } // Scan this assembly for helpers Type[] persistenceTypes = Array.FindAll <Type>(typeof(DatabasePersistenceService).Assembly.GetTypes(), o => o.GetInterface(typeof(IComponentPersister).FullName) != null); // Persistence helpers foreach (var t in persistenceTypes) { ConstructorInfo ci = t.GetConstructor(Type.EmptyTypes); IComponentPersister instance = ci.Invoke(null) as IComponentPersister; m_persisters.Add(instance.HandlesComponent, instance); } }
public void TestTearDownAfterScenarioWhenReuseBrowserIsTrue() { // arrange var config = new ConfigurationSectionHandler { BrowserFactory = new BrowserFactoryConfigurationElement { ReuseBrowser = true } }; var browser = new Mock <IBrowser>(MockBehavior.Loose); WebDriverSupport.Browser = browser.Object; WebDriverSupport.ConfigurationMethod = new Lazy <ConfigurationSectionHandler>(() => config); // act WebDriverSupport.TearDownAfterScenario(); // assert browser.Verify(b => b.Close(true), Times.Never()); }