public IDbConnection CreateDbConnection(DbConnectionName connectionName) { if (_connectionDictionary.TryGetValue(connectionName, out string connectionString)) { return(new NpgsqlConnection(connectionString)); } throw new ArgumentNullException(); }
public void Call_Unavailable_Db_Connection_Factory() { var dbConnectionName = new DbConnectionName("name"); var callDbConnName = new DbConnectionName("SomeName"); var provider = new DbConnectionFactoryProvider(); var mockFactory = new Mock <IDbConnectionFactory>(); provider.Add(dbConnectionName, mockFactory.Object); Should.Throw <DbConnectionFactoryProviderException>(() => provider.Create(callDbConnName)); }
//Inject SqlConnection with different Connection Str public IDbConnection CreateDbConnection(DbConnectionName connectionName) { string st_ConnectionString = null; if (_connectionDict.TryGetValue(connectionName, out st_ConnectionString)) { return(new SqlConnection(st_ConnectionString)); } throw new ArgumentNullException(); }
public void Register_Db_Connection_Factory_And_Find() { var dbConnectionName = new DbConnectionName("name"); var provider = new DbConnectionFactoryProvider(); var mockFactory = new Mock <IDbConnectionFactory>(); mockFactory.Verify(tt => tt.Create(null), Times.AtMost(1)); provider.Add(dbConnectionName, mockFactory.Object); provider.Create(dbConnectionName).Create(null); mockFactory.VerifyAll(); }