public DbConnection AdaptConnection(string connectionString) { var connectionData = new EntityConnectionStringBuilder(connectionString); if (!string.IsNullOrEmpty(connectionData.Name)) { connectionData = new EntityConnectionStringBuilder(ConfigurationManager.ConnectionStrings[connectionData.Name].ConnectionString); } IEnumerable <SchemaTranslation> schemaTranslations = null; connectionData.ProviderConnectionString = SchemaTranslationParser.ResolveSchemaTranslations(connectionData.ProviderConnectionString, out schemaTranslations); var connection = DbProviderFactories.GetFactory(connectionData.Provider).CreateConnection(); connection.ConnectionString = connectionData.ProviderConnectionString; EntityConnection resultConn = null; //it happened to throw exceptions when inserting in the cache dictionary; hence the lock here lock (lockObj) { resultConn = new EntityConnection(AdaptWorkspace(connectionData, schemaTranslations), connection); } return(resultConn); }
public void ShouldReturnMultipleSchemaTranslations() { string connectionString = "User Id=IAM_V4_1_ADM;Password=mypass;Server=dev10g;Home=OraClient11gR2;Persist Security Info=True;Schema Translations=IAM_V4_1_ADM->IAM_V4_ADM,IAM_X->IAM_Y"; string cleanConnString = connectionString.Replace(";Schema Translations=IAM_V4_1_ADM->IAM_V4_ADM,IAM_X->IAM_Y", ""); IEnumerable <SchemaTranslation> schemaTranslations = null; string result = SchemaTranslationParser.ResolveSchemaTranslations(connectionString, out schemaTranslations); Assert.AreEqual(2, schemaTranslations.Count(), "There should be 2 schema translation"); }
public void ShouldReturnCleanedConnectionString() { string connectionString = "User Id=IAM_V4_1_ADM;Password=mypass;Server=dev10g;Home=OraClient11gR2;Persist Security Info=True;Schema Translations=IAM_V4_1_ADM->IAM_V4_ADM"; string cleanConnString = connectionString.Replace(";Schema Translations=IAM_V4_1_ADM->IAM_V4_ADM", ""); IEnumerable <SchemaTranslation> schemaTranslations = null; string result = SchemaTranslationParser.ResolveSchemaTranslations(connectionString, out schemaTranslations); Assert.AreEqual(cleanConnString, result); }
public void ShouldReturnPassedConnectionStringWhenNoTranslationSpecified() { string connectionString = "User Id=IAM_V4_1_ADM;Password=mypass;Server=dev10g;Home=OraClient11gR2;Persist Security Info=True"; IEnumerable <SchemaTranslation> schemaTranslations = null; string result = SchemaTranslationParser.ResolveSchemaTranslations(connectionString, out schemaTranslations); Assert.AreEqual(connectionString, result); Assert.IsNull(schemaTranslations); }
public void ShouldReturnOneSchemaTranslation() { string connectionString = "User Id=IAM_V4_1_ADM;Password=mypass;Server=dev10g;Home=OraClient11gR2;Persist Security Info=True;Schema Translations=IAM_V4_1_ADM->IAM_V4_ADM"; string cleanConnString = connectionString.Replace(";Schema Translations=IAM_V4_1_ADM->IAM_V4_ADM", ""); IEnumerable <SchemaTranslation> schemaTranslations = null; string result = SchemaTranslationParser.ResolveSchemaTranslations(connectionString, out schemaTranslations); Assert.AreEqual(1, schemaTranslations.Count(), "There should be 1 schema translation"); Assert.AreEqual("IAM_V4_1_ADM", schemaTranslations.ElementAt(0).OldName, "old name should match"); Assert.AreEqual("IAM_V4_ADM", schemaTranslations.ElementAt(0).NewName, "new name should match"); }