Stores database configuration settings and creates connections using these settings
Inheritance: IDatabaseConfig, ISupportsRSADecryption
		private static void SetupSQLServerCeConnection()
		{
			var uri = new Uri(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) ?? "");
			var databaseFile = Path.Combine(uri.LocalPath, "sqlserverce-testdb.sdf");
			var databaseConfig = new DatabaseConfig(DatabaseConfig.SqlServerCe, "", databaseFile, "", "", null);
			DatabaseConnection.CurrentConnection = databaseConfig.GetDatabaseConnection();
		}
 public void SetupFixture()
 {
     DatabaseConfig databaseConfig = new DatabaseConfig("Mysql", "localhost", "habanero_temp", "root", "root",
                                                        "3306");
     IDatabaseConnection databaseConnection = databaseConfig.GetDatabaseConnection();
     _setupDatabase = new SetupDatabase(databaseConnection);
     _setupDatabase.ClearDatabase();
 }
Beispiel #3
0
 public Migrator(DatabaseConfig databaseConfig)
 {
     _databaseConfig = databaseConfig;
     NamespaceContainingMigrations = "Habanero.Test.Migrations";
     AssemblyContainingMigrations = Assembly.GetExecutingAssembly();
     MigrationProcessorFactory = GetMigrationProcessorFactory(databaseConfig);
     Announcer = new TextWriterAnnouncer(s => System.Diagnostics.Debug.WriteLine(s));
     _databaseInitialiser = new DatabaseInitialiser(databaseConfig);
 }
 public void TestDatabaseConfigAlternateConstructor()
 {
     DatabaseConfig d = new DatabaseConfig(DatabaseConfig.MySql, "a", "b", "c", "d", "e");
     Assert.AreEqual(DatabaseConfig.MySql, d.Vendor);
     Assert.AreEqual("a", d.Server);
     Assert.AreEqual("b", d.Database);
     Assert.AreEqual("c", d.UserName);
     Assert.AreEqual("d", d.Password);
     Assert.AreEqual("e", d.Port);
 }
 public void TestDatabaseConfigSettings()
 {
     DatabaseConfig d = new DatabaseConfig(settingsMySql);
     Assert.AreEqual(DatabaseConfig.MySql, d.Vendor);
     Assert.AreEqual("b", d.Server);
     Assert.AreEqual("c", d.Database);
     Assert.AreEqual("d", d.UserName);
     Assert.AreEqual("e", d.Password);
     Assert.AreEqual("f", d.Port);
 }
        public void TestCreateConnectionFireBird()
        {
            //---------------Set up test pack-------------------
            DatabaseConfig config = new DatabaseConfig(DatabaseConfig.Firebird, "test", "test", "test", "test", "1000");

            //---------------Execute Test ----------------------
            IDatabaseConnection connection = new DatabaseConnectionFactory().CreateConnection(config);
            IDbConnection dbConnection = connection.GetConnection();

            //---------------Test Result -----------------------
            Assert.AreEqual("FirebirdSql.Data.FirebirdClient", dbConnection.GetType().Namespace);
        }
        public void TestCreateConnectionSqlServer()
        {
            //---------------Set up test pack-------------------
            DatabaseConfig config = new DatabaseConfig(DatabaseConfig.SqlServer, "test", "test", "test", "test", "1000");

            //---------------Execute Test ----------------------
            IDatabaseConnection connection = new DatabaseConnectionFactory().CreateConnection(config);
            IDbConnection dbConnection = connection.GetConnection();

            //---------------Test Result -----------------------
            Assert.AreEqual("System.Data.SqlClient", dbConnection.GetType().Namespace);
        }
 public void SetupTestFixture()
 {
     var config = new DatabaseConfig(DatabaseConfig.SqlServer, "test", "test", "test", "test", "1000");
     _connection = new DatabaseConnectionFactory().CreateConnection(config);
     _testStatement = new SqlStatement(_connection);
     _rawStatement = "insert into tb1 (field1, field2, field3) values (@Param1, @Param2, @Param3)";
     _testStatement.Statement.Append(_rawStatement);
     _addedParameter = _testStatement.AddParameter("Param1", "12345");
     _testStatement.AddParameter("Param2", "67890");
     _testStatement.AddParameter("Param3", "13579");
     _command = _connection.GetConnection().CreateCommand();
     _testStatement.SetupCommand(_command);
 }
Beispiel #9
0
        public static DatabaseConfig GetDatabaseConfig()
        {
            IDictionary settings = new Hashtable();

            settings.Add("vendor", DatabaseConfig.MySql);
            settings.Add("server", "localhost");
            settings.Add("database", "habanero_test_trunk");
            settings.Add("username", "root");
            settings.Add("password", "root");
            settings.Add("port", "3306");

            DatabaseConfig config = new DatabaseConfig(settings);
            return config;
        }
 public void Setup()
 {
     encryptedConfig = new DatabaseConfig(DatabaseConfig.MySql, "a", "b", "c", encryptedPassword, "e");
 }
 public void TestToStringEncryptedPassword()
 {
     encryptedConfig.SetPrivateKey(rsa.ToXmlString(true));
     DatabaseConfig d2 = new DatabaseConfig(DatabaseConfig.MySql, "a", "b", "c", encryptedPassword, "e");
     Assert.AreEqual(d2.ToString(), encryptedConfig.ToString());
 }
 public void TestUsingDatabaseConfigMySql()
 {
     DatabaseConfig config = new DatabaseConfig(settingsMySql);
     String connectString =
         new ConnectionStringMySqlFactory().GetConnectionString("b", "c", "d", "e", "f");
     Assert.AreEqual(connectString, config.GetConnectionString(),
                     "ConnectionStringFactory not working for MySql using ConfigData");
 }
		private static void SetupSQLServerConnection()
		{
			var databaseConfig = new DatabaseConfig("SqlServer", "localhost", "habanero_test_trunk", "sa", "sa", null);
			//var databaseConfig = new DatabaseConfig("SqlServer", @"localhost\sqlexpress", "habanero_test_branch_2_6", "sa", "sa", null);
			DatabaseConnection.CurrentConnection = databaseConfig.GetDatabaseConnection();
		}
 private static void EnsureDatabaseMigrated(DatabaseConfig databaseConfig)
 {
     var migrator = new Migrator(databaseConfig);
     migrator.EnsureDatabseExists();    
     migrator.MigrateToLatest();
 }
        public void TestUsingCustomAssembly()
        {
            //---------------Set up test pack-------------------
            DatabaseConfig config = new DatabaseConfig(DatabaseConfig.Oracle, "test", "test", "test", "test", "1000");
            config.AssemblyName = "System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
            config.FullClassName = "System.Data.SqlClient.SqlConnection";

            //---------------Execute Test ----------------------
            IDatabaseConnection connection = new DatabaseConnectionFactory().CreateConnection(config);
            IDbConnection dbConnection = connection.GetConnection();

            //---------------Test Result -----------------------
            Assert.AreEqual("System.Data.SqlClient", dbConnection.GetType().Namespace);
            StringAssert.Contains("System.Data, ", dbConnection.GetType().Assembly.FullName);
            StringAssert.Contains(", Culture=neutral, PublicKeyToken=b77a5c561934e089", dbConnection.GetType().Assembly.FullName);
            //---------------Tear Down -------------------------          
        }
        public void TestCreateConnectionPostgreSql()
        {
            //---------------Set up test pack-------------------
            DatabaseConfig config = new DatabaseConfig(DatabaseConfig.PostgreSql, "test", "test", "test", "test", "1000");

            //---------------Execute Test ----------------------
            IDatabaseConnection connection = new DatabaseConnectionFactory().CreateConnection(config);
            IDbConnection dbConnection = connection.GetConnection();

            //---------------Test Result -----------------------
            Assert.AreEqual("Npgsql", dbConnection.GetType().Namespace);
        }
 public void SetupTestFixture()
 {
     var config = new DatabaseConfig(DatabaseConfig.SqlServer, "test", "test", "test", "test", "1000");
     _connection = new DatabaseConnectionFactory().CreateConnection(config);
 }
 /// <summary>
 /// Sets up the database connection.  If not provided, then
 /// reads the connection from the config file.
 /// </summary>
 protected override void SetupDatabaseConnection()
 {
     if (DatabaseConnection.CurrentConnection != null) return;
     if (_databaseConfig == null) _databaseConfig = DatabaseConfig.ReadFromConfigFile();
     string vendor = _databaseConfig.Vendor;
     if (string.IsNullOrEmpty(vendor) || vendor.ToLower().Contains("memory"))
     {
         BORegistry.DataAccessor = new DataAccessorInMemory();
     }
     else
     {
         if (_privateKey != null) _databaseConfig.SetPrivateKey(_privateKey);
         DatabaseConnection.CurrentConnection = _databaseConfig.GetDatabaseConnection();
         BORegistry.DataAccessor = new DataAccessorDB();
     }
 }
Beispiel #19
0
 protected internal DatabaseConfig Clone()
 {
     var databaseConfig = new DatabaseConfig(Vendor, Server, Database, UserName, Password, Port);
     databaseConfig._passwordCrypter = _passwordCrypter;
     databaseConfig.AssemblyName = AssemblyName;
     databaseConfig.FullClassName = FullClassName;
     databaseConfig.ConnectionStringFactoryAssemblyName = ConnectionStringFactoryAssemblyName;
     databaseConfig.ConnectionStringFactoryClassName = ConnectionStringFactoryClassName;
     return databaseConfig;
 }
 public void Test_CreateSqlFormatter_AlternateConstructor_SQLite()
 {
     //---------------Set up test pack-------------------
     string connectionString =
         new DatabaseConfig(DatabaseConfig.SqlServer, "test", "test", "test", "test", "1000").GetConnectionString
             ();
     IDatabaseConnection dbConn = new DatabaseConnectionSQLite
         ("System.Data", "System.Data.SqlClient.SqlConnection", connectionString);
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     ISqlFormatter defaultSqlFormatter = dbConn.SqlFormatter;
     //---------------Test Result -----------------------
     Assert.IsInstanceOf(typeof(SqlFormatter), defaultSqlFormatter);
     SqlFormatter sqlFormatter = (SqlFormatter)defaultSqlFormatter;
     Assert.IsNotNull(sqlFormatter);
     Assert.AreEqual("\"", sqlFormatter.LeftFieldDelimiter);
     Assert.AreEqual("\"", sqlFormatter.RightFieldDelimiter);
     Assert.AreEqual("", sqlFormatter.LimitClauseAtBeginning);
     Assert.AreEqual("limit", sqlFormatter.LimitClauseAtEnd);
     Assert.AreEqual(sqlFormatter.LeftFieldDelimiter, dbConn.LeftFieldDelimiter);
     Assert.AreEqual(sqlFormatter.RightFieldDelimiter, dbConn.RightFieldDelimiter);
     //            StringAssert.Contains(sqlFormatter.LimitClauseAtBeginning, dbConn.GetLimitClauseForBeginning(1));
     //            StringAssert.Contains(sqlFormatter.LimitClauseAtEnd, dbConn.GetLimitClauseForEnd(1));
 }
 public DatabaseInitialiser(DatabaseConfig databaseConfig)
 {
     _databaseConfig = databaseConfig;
 }