protected override void Initialize() { DatabaseConfigurationView configurationView = new DatabaseConfigurationView(ConfigurationSource); string defaultDatabaseName = configurationView.DefaultName; foreach (ConnectionStringSettings connectionStringSettings in configurationView.GetConnectionStringSettingsCollection()) { if (IsValidProviderName(connectionStringSettings.ProviderName)) { DbProviderMapping mapping = configurationView.GetProviderMapping( connectionStringSettings.Name, connectionStringSettings.ProviderName); Type databaseType = mapping.DatabaseType; this.Context.Policies.Set <IBuildKeyMappingPolicy>( new BuildKeyMappingPolicy(new NamedTypeBuildKey(databaseType, connectionStringSettings.Name)), NamedTypeBuildKey.Make <Database>(connectionStringSettings.Name)); if (connectionStringSettings.Name == defaultDatabaseName) { this.Context.Policies.Set <IBuildKeyMappingPolicy>( new BuildKeyMappingPolicy(new NamedTypeBuildKey(databaseType, connectionStringSettings.Name)), NamedTypeBuildKey.Make <Database>()); } IContainerPolicyCreator policyCreator = GetContainerPolicyCreator(databaseType, null); policyCreator.CreatePolicies( this.Context.Policies, connectionStringSettings.Name, connectionStringSettings, this.ConfigurationSource); } } }
public void WillGetGenericMappingIfDatabaseSettingsSectionDoesNotExist() { DictionaryConfigurationSource source = new DictionaryConfigurationSource(); DatabaseConfigurationView view = new DatabaseConfigurationView(source); DbProviderMapping mapping = view.GetProviderMapping("ignore", OdbcProviderName); Assert.IsNotNull(mapping); Assert.AreEqual(typeof(GenericDatabase), mapping.DatabaseType); }
public void WillGetDefaultMappingIfDatabaseSettingsSectionDoesNotExistForSql() { DictionaryConfigurationSource source = new DictionaryConfigurationSource(); DatabaseConfigurationView view = new DatabaseConfigurationView(source); DbProviderMapping mapping = view.GetProviderMapping("ignore", DbProviderMapping.DefaultSqlProviderName); Assert.IsNotNull(mapping); Assert.AreEqual(DbProviderMapping.DefaultSqlProviderName, mapping.DbProviderName); Assert.AreEqual(typeof(SqlDatabase), mapping.DatabaseType); }
public void WillGetGenericMappingIfProviderTypeIsNotMappedAndDefaultDoesNotExist() { DatabaseSettings databaseSettings = new DatabaseSettings(); DictionaryConfigurationSource source = new DictionaryConfigurationSource(); source.Add(DatabaseSettings.SectionName, databaseSettings); DatabaseConfigurationView view = new DatabaseConfigurationView(source); DbProviderMapping mapping = view.GetProviderMapping("ignore", OdbcProviderName); Assert.IsNotNull(mapping); Assert.AreEqual(typeof(GenericDatabase), mapping.DatabaseType); }
public void WillGetMappedProviderTypeEvenIfDefaultExists() { DatabaseSettings databaseSettings = new DatabaseSettings(); databaseSettings.ProviderMappings.Add(new DbProviderMapping(DbProviderMapping.DefaultSqlProviderName, typeof(GenericDatabase))); DictionaryConfigurationSource source = new DictionaryConfigurationSource(); source.Add(DatabaseSettings.SectionName, databaseSettings); DatabaseConfigurationView view = new DatabaseConfigurationView(source); DbProviderMapping mapping = view.GetProviderMapping("ignore", DbProviderMapping.DefaultSqlProviderName); Assert.IsNotNull(mapping); Assert.AreEqual(DbProviderMapping.DefaultSqlProviderName, mapping.DbProviderName); Assert.AreEqual(typeof(GenericDatabase), mapping.DatabaseType); }
public void WillGetDefaultMappingIfProviderTypeIsNotMappedAndDefaultExistsForOracle() { DatabaseSettings databaseSettings = new DatabaseSettings(); DictionaryConfigurationSource source = new DictionaryConfigurationSource(); source.Add(DatabaseSettings.SectionName, databaseSettings); DatabaseConfigurationView view = new DatabaseConfigurationView(source); DbProviderMapping mapping = view.GetProviderMapping("ignore", DbProviderMapping.DefaultOracleProviderName); Assert.IsNotNull(mapping); Assert.AreEqual(DbProviderMapping.DefaultOracleProviderName, mapping.DbProviderName); Assert.AreEqual(typeof(OracleDatabase), mapping.DatabaseType); }