public override DataTable GetSchema(string collectionName) { return(WrappedConnection.GetSchema(collectionName)); }
public override void ChangeDatabase(string databaseName) { _catalogHelpers = null; WrappedConnection.ChangeDatabase(databaseName); }
public override void EnlistTransaction(System.Transactions.Transaction transaction) { WrappedConnection.EnlistTransaction(transaction); }
public static string GetFirstAvailableKeyspace(WrappedConnection wrappedConnection) => wrappedConnection.QueryForString("select keyspace_name from system_schema.keyspaces limit 1");
protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel) { return(WrappedConnection.BeginTransaction(isolationLevel)); }
public void Run_all_PostgreSQL_integration_tests_work() { // Open a connection to the PostgreSQL database var cnn = new NpgsqlConnection($"Server=127.0.0.1;Port={_pgFixture.HostPort};Database={_pgFixture.DbName};User Id={_pgFixture.DbUser};Password={_pgFixture.DbPwd};"); cnn.Open(); Assert.True(cnn.State == ConnectionState.Open, "Cannot open a connection to the database."); // Initiate a connection to the database var wcnn = new WrappedConnection(cnn); // Validate DBMS.PostgreSQL Assert.Equal(DBMS.PostgreSQL, wcnn.GetDatabaseServerType()); // Init the DatabaseHelper DatabaseHelper db = DatabaseHelperFactory.GetDatabaseHelper(DBMS.PostgreSQL, wcnn); // Test default schema name Assert.True(db.GetCurrentSchemaName() == "public", "The default PostgreSQL schema should be 'public'."); // Create schema string metadataSchemaName = "My metadata schema"; Schema metadataSchema = new PostgreSQLSchema(metadataSchemaName, wcnn); Assert.False(metadataSchema.IsExists(), $"The schema [{metadataSchemaName}] should not already exist."); Assert.True(metadataSchema.Create(), $"Creation of the schema [{metadataSchemaName}] failed."); Assert.True(metadataSchema.IsExists(), $"The schema [{metadataSchemaName}] should be created."); Assert.True(metadataSchema.IsEmpty(), $"The schema [{metadataSchemaName}] should be empty."); // Get MetadataTable string metadataTableName = "changelog"; var metadata = db.GetMetadataTable(metadataSchemaName, metadataTableName); // Create MetadataTable Assert.False(metadata.IsExists(), "MetadataTable sould not already exist."); Assert.True(metadata.CreateIfNotExists(), "MetadataTable creation failed."); Assert.True(metadata.IsExists(), "MetadataTable sould exist."); Assert.False(metadata.CreateIfNotExists(), "MetadataTable already exists. Creation should return false."); Assert.True(metadata.GetAllMigrationMetadata().Count() == 0, "No migration metadata should be found."); // Lock MetadataTable metadata.Lock(); // Save NewSchema metadata metadata.Save(MetadataType.NewSchema, "0", "New schema created.", metadataSchemaName); Assert.True(metadata.CanDropSchema(metadataSchemaName), $"[{metadataSchemaName}] should be droppable."); Assert.False(metadata.CanEraseSchema(metadataSchemaName), $"[{metadataSchemaName}] should not be erasable."); // Add metadata migration var migrationScript = new FileMigrationScript(TestContext.EmptyMigrationScriptPath, "1_3_2", "Migration_description"); metadata.SaveMigration(migrationScript, true); var migrationMetadata = metadata.GetAllMigrationMetadata().FirstOrDefault(); Assert.True(migrationMetadata != null, "One migration metadata should be found."); Assert.True(migrationMetadata.Version == migrationScript.Version, "Metadata version is not the same."); Assert.True(migrationMetadata.Checksum == migrationScript.CalculateChecksum(), "Metadata checksum is not the same."); Assert.True(migrationMetadata.Description == migrationScript.Description, "Metadata descritpion is not the same."); Assert.True(migrationMetadata.Name == migrationScript.Name, "Metadata name is not the same."); Assert.True(migrationMetadata.Success == true, "Metadata success is not true."); Assert.True(migrationMetadata.Id > 0, "Metadata id is not set."); Assert.True(migrationMetadata.InstalledOn.Date == DateTime.UtcNow.Date, "Installed date is not set."); // Update checksum metadata.UpdateChecksum(migrationMetadata.Id, "Hi !"); Assert.Equal("Hi !", metadata.GetAllMigrationMetadata().First().Checksum); // Assert metadata schema is not empty Assert.False(metadataSchema.IsEmpty(), $"[{metadataSchemaName}] should not be empty."); // Erase schema metadataSchema.Erase(); Assert.True(metadataSchema.IsEmpty(), $"The schema [{metadataSchemaName}] should be empty."); Assert.True(metadataSchema.IsExists(), $"The schema [{metadataSchemaName}] should exist."); // Drop schema metadataSchema.Drop(); Assert.False(metadataSchema.IsExists(), $"The schema [{metadataSchemaName}] should not exist."); // Acquisition du lock applicatif while (true) { if (db.TryAcquireApplicationLock()) { break; } Thread.Sleep(TimeSpan.FromSeconds(1)); } Assert.True(db.TryAcquireApplicationLock(), "Cannot acquire application lock."); // Can not acquire lock while it is taken by another connection var cnn2 = new NpgsqlConnection($"Server=127.0.0.1;Port={_pgFixture.HostPort};Database={_pgFixture.DbName};User Id={_pgFixture.DbUser};Password={_pgFixture.DbPwd};"); var wcnn2 = new WrappedConnection(cnn2); var db2 = DatabaseHelperFactory.GetDatabaseHelper(DBMS.PostgreSQL, wcnn2); Assert.False(db2.TryAcquireApplicationLock(), "Application lock could not have been acquired."); // Release the lock db.ReleaseApplicationLock(); db.CloseConnection(); Assert.True(db.WrappedConnection.DbConnection.State == ConnectionState.Closed, "SQL connection should be closed."); }
public PostgreSQLSchema(string schemaName, WrappedConnection wrappedConnection) : base(schemaName, wrappedConnection) { Version = _wrappedConnection.QueryForLong("SHOW server_version_num;"); }
/// <inheritdoc cref="DbConnection.CreateDbCommand()" /> protected override DbCommand CreateDbCommand() { return(new AdoNetProfilerDbCommand(WrappedConnection.CreateCommand(), this, Profiler)); }
/// <inheritdoc cref="DbConnection.ChangeDatabase(string)" /> public override void ChangeDatabase(string databaseName) { WrappedConnection.ChangeDatabase(databaseName); }
public CassandraKeyspace(string keyspaceName, ReplicationStrategy replicationStrategy, WrappedConnection wrappedConnection) : base(keyspaceName, wrappedConnection) { _replicationStrategy = replicationStrategy ?? throw new ArgumentNullException(nameof(replicationStrategy)); }
public void Run_all_MySQL_integration_tests_work() { // Open a connection to the PostgreSQL database var cnn = new MySqlConnection($"Server=127.0.0.1;Port={_fixture.MySql.HostPort};Database={_fixture.MySql.DbName};Uid={_fixture.MySql.DbUser};Pwd={_fixture.MySql.DbPwd};"); cnn.Open(); Assert.True(cnn.State == ConnectionState.Open, "Cannot open a connection to the database."); // Initiate a connection to the database var wcnn = new WrappedConnection(cnn); // Validate DBMS.MySQL_MariaDB Assert.Equal(DBMS.MySQL_MariaDB, wcnn.GetDatabaseServerType()); // Init the DatabaseHelper DatabaseHelper db = DatabaseHelperFactory.GetDatabaseHelper(DBMS.MySQL_MariaDB, wcnn); // Get default schema name Assert.True(db.GetCurrentSchemaName() == _fixture.MySql.DbName, $"The default MySQL schema should be '{_fixture.MySql.DbName}'."); // Create schema string metadataSchemaName = "My metadata schema"; Schema metadataSchema = new MySQLSchema(metadataSchemaName, wcnn); Assert.False(metadataSchema.IsExists(), $"The schema [{metadataSchemaName}] should not already exist."); Assert.True(metadataSchema.Create(), $"Creation of the schema [{metadataSchemaName}] failed."); Assert.True(metadataSchema.IsExists(), $"The schema [{metadataSchemaName}] should be created."); Assert.True(metadataSchema.IsEmpty(), $"The schema [{metadataSchemaName}] should be empty."); // Get MetadataTable string metadataTableName = "change log"; var metadata = db.GetMetadataTable(metadataSchemaName, metadataTableName); // Create MetadataTable Assert.False(metadata.IsExists(), "MetadataTable sould not already exist."); Assert.True(metadata.CreateIfNotExists(), "MetadataTable creation failed."); Assert.True(metadata.IsExists(), "MetadataTable sould exist."); Assert.False(metadata.CreateIfNotExists(), "MetadataTable already exists. Creation should return false."); Assert.True(metadata.GetAllMigrationMetadata().Count() == 0, "No migration metadata should be found."); // Lock MetadataTable metadata.Lock(); // Save NewSchema metadata metadata.Save(MetadataType.NewSchema, "0", "New schema created.", metadataSchemaName); Assert.True(metadata.CanDropSchema(metadataSchemaName), $"[{metadataSchemaName}] should be droppable."); Assert.False(metadata.CanEraseSchema(metadataSchemaName), $"[{metadataSchemaName}] should not be erasable."); // Add metadata migration var migrationScript = new MigrationScript(TestContext.EmptyMigrationScriptPath, "1_3_2", "Migration_description"); metadata.SaveMigration(migrationScript, true); var migrationMetadata = metadata.GetAllMigrationMetadata().FirstOrDefault(); Assert.True(migrationMetadata != null, "One migration metadata should be found."); Assert.True(migrationMetadata.Version == migrationScript.Version, "Metadata version is not the same."); Assert.True(migrationMetadata.Checksum == migrationScript.CalculateChecksum(), "Metadata checksum is not the same."); Assert.True(migrationMetadata.Description == migrationScript.Description, "Metadata descritpion is not the same."); Assert.True(migrationMetadata.Name == migrationScript.Name, "Metadata name is not the same."); Assert.True(migrationMetadata.Success == true, "Metadata success is not true."); Assert.True(migrationMetadata.Id > 0, "Metadata id is not set."); Assert.True(migrationMetadata.InstalledOn.Date == DateTime.Now.Date, "Installed date is not set."); // Update checksum metadata.UpdateChecksum(migrationMetadata.Id, "Hi !"); Assert.Equal("Hi !", metadata.GetAllMigrationMetadata().First().Checksum); // Assert metadata schema is not empty Assert.False(metadataSchema.IsEmpty(), $"[{metadataSchemaName}] should not be empty."); // Erase schema metadataSchema.Erase(); Assert.True(metadataSchema.IsEmpty(), $"The schema [{metadataSchemaName}] should be empty."); Assert.True(metadataSchema.IsExists(), $"The schema [{metadataSchemaName}] should exist."); // Drop schema metadataSchema.Drop(); Assert.False(metadataSchema.IsExists(), $"The schema [{metadataSchemaName}] should not exist."); }
public DatabaseHelper(WrappedConnection wrappedConnection) { WrappedConnection = Check.NotNull(wrappedConnection, nameof(wrappedConnection)); _originalSchemaName = GetCurrentSchemaName(); }
protected DatabaseHelper(WrappedConnection wrappedConnection) { WrappedConnection = Check.NotNull(wrappedConnection, nameof(wrappedConnection)); }
protected override void InternalChangeSchema(string toSchemaName) { WrappedConnection.ExecuteNonQuery($"Use {toSchemaName}"); _currentKeyspaceName = toSchemaName; }
public override DataTable GetSchema() { return(WrappedConnection.GetSchema()); }
public static WrappedConnection AssertDatabaseServerType(this WrappedConnection wcnn, DBMS expectedDBMS) { Assert.Equal(expectedDBMS, wcnn.GetDatabaseServerType()); return(wcnn); }
public override DataTable GetSchema(string collectionName, string[] restrictionValues) { return(WrappedConnection.GetSchema(collectionName, restrictionValues)); }
public SQLServerDatabase(WrappedConnection wrappedConnection) : base(wrappedConnection) { }
public SQLiteDatabase(WrappedConnection wrappedConnection) : base(wrappedConnection) { }
public CockroachDBCluster(WrappedConnection wrappedConnection) : base(wrappedConnection) { }
public override string GetCurrentSchemaName() => WrappedConnection.QueryForString("SHOW database");
public CassandraCluster(WrappedConnection wrappedConnection) : base(wrappedConnection) { _currentKeyspaceName = _currentKeyspaceName ?? GetFirstAvailableKeyspace(wrappedConnection); }