public void Remove(NameValueConfigurationElement nameValue)
 {
     if (BaseIndexOf(nameValue) >= 0)
     {
         BaseRemove(nameValue.Name);
     }
 }
        public void SetElement_NoElementWithGivenName_Ok()
        {
            var collection = new NameValueConfigurationCollection();

            collection["foo"] = new NameValueConfigurationElement("foo", "bar");
            Assert.Equal("bar", collection["foo"].Value);
        }
        public void SetElement_IndexAndElementNameMismatch_ElementNameIsUsed()
        {
            var collection = new NameValueConfigurationCollection();

            collection["foo"] = new NameValueConfigurationElement("fooMismatched", "bar");
            Assert.Equal("bar", collection["fooMismatched"].Value);
            Assert.Null(collection["foo"]);
        }
        public void Add_NullValue_Ok()
        {
            var collection = new NameValueConfigurationCollection();
            var element    = new NameValueConfigurationElement("foo", null);

            collection.Add(element);
            Assert.Null(collection["foo"].Value);
        }
        public void Add_ElementWithExistingName_Throws()
        {
            var collection = new NameValueConfigurationCollection();
            var element1   = new NameValueConfigurationElement("foo", "foo");
            var element2   = new NameValueConfigurationElement("foo", "bar");

            collection.Add(element1);
            Assert.Throws <ConfigurationErrorsException>(() => collection.Add(element2));
        }
示例#6
0
		public IEnumerable<KeyValuePair<string, string>> GetNameValueItems()
		{
			foreach ( string key in this.ConfigurationCollection.AllKeys )
			{
				NameValueConfigurationElement confElement = this.ConfigurationCollection[key];
				yield return new KeyValuePair<string, string>
					(confElement.Name, confElement.Value);
			}
		}
        public void Value_AssignNewValue_Ok()
        {
            var collection = new NameValueConfigurationCollection();
            var element    = new NameValueConfigurationElement("foo", "foo");

            collection.Add(element);
            collection["foo"].Value = "bar";
            Assert.Equal("bar", collection["foo"].Value);
        }
        public void Clear_NotEmptyCollection_EmptyCollection()
        {
            var collection = new NameValueConfigurationCollection();
            var element    = new NameValueConfigurationElement("foo", "foo");

            collection.Add(element);
            Assert.NotEmpty(collection);
            collection.Clear();
            Assert.Empty(collection);
        }
示例#9
0
        /// <summary>
        /// Converts the NameValueConfigurationCollection to a collection of key value pairs.
        /// </summary>
        /// <param name="collection">The name value configuration collection.</param>
        /// <returns>A collection of key value pairs.</returns>
        public static IEnumerable <KeyValuePair <string, string> > ToKeyValuePairs(
            this NameValueConfigurationCollection collection)
        {
            foreach (string key in collection.AllKeys)
            {
                NameValueConfigurationElement element = collection[key];

                yield return(new KeyValuePair <string, string>(element.Name, element.Value));
            }
        }
        public void Remove_ByName_ElementIsNull()
        {
            var collection = new NameValueConfigurationCollection();
            var element    = new NameValueConfigurationElement("foo", "foo");

            collection.Add(element);
            Assert.Equal("foo", collection["foo"].Value);
            collection.Remove("foo");
            Assert.Null(collection["foo"]);
        }
 public new NameValueConfigurationElement this[string name]
 {
     get { return((NameValueConfigurationElement)BaseGet(name)); }
     set
     {
         int index = -1; // append by default
         NameValueConfigurationElement tempElement = (NameValueConfigurationElement)BaseGet(name);
         if (tempElement != null)
         {
             index = BaseIndexOf(tempElement);
             BaseRemoveAt(index);
         }
         BaseAdd(index, value);
     }
 }
        public static string GetServiceProvider(string service, string provider)
        {
            IServiceConfig config = GetServiceConfig(service);

            if (config == null)
            {
                return(string.Empty);
            }

            NameValueConfigurationElement element = config.Providers[provider];

            if (element == null)
            {
                return(string.Empty);
            }
            else
            {
                return(element.Value);
            }
        }
示例#13
0
        private void CopyEnvironmentOverrides(EnvironmentMergeSection environmentMergeSection, Dictionary <string, ConfigurationNodeMergeData> mergeDataByPath, IConfigurationUIHierarchy configurationHierarchy)
        {
            foreach (string path in mergeDataByPath.Keys)
            {
                ConfigurationNodeMergeData mergeData = mergeDataByPath[path];

                EnvironmentNodeMergeElement mergeElement = new EnvironmentNodeMergeElement();
                mergeElement.ConfigurationNodePath = path;
                mergeElement.OverrideProperties    = mergeData.OverrideProperties;

                foreach (string propertyName in mergeData.AllPropertyNames)
                {
                    object propertyValue            = mergeData.GetPropertyValue(propertyName, typeof(string), null, configurationHierarchy);
                    string serializedRepresentation = SerializationUtility.SerializeToString(propertyValue, configurationHierarchy);

                    NameValueConfigurationElement keyValue = new NameValueConfigurationElement(propertyName, serializedRepresentation);
                    mergeElement.OverriddenProperties.Add(keyValue);
                }

                environmentMergeSection.MergeElements.Add(mergeElement);
            }
        }
 public void Remove(NameValueConfigurationElement nameValue)
 {
     throw new NotImplementedException();
 }
 public void Add(NameValueConfigurationElement nameValue)
 {
     BaseAdd(nameValue, false);
 }
示例#16
0
        /// <summary>
        /// Gets the setting with the specified name. If the setting is not found, returns null.
        /// </summary>
        /// <param name="name">The name of the setting to lookup.</param>
        /// <returns>The value associated with the setting name. If the name is not found, returns null.</returns>
        public string Setting(string name)
        {
            NameValueConfigurationElement config = Settings[name];

            return((config == null) ? null : config.Value);
        }
示例#17
0
        static void Main(string[] args)
        {
            try
            {
                // Set the path of the config file.
                // Make sure that you have a Web site on the
                // same server called TestConfig.
                string configPath = "/TestConfig";

                // Get the Web application configuration object.
                Configuration config =
                    WebConfigurationManager.OpenWebConfiguration(configPath);

                // Get the section related object.
                AnonymousIdentificationSection configSection =
                    (AnonymousIdentificationSection)config.GetSection
                        ("system.web/anonymousIdentification");

                // Display title and info.
                Console.WriteLine("Configuration Info");
                Console.WriteLine();

                // Display Config details.
                Console.WriteLine("File Path: {0}",
                                  config.FilePath);
                Console.WriteLine("Section Path: {0}",
                                  configSection.SectionInformation.Name);
                Console.WriteLine();

                // Create a NameValueConfigurationCollection object.
                NameValueConfigurationCollection myNameValConfigCollection =
                    new NameValueConfigurationCollection();

                foreach (PropertyInformation propertyItem in
                         configSection.ElementInformation.Properties)
                {
                    // Assign  domain name.
                    if (propertyItem.Name == "domain")
                    {
                        propertyItem.Value = "MyDomain";
                    }

                    if (propertyItem.Value != null)
                    {
                        // Enable SSL for cookie exchange.
                        if (propertyItem.Name == "cookieRequireSSL")
                        {
                            propertyItem.Value = true;
                        }

                        NameValueConfigurationElement nameValConfigElement =
                            new NameValueConfigurationElement
                                (propertyItem.Name.ToString(), propertyItem.Value.ToString());

                        // Add a NameValueConfigurationElement
                        // to the collection.
                        myNameValConfigCollection.Add(nameValConfigElement);
                    }
                }

                // Count property.
                Console.WriteLine("Collection Count: {0}",
                                  myNameValConfigCollection.Count);

                // Item property.
                Console.WriteLine("Value of property 'enabled': {0}",
                                  myNameValConfigCollection["enabled"].Value);

                // Display the contents of the collection.
                foreach (NameValueConfigurationElement configItem
                         in myNameValConfigCollection)
                {
                    Console.WriteLine();
                    Console.WriteLine("Configuration Details:");
                    Console.WriteLine("Name: {0}", configItem.Name);
                    Console.WriteLine("Value: {0}", configItem.Value);
                }

                // Assign the domain calue.
                configSection.Domain = myNameValConfigCollection["domain"].Value;
                // Assign the SSL required value.
                if (myNameValConfigCollection["cookieRequireSSL"].Value == "true")
                {
                    configSection.CookieRequireSSL = true;
                }

                // Remove domain from the collection.
                NameValueConfigurationElement myConfigElement =
                    myNameValConfigCollection["domain"];
                // Remove method.
                myNameValConfigCollection.Remove(myConfigElement);

                // Save changes to the configuration file.
                // This modifies the Web.config of the TestConfig site.
                config.Save(ConfigurationSaveMode.Minimal, true);

                // Clear the collection.
                myNameValConfigCollection.Clear();
            }

            catch (Exception e)
            {
                // Unknown error.
                Console.WriteLine(e.ToString());
            }

            // Display and wait.
            Console.ReadLine();
        }
 // Methods
 public void Add(NameValueConfigurationElement nameValue)
 {
 }
示例#19
0
        /// <summary>
        /// Creates the web driver.
        /// </summary>
        /// <param name="browserType">Type of the browser.</param>
        /// <param name="browserFactoryConfiguration">The browser factory configuration.</param>
        /// <returns>The created web driver.</returns>
        /// <exception cref="System.InvalidOperationException">Thrown if the browser is not supported.</exception>
        internal static IWebDriver CreateWebDriver(BrowserType browserType, BrowserFactoryConfigurationElement browserFactoryConfiguration)
        {
            if (!RemoteDriverExists(browserFactoryConfiguration.Settings, browserType, out IWebDriver driver))
            {
                switch (browserType)
                {
                case BrowserType.IE:

                    NameValueConfigurationElement ignoreProtectedModeSettingsNameValueConfigurationElement
                        = browserFactoryConfiguration.Settings[IgnoreProtectedModeSettings];
                    bool ignoreProtectedModeSettings = false;
                    if (!string.IsNullOrWhiteSpace(ignoreProtectedModeSettingsNameValueConfigurationElement?.Value))
                    {
                        if (!bool.TryParse(ignoreProtectedModeSettingsNameValueConfigurationElement.Value, out ignoreProtectedModeSettings))
                        {
                            throw new ConfigurationErrorsException(
                                      $"The {IgnoreProtectedModeSettings} setting is not a valid boolean: {ignoreProtectedModeSettingsNameValueConfigurationElement.Value}");
                        }
                    }

                    var explorerOptions = new InternetExplorerOptions
                    {
                        EnsureCleanSession = browserFactoryConfiguration.EnsureCleanSession,
                        IntroduceInstabilityByIgnoringProtectedModeSettings = ignoreProtectedModeSettings
                    };

                    var internetExplorerDriverService = InternetExplorerDriverService.CreateDefaultService();
                    internetExplorerDriverService.HideCommandPromptWindow = true;
                    driver = new InternetExplorerDriver(internetExplorerDriverService, explorerOptions);
                    break;

                case BrowserType.FireFox:
                    driver = GetFireFoxDriver(browserFactoryConfiguration);
                    break;

                case BrowserType.Chrome:
                case BrowserType.ChromeHeadless:
                    var chromeOptions = new ChromeOptions {
                        LeaveBrowserRunning = false
                    };

                    var cmdLineSetting = browserFactoryConfiguration.Settings[ChromeArgumentSetting];
                    if (!string.IsNullOrWhiteSpace(cmdLineSetting?.Value))
                    {
                        foreach (var arg in cmdLineSetting.Value.Split(';'))
                        {
                            chromeOptions.AddArgument(arg);
                        }
                    }

                    // Activate chrome headless via a command line
                    if (browserType == BrowserType.ChromeHeadless)
                    {
                        chromeOptions.AddArgument("--headless");
                    }

                    var chromeDriverService = ChromeDriverService.CreateDefaultService();
                    chromeDriverService.HideCommandPromptWindow = true;

                    driver = new ChromeDriver(chromeDriverService, chromeOptions);
                    break;

                case BrowserType.PhantomJS:
                    var phantomJsDriverService = PhantomJSDriverService.CreateDefaultService();
                    phantomJsDriverService.HideCommandPromptWindow = true;
                    driver = new PhantomJSDriver(phantomJsDriverService);
                    break;

                case BrowserType.Safari:
                    driver = new SafariDriver();
                    break;

                case BrowserType.Edge:
                    var edgeOptions = new EdgeOptions {
                        PageLoadStrategy = EdgePageLoadStrategy.Normal
                    };
                    var edgeDriverService = EdgeDriverService.CreateDefaultService();
                    driver = new EdgeDriver(edgeDriverService, edgeOptions);
                    break;

                default:
                    throw new InvalidOperationException(
                              $"Browser type '{browserType}' is not supported in Selenium local mode. Did you mean to configure a remote driver?");
                }
            }

            // Set Driver Settings
            var managementSettings = driver.Manage();

            // Set timeouts

            var applicationConfiguration = SettingHelper.GetConfigurationSection().Application;

            var timeouts = managementSettings.Timeouts();

            timeouts.ImplicitWait = browserFactoryConfiguration.ElementLocateTimeout;
            timeouts.PageLoad     = browserFactoryConfiguration.PageLoadTimeout;

            ActionBase.DefaultTimeout              = browserFactoryConfiguration.ElementLocateTimeout;
            WaitForPageAction.DefaultTimeout       = browserFactoryConfiguration.PageLoadTimeout;
            ActionBase.RetryValidationUntilTimeout = applicationConfiguration.RetryValidationUntilTimeout;

            // Maximize window
            managementSettings.Window.Maximize();

            return(driver);
        }
        public void Add_NullKeyValue_Throws()
        {
            var element = new NameValueConfigurationElement(null, null);

            Assert.Throws <ConfigurationErrorsException>(() => new NameValueConfigurationCollection().Add(element));
        }
        /// <summary>
        /// Gets the setting with the specified name. If the setting is not found, returns null.
        /// </summary>
        /// <param name="name">The name of the setting to lookup.</param>
        /// <returns>The value associated with the setting name. If the name is not found, returns null.</returns>
        public string Setting(string name)
        {
            NameValueConfigurationElement config = Settings[name];

            return(config?.Value);
        }
	public void Remove(NameValueConfigurationElement nameValue) {}
	// Methods
	public void Add(NameValueConfigurationElement nameValue) {}
 public void Remove(NameValueConfigurationElement nameValue)
 {
 }