public void GetConfigSettingAsBool(string value, bool expectedValue, bool defaultValue = false)
        {
            var config = new TestConfiguration();
            IConfigurationSection configSection = new TestConfigurationSection();

            configSection.Value = value;
            config.AddSection(TestConfigSetting, configSection);
            bool actualValue = Utils.GetConfigSettingAsBool(TestConfigSetting, config, defaultValue);

            Assert.Equal(expectedValue, actualValue);
        }
            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);
            }
Пример #3
0
    private object GetMergedDataSourcesSection(string configKey, object originalSection)
    {
        var testDataSourcesSection = TestConfig.GetSection(configKey);

        //return original section if test config has no datasources section defined
        if (testDataSourcesSection == null)
        {
            return(originalSection);
        }

        var mergedDataSources = new DataSourceElementCollection();

        //copy test datasources
        foreach (DataSourceElement dataSource in ((TestConfigurationSection)testDataSourcesSection).DataSources)
        {
            mergedDataSources.Add(dataSource);
        }

        //merge datasources from original config
        if (originalSection != null)
        {
            foreach (DataSourceElement item in ((TestConfigurationSection)originalSection).DataSources)
            {
                if (!mergedDataSources.Cast <DataSourceElement>().Any(x => x.Name.Equals(item.Name, StringComparison.CurrentCultureIgnoreCase)))
                {
                    mergedDataSources.Add(item);
                }
            }
        }

        //create merged TestConfigurationSection
        TestConfigurationSection mergedDataSourcesSection = new TestConfigurationSection();

        foreach (DataSourceElement dataSource in mergedDataSources)
        {
            mergedDataSourcesSection.DataSources.Add(dataSource);
        }
        return(mergedDataSourcesSection);
    }
 public void Setup()
 {
     settings = TestConfigurationSection.Settings;
 }
    private object GetMergedDataSourcesSection(string configKey, object originalSection)
    {
        var testDataSourcesSection = TestConfig.GetSection(configKey);

        //return original section if test config has no datasources section defined
        if (testDataSourcesSection == null)
        {
            return originalSection;
        }

        var mergedDataSources = new DataSourceElementCollection();

        //copy test datasources
        foreach (DataSourceElement dataSource in ((TestConfigurationSection)testDataSourcesSection).DataSources)
        {
            mergedDataSources.Add(dataSource);
        }

        //merge datasources from original config
        if (originalSection != null)
        {
            foreach (DataSourceElement item in ((TestConfigurationSection)originalSection).DataSources)
            {
                if (!mergedDataSources.Cast<DataSourceElement>().Any(x => x.Name.Equals(item.Name, StringComparison.CurrentCultureIgnoreCase)))
                {
                    mergedDataSources.Add(item);
                }
            }
        }

        //create merged TestConfigurationSection
        TestConfigurationSection mergedDataSourcesSection = new TestConfigurationSection();
        foreach (DataSourceElement dataSource in mergedDataSources)
        {
            mergedDataSourcesSection.DataSources.Add(dataSource);
        }
        return mergedDataSourcesSection;
    }