Beispiel #1
0
 /// <summary>
 /// Removes a System.Configuration.ConfigurationElement from the collection.
 /// </summary>
 /// <param name="element">The <see cref="DataSourceElement"/> .</param>
 public void Remove(DataSourceElement element)
 {
     if (this.BaseIndexOf(element) >= 0)
     {
         this.BaseRemove(element.Key);
     }
 }
            public Microsoft.VisualStudio.TestTools.UnitTesting.DataSourceAttribute GetTestDataSource(string dataSourceSettingName)
            {
                Microsoft.VisualStudio.TestTools.UnitTesting.DataSourceElement element = null;
                DataSourceAttribute dataSourceAttribute = null;

                TestConfigurationSection configurationSection = GetTestConfigurationSection();

                element = configurationSection.DataSources[dataSourceSettingName];

                if (element != null)
                {
                    System.Configuration.ConnectionStringSettings connectionString = GetConnectionString(element.ConnectionString);
                    dataSourceAttribute = new DataSourceAttribute(connectionString.ProviderName, connectionString.ConnectionString, element.DataTableName, (DataAccessMethod)Enum.Parse(typeof(DataAccessMethod), element.DataAccessMethod));
                }

                return(dataSourceAttribute);
            }
Beispiel #3
0
        /// <summary>
        /// Get connection property based on DataSourceAttribute. If its in config file then read it from config.
        /// </summary>
        /// <param name="dataSourceAttribute">The dataSourceAttribute.</param>
        /// <param name="providerNameInvariant">The provider name.</param>
        /// <param name="connectionString">The connection string.</param>
        /// <param name="tableName">The table name.</param>
        /// <param name="dataAccessMethod">The data access method.</param>
        private void GetConnectionProperties(UTF.DataSourceAttribute dataSourceAttribute, out string providerNameInvariant, out string connectionString, out string tableName, out UTF.DataAccessMethod dataAccessMethod)
        {
            if (string.IsNullOrEmpty(dataSourceAttribute.DataSourceSettingName) == false)
            {
                UTF.DataSourceElement elem = UTF.TestConfiguration.ConfigurationSection.DataSources[dataSourceAttribute.DataSourceSettingName];
                if (elem == null)
                {
                    throw new Exception(string.Format(CultureInfo.CurrentCulture, Resource.UTA_DataSourceConfigurationSectionMissing, dataSourceAttribute.DataSourceSettingName));
                }

                providerNameInvariant = ConfigurationManager.ConnectionStrings[elem.ConnectionString].ProviderName;
                connectionString      = ConfigurationManager.ConnectionStrings[elem.ConnectionString].ConnectionString;
                tableName             = elem.DataTableName;
                dataAccessMethod      = (UTF.DataAccessMethod)Enum.Parse(typeof(UTF.DataAccessMethod), elem.DataAccessMethod);
            }
            else
            {
                providerNameInvariant = dataSourceAttribute.ProviderInvariantName;
                connectionString      = dataSourceAttribute.ConnectionString;
                tableName             = dataSourceAttribute.TableName;
                dataAccessMethod      = dataSourceAttribute.DataAccessMethod;
            }
        }
Beispiel #4
0
 /// <summary>
 /// Adds a configuration element to the configuration element collection.
 /// </summary>
 /// <param name="element">The System.Configuration.ConfigurationElement to add.</param>
 public void Add(DataSourceElement element)
 {
     this.BaseAdd(element, false);
 }
Beispiel #5
0
        /// <summary>
        /// Gets the element key for a specified configuration element.
        /// </summary>
        /// <param name="element">The System.Configuration.ConfigurationElement to return the key for.</param>
        /// <returns>An System.Object that acts as the key for the specified System.Configuration.ConfigurationElement.</returns>
        protected override object GetElementKey(ConfigurationElement element)
        {
            DataSourceElement dataSource = (DataSourceElement)element;

            return(dataSource.Key);
        }