public void RequestForNullNameThrows() { DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource(); DatabaseConfigurationView view = new DatabaseConfigurationView(configurationSource); view.GetConnectionStringSettings(null); }
public void FailsGetConnectionStringIfConnectionStringDoesNotExist() { DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource(); DatabaseConfigurationView view = new DatabaseConfigurationView(configurationSource); view.GetConnectionStringSettings(unknownConnectionName); }
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 FailsGetConnectionStringIfConnectionStringDoesNotExist() { DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource(); DatabaseConfigurationView view = new DatabaseConfigurationView(configurationSource); view.GetConnectionStringSettings(unknownConnectionName); }
public void SetUp() { AppDomain.CurrentDomain.SetData("APPBASE", Environment.CurrentDirectory); assembler = new DatabaseCustomFactory().GetAssembler(typeof(OracleDatabase), "", new ConfigurationReflectionCache()); configurationSource = new DictionaryConfigurationSource(); configurationView = new DatabaseConfigurationView(configurationSource); }
public void RequestForEmptyNameThrows() { DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource(); DatabaseConfigurationView view = new DatabaseConfigurationView(configurationSource); view.GetConnectionStringSettings(""); }
public void CanGetConnectionForStringWithNoCredentials() { DatabaseConfigurationView view = new DatabaseConfigurationView(TestConfigurationSource.CreateConfigurationSource()); ConnectionStringSettings data = view.GetConnectionStringSettings("NewDatabase"); SqlDatabase sqlDatabase = new SqlDatabase(data.ConnectionString); Assert.AreEqual(@"server=(local)\sqlexpress;database=northwind;integrated security=true;", sqlDatabase.ConnectionStringWithoutCredentials); }
public void CanGetConnectionForStringWithNoCredentials() { DatabaseConfigurationView view = new DatabaseConfigurationView(TestConfigurationSource.CreateConfigurationSource()); ConnectionStringSettings data = view.GetConnectionStringSettings("NewDatabase"); SqlDatabase sqlDatabase = new SqlDatabase(data.ConnectionString); Assert.AreEqual(@"server=(local)\sqlexpress;database=northwind;integrated security=true;", sqlDatabase.ConnectionStringWithoutCredentials); }
public void CanGetConnectionWithoutCredentials() { DatabaseConfigurationView view = new DatabaseConfigurationView(TestConfigurationSource.CreateConfigurationSource()); ConnectionStringSettings data = view.GetConnectionStringSettings("DbWithSqlServerAuthn"); SqlDatabase sqlDatabase = new SqlDatabase(data.ConnectionString); Assert.AreEqual(@"server=(local)\sqlexpress;database=northwind;", sqlDatabase.ConnectionStringWithoutCredentials); }
public void CanGetConnectionWithoutCredentials() { DatabaseConfigurationView view = new DatabaseConfigurationView(TestConfigurationSource.CreateConfigurationSource()); ConnectionStringSettings data = view.GetConnectionStringSettings("DbWithSqlServerAuthn"); SqlDatabase sqlDatabase = new SqlDatabase(data.ConnectionString); Assert.AreEqual(@"server=(local)\sqlexpress;database=northwind;", sqlDatabase.ConnectionStringWithoutCredentials); }
public void CanGetConnectionStringsIfConnectionStringExists() { DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource(); DatabaseConfigurationView view = new DatabaseConfigurationView(configurationSource); ConnectionStringSettings data = view.GetConnectionStringSettings(connectionName); Assert.IsNotNull(data); Assert.AreEqual(connectionString, data.ConnectionString); }
/// <summary> /// Returns an new instance of the type the receiver knows how to build. /// </summary> /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param> /// <param name="name">The name of the instance to build, or null.</param> /// <param name="configurationSource">The source for configuration objects.</param> /// <param name="reflectionCache">The cache to use retrieving reflection information.</param> /// <returns>The new instance.</returns> public object CreateObject(IBuilderContext context, string name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) { DatabaseConfigurationView databaseConfigurationView = new DatabaseConfigurationView(configurationSource); ConnectionStringSettings connectionStringSettings = databaseConfigurationView.GetConnectionStringSettings(name); DbSchemaProviderConfigurationView dbSchemaProviderConfigurationView = new DbSchemaProviderConfigurationView(configurationSource); DbSchemaProviderMapping mapping = dbSchemaProviderConfigurationView.GetProviderMapping(connectionStringSettings.ProviderName); return(Activator.CreateInstance(mapping.DbSchemaProviderType)); }
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 CanGetConnectionStringsIfConnectionStringExists() { DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource(); DatabaseConfigurationView view = new DatabaseConfigurationView(configurationSource); ConnectionStringSettings data = view.GetConnectionStringSettings(connectionName); Assert.IsNotNull(data); Assert.AreEqual(connectionString, data.ConnectionString); }
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 WillGetDefaultMappingIfProviderTypeIsNotMappedAndDefaultExistsForSql() { DatabaseSettings databaseSettings = new DatabaseSettings(); 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(SqlDatabase), mapping.DatabaseType); }
public void ConnectionTest() { DatabaseConfigurationView view = new DatabaseConfigurationView(TestConfigurationSource.CreateConfigurationSource()); ConnectionStringSettings data = view.GetConnectionStringSettings("NewDatabase"); SqlDatabase sqlDatabase = new SqlDatabase(data.ConnectionString); DbConnection connection = sqlDatabase.CreateConnection(); Assert.IsNotNull(connection); Assert.IsTrue(connection is SqlConnection); connection.Open(); DbCommand cmd = sqlDatabase.GetSqlStringCommand("Select * from Region"); cmd.CommandTimeout = 60; Assert.AreEqual(cmd.CommandTimeout, 60); }
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 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 ConnectionTest() { DatabaseConfigurationView view = new DatabaseConfigurationView(TestConfigurationSource.CreateConfigurationSource()); ConnectionStringSettings data = view.GetConnectionStringSettings("NewDatabase"); SqlDatabase sqlDatabase = new SqlDatabase(data.ConnectionString); DbConnection connection = sqlDatabase.CreateConnection(); Assert.IsNotNull(connection); Assert.IsTrue(connection is SqlConnection); connection.Open(); DbCommand cmd = sqlDatabase.GetSqlStringCommand("Select * from Region"); cmd.CommandTimeout = 60; Assert.AreEqual(cmd.CommandTimeout, 60); }
public void CheckNoPasswordInConnectionStringWithPersistInfoEqualsFalse() { try { CreateUser(); DatabaseConfigurationView view = new DatabaseConfigurationView(TestConfigurationSource.CreateConfigurationSource()); ConnectionStringSettings data = view.GetConnectionStringSettings("NorthwindPersistFalse"); SqlDatabase sqlDatabase = new SqlDatabase(data.ConnectionString); DbConnection dbConnection = sqlDatabase.CreateConnection(); dbConnection.Open(); dbConnection.Close(); string connectionString = dbConnection.ConnectionString; if (connectionString.ToLower().Contains("pwd") || connectionString.ToLower().Contains("password")) { Assert.Fail(); } } finally { DeleteUser(); } }
public void CheckNoPasswordInConnectionStringWithPersistInfoEqualsFalse() { try { CreateUser(); DatabaseConfigurationView view = new DatabaseConfigurationView(TestConfigurationSource.CreateConfigurationSource()); ConnectionStringSettings data = view.GetConnectionStringSettings("NorthwindPersistFalse"); SqlDatabase sqlDatabase = new SqlDatabase(data.ConnectionString); DbConnection dbConnection = sqlDatabase.CreateConnection(); dbConnection.Open(); dbConnection.Close(); string connectionString = dbConnection.ConnectionString; if (connectionString.ToLower().Contains("pwd") || connectionString.ToLower().Contains("password")) { Assert.Fail(); } } finally { DeleteUser(); } }
public void SetUp() { assembler = new DatabaseCustomFactory().GetAssembler(typeof(OracleDatabase), "", new ConfigurationReflectionCache()); configurationSource = new DictionaryConfigurationSource(); configurationView = new DatabaseConfigurationView(configurationSource); }
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 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 SetUp() { configurationSource = new SystemConfigurationSource(); view = new DatabaseConfigurationView(configurationSource); assembler = new DatabaseCustomFactory().GetAssembler(typeof(OracleDatabase), "", new ConfigurationReflectionCache()); }
internal static void ShowDatabaseConfigurationWindow() { var databaseConfiguration = new DatabaseConfigurationView(); databaseConfiguration.ShowDialog(); }