Skip to content

Commit

Permalink
Update Respawn.csproj
Browse files Browse the repository at this point in the history
  • Loading branch information
jbogard authored and marco-carvalho committed May 15, 2024
2 parents d07ad07 + 270ba6a commit ee5a0d4
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 89 deletions.
2 changes: 1 addition & 1 deletion Respawn.DatabaseTests/EmptyDbTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task InitializeAsync()
{
var connString = @"Server=(LocalDb)\mssqllocaldb;Database=tempdb;Integrated Security=True";

await using (var connection = new SqlConnection(connString))
using (var connection = new SqlConnection(connString))
{
await connection.OpenAsync();
using (var database = new Database(connection))
Expand Down
28 changes: 14 additions & 14 deletions Respawn.DatabaseTests/InformixTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public async Task InitializeAsync()
{
const string connString = "Server=127.0.0.1:9089;Database=sysadmin;UID=informix;PWD=in4mix;Persist Security Info=True;Authentication=Server;";

await using (var connection = new DB2Connection(connString))
using (var connection = new DB2Connection(connString))
{
await connection.OpenAsync();

using var database = new Database(connection);

_databaseName = $"dummyifx_{Guid.NewGuid():N}";
Expand All @@ -57,7 +57,7 @@ public async Task InitializeAsync()
[SkipOnCI]
public async Task ShouldDeleteData()
{
await using var command = new DB2Command("DROP TABLE IF EXISTS Foo; CREATE TABLE Foo (Value INT);", _connection);
using var command = new DB2Command("DROP TABLE IF EXISTS Foo; CREATE TABLE Foo (Value INT);", _connection);

command.ExecuteNonQuery();
command.CommandText = "INSERT INTO Foo VALUES (?)";
Expand All @@ -84,7 +84,7 @@ public async Task ShouldDeleteData()
[SkipOnCI]
public async Task ShouldIgnoreTables()
{
await using var command = new DB2Command("DROP TABLE IF EXISTS Foo; CREATE TABLE Foo (Value INT);", _connection);
using var command = new DB2Command("DROP TABLE IF EXISTS Foo; CREATE TABLE Foo (Value INT);", _connection);
command.ExecuteNonQuery();
command.CommandText = "DROP TABLE IF EXISTS Bar; CREATE TABLE Bar (Value INT);";
command.ExecuteNonQuery();
Expand Down Expand Up @@ -114,9 +114,9 @@ public async Task ShouldIgnoreTables()
[SkipOnCI]
public async Task ShouldHandleRelationships()
{
await using var command = new DB2Command("DROP TABLE IF EXISTS Foo; CREATE TABLE Foo (Value INT PRIMARY KEY);", _connection);
using var command = new DB2Command("DROP TABLE IF EXISTS Foo; CREATE TABLE Foo (Value INT PRIMARY KEY);", _connection);
command.ExecuteNonQuery();
command.CommandText = @"DROP TABLE IF EXISTS Bar;
command.CommandText = @"DROP TABLE IF EXISTS Bar;
CREATE TABLE Bar (
Value INT,
FooValue INT,
Expand Down Expand Up @@ -162,13 +162,13 @@ FOREIGN KEY (FooValue) REFERENCES Foo(Value)
[SkipOnCI]
public async Task ShouldHandleCircularRelationships()
{
await using var command = new DB2Command(@"DROP TABLE IF EXISTS Parent;
using var command = new DB2Command(@"DROP TABLE IF EXISTS Parent;
CREATE TABLE Parent (
Id INT PRIMARY KEY,
ChildId INT NULL
);", _connection);
command.ExecuteNonQuery();
command.CommandText = @"DROP TABLE IF EXISTS Child;
command.CommandText = @"DROP TABLE IF EXISTS Child;
CREATE TABLE Child (
Id INT PRIMARY KEY,
ParentId INT NULL
Expand Down Expand Up @@ -225,7 +225,7 @@ ParentId INT NULL
[SkipOnCI]
public async Task ShouldHandleSelfRelationships()
{
await using var command = new DB2Command(@"DROP TABLE IF EXISTS Foo;
using var command = new DB2Command(@"DROP TABLE IF EXISTS Foo;
CREATE TABLE Foo (
Id INT PRIMARY KEY,
ParentId INT NULL
Expand Down Expand Up @@ -271,7 +271,7 @@ ParentId INT NULL
[SkipOnCI]
public async Task ShouldHandleComplexCycles()
{
await using var command = new DB2Command("DROP TABLE IF EXISTS A; CREATE TABLE A (Id INT PRIMARY KEY, B_Id INT NULL)", _connection);
using var command = new DB2Command("DROP TABLE IF EXISTS A; CREATE TABLE A (Id INT PRIMARY KEY, B_Id INT NULL)", _connection);
command.ExecuteNonQuery();
command.CommandText = "DROP TABLE IF EXISTS B; CREATE TABLE B (Id INT PRIMARY KEY, A_Id INT NULL, C_Id INT NULL, D_Id INT NULL)";
command.ExecuteNonQuery();
Expand Down Expand Up @@ -366,7 +366,7 @@ public async Task ShouldExcludeSchemas()

await ManageUser(user_1);
await ManageUser(user_2);
await using var command = new DB2Command($"DROP TABLE IF EXISTS {user_1}.Foo; CREATE TABLE {user_1}.Foo (Value INT)", _connection);
using var command = new DB2Command($"DROP TABLE IF EXISTS {user_1}.Foo; CREATE TABLE {user_1}.Foo (Value INT)", _connection);
command.ExecuteNonQuery();
command.CommandText = $"DROP TABLE IF EXISTS {user_2}.Bar; CREATE TABLE {user_2}.Bar (Value INT)";
command.ExecuteNonQuery();
Expand Down Expand Up @@ -410,7 +410,7 @@ public async Task ShouldIncludeSchemas()

await ManageUser(user_1);
await ManageUser(user_2);
await using var command = new DB2Command($"DROP TABLE IF EXISTS {user_1}.Fooo; CREATE TABLE {user_1}.Fooo (Value INT)", _connection);
using var command = new DB2Command($"DROP TABLE IF EXISTS {user_1}.Fooo; CREATE TABLE {user_1}.Fooo (Value INT)", _connection);
command.ExecuteNonQuery();
command.CommandText = $"DROP TABLE IF EXISTS {user_2}.Baar; CREATE TABLE {user_2}.Baar (Value INT)";
command.ExecuteNonQuery();
Expand Down Expand Up @@ -448,10 +448,10 @@ public async Task ShouldIncludeSchemas()

private async Task ManageUser(string userName)
{
await using var connection = new DB2Connection($"Server=127.0.0.1:9089;Database={_databaseName};UID=informix;PWD=in4mix;Persist Security Info=True;Authentication=Server;");
using var connection = new DB2Connection($"Server=127.0.0.1:9089;Database={_databaseName};UID=informix;PWD=in4mix;Persist Security Info=True;Authentication=Server;");
await connection.OpenAsync();

//await using var allUsers = new DB2Command("SELECT username FROM sysusers", connection);
//using var allUsers = new DB2Command("SELECT username FROM sysusers", connection);
var database = new Database(connection);

await database.ExecuteAsync($"DROP USER {userName};");
Expand Down
4 changes: 2 additions & 2 deletions Respawn.DatabaseTests/PostgresTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public async Task InitializeAsync()
dbConnString = "Server=127.0.0.1;Port=5432;User ID=postgres;Password=root;database={0}";
}
var dbName = DateTime.Now.ToString("yyyyMMddHHmmss") + Guid.NewGuid().ToString("N");
await using (var connection = new NpgsqlConnection(rootConnString))
using (var connection = new NpgsqlConnection(rootConnString))
{
connection.Open();

await using (var cmd = connection.CreateCommand())
using (var cmd = connection.CreateCommand())
{
cmd.CommandText = "create database \"" + dbName + "\"";
await cmd.ExecuteNonQueryAsync();
Expand Down
2 changes: 1 addition & 1 deletion Respawn.DatabaseTests/Respawn.DatabaseTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" PrivateAssets="All" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="4.0.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="4.0.5" />
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="3.21.90" />
</ItemGroup>
<ItemGroup>
Expand Down
98 changes: 49 additions & 49 deletions Respawn.DatabaseTests/SqlServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public async Task InitializeAsync()
{
var connString = @"Server=(LocalDb)\mssqllocaldb;Database=tempdb;Integrated Security=True";

await using (var connection = new SqlConnection(connString))
using (var connection = new SqlConnection(connString))
{
await connection.OpenAsync();
using (var database = new Database(connection))
Expand Down Expand Up @@ -231,7 +231,7 @@ public async Task ShouldHandleCircularRelationships()
{
await checkpoint.ResetAsync(_connection);
}
catch
catch
{
_output.WriteLine(checkpoint.DeleteSql);
throw;
Expand Down Expand Up @@ -262,8 +262,8 @@ public async Task ShouldIgnoreTables()
{
_output.WriteLine(checkpoint.DeleteSql);
throw;
}
}

_output.WriteLine(checkpoint.DeleteSql);
_database.ExecuteScalar<int>("SELECT COUNT(1) FROM Foo").ShouldBe(100);
_database.ExecuteScalar<int>("SELECT COUNT(1) FROM Bar").ShouldBe(0);
Expand Down Expand Up @@ -293,7 +293,7 @@ public async Task ShouldIgnoreTablesWithSchema()
{
TablesToIgnore = new[]
{
new Table("A", "Foo"),
new Table("A", "Foo"),
new Table("A", "FooWithBrackets")
}
});
Expand Down Expand Up @@ -342,7 +342,7 @@ public async Task ShouldIncludeTables()

[Fact]
public async Task ShouldExcludeSchemas()
{
{
await _database.ExecuteAsync("drop schema if exists A");
await _database.ExecuteAsync("drop schema if exists B");
await _database.ExecuteAsync("create schema A");
Expand Down Expand Up @@ -440,10 +440,10 @@ public async Task ShouldReseedId_TableWithSchema()
{
await _database.ExecuteAsync("IF EXISTS (SELECT * FROM sys.schemas WHERE name = 'A') DROP SCHEMA A");
await _database.ExecuteAsync("create schema A");
await _database.ExecuteAsync("create table A.Foo ([id] [int] IDENTITY(1,1), Value int)");

for (int i = 0; i < 100; i++)
{
await _database.ExecuteAsync("create table A.Foo ([id] [int] IDENTITY(1,1), Value int)");

for (int i = 0; i < 100; i++)
{
await _database.ExecuteAsync("INSERT A.Foo VALUES (" + i + ")");
}

Expand All @@ -461,16 +461,16 @@ public async Task ShouldReseedId_TableWithSchema()
{
_output.WriteLine(checkpoint.ReseedSql);
throw;
}

}

await _database.ExecuteAsync("INSERT A.Foo VALUES (0)");

_database.ExecuteScalar<int>("SELECT MAX(id) FROM A.Foo").ShouldBe(1);
}

[Fact]
public async Task ShouldReseedId_TableHasNeverHadAnyData()
{
{
await _database.ExecuteAsync("drop schema if exists A");
await _database.ExecuteAsync("create schema A");
await _database.ExecuteAsync("create table A.Foo ([id] [int] IDENTITY(1,1), Value int)");
Expand All @@ -486,12 +486,12 @@ public async Task ShouldReseedId_TableHasNeverHadAnyData()
{
_output.WriteLine(checkpoint.ReseedSql);
throw;
}

}

await _database.ExecuteAsync("INSERT A.Foo VALUES (0)");
_database.ExecuteScalar<int>("SELECT MAX(id) FROM A.Foo").ShouldBe(1);
}

}

[Fact]
public async Task ShouldReseedId_TableWithSchemaHasNeverHadAnyData()
{
Expand Down Expand Up @@ -539,17 +539,17 @@ public async Task ShouldNotReseedId()

await _database.InsertAsync(new Foo { Value = 0 });
_database.ExecuteScalar<int>("SELECT MAX(id) FROM Foo").ShouldBe(101);
}

}

[Fact]
public async Task ShouldNotReseedId_TableWithSchema()
{
{
await _database.ExecuteAsync("drop schema if exists A");
await _database.ExecuteAsync("create schema A");
await _database.ExecuteAsync("create table A.Foo ([id] [int] IDENTITY(1,1), Value int)");

for (int i = 0; i < 100; i++)
{
await _database.ExecuteAsync("create table A.Foo ([id] [int] IDENTITY(1,1), Value int)");

for (int i = 0; i < 100; i++)
{
await _database.ExecuteAsync("INSERT A.Foo VALUES (" + i + ")");
}

Expand All @@ -567,8 +567,8 @@ public async Task ShouldNotReseedId_TableWithSchema()
{
_output.WriteLine(checkpoint.ReseedSql);
throw;
}

}

await _database.ExecuteAsync("INSERT A.Foo VALUES (0)");
_database.ExecuteScalar<int>("SELECT MAX(id) FROM A.Foo").ShouldBe(101);
}
Expand Down Expand Up @@ -602,14 +602,14 @@ public async Task ShouldReseedIdAccordingToIdentityInitialSeedValue()
}

[Fact]
public async Task ShouldReseedIdAccordingToIdentityInitialSeedValue_TableWithSchema()
{
public async Task ShouldReseedIdAccordingToIdentityInitialSeedValue_TableWithSchema()
{
await _database.ExecuteAsync("drop schema if exists A");
await _database.ExecuteAsync("create schema A");
await _database.ExecuteAsync("create table A.Foo ([id] [int] IDENTITY(1001,1), Value int)");

for (int i = 0; i < 100; i++)
{
await _database.ExecuteAsync("create schema A");
await _database.ExecuteAsync("create table A.Foo ([id] [int] IDENTITY(1001,1), Value int)");

for (int i = 0; i < 100; i++)
{
await _database.ExecuteAsync("INSERT A.Foo VALUES (" + i + ")");
}

Expand All @@ -628,10 +628,10 @@ public async Task ShouldReseedIdAccordingToIdentityInitialSeedValue_TableWithSch
{
_output.WriteLine(checkpoint.ReseedSql);
throw;
}

}

await _database.ExecuteAsync("INSERT A.Foo VALUES (0)");
_database.ExecuteScalar<int>("SELECT MAX(id) FROM A.Foo").ShouldBe(1001);
_database.ExecuteScalar<int>("SELECT MAX(id) FROM A.Foo").ShouldBe(1001);
}

[Fact]
Expand All @@ -656,11 +656,11 @@ public async Task ShouldReseedIdAccordingToIdentityInitialSeedValue_TableHasNeve

await _database.InsertAsync(new Foo { Value = 0 });
_database.ExecuteScalar<int>("SELECT MAX(id) FROM Foo").ShouldBe(1001);
}

}

[Fact]
public async Task ShouldReseedIdAccordingToIdentityInitialSeedValue_TableWithSchemaHasNeverHadAnyData()
{
{
await _database.ExecuteAsync("drop schema if exists A");
await _database.ExecuteAsync("create schema A");
await _database.ExecuteAsync("create table A.Foo ([id] [int] IDENTITY(1001,1), Value int)");
Expand All @@ -678,8 +678,8 @@ public async Task ShouldReseedIdAccordingToIdentityInitialSeedValue_TableWithSch
{
_output.WriteLine(checkpoint.ReseedSql);
throw;
}

}

await _database.ExecuteAsync("INSERT A.Foo VALUES (0)");
_database.ExecuteScalar<int>("SELECT MAX(id) FROM A.Foo").ShouldBe(1001);
}
Expand Down Expand Up @@ -732,8 +732,8 @@ await _database.ExecuteAsync("create table Foo (Value [int] not null primary key
await checkpoint.ResetAsync(_connection);

var sql = @"
SELECT t1.name
FROM sys.tables t1
SELECT t1.name
FROM sys.tables t1
WHERE t1.object_id = (SELECT history_table_id FROM sys.tables t2 WHERE t2.name = 'Foo')
";
_database.ExecuteScalar<string>(sql).ShouldBe("FooHistory");
Expand Down Expand Up @@ -762,18 +762,18 @@ await _database.ExecuteAsync("create table Foo (Value [int] not null primary key
await checkpoint.ResetAsync(_connection);

var sql = @"
SELECT t1.name
FROM sys.tables t1
SELECT t1.name
FROM sys.tables t1
WHERE t1.object_id = (SELECT history_table_id FROM sys.tables t2 WHERE t2.name = 'Foo')
";
_database.ExecuteScalar<string>(sql).ShouldStartWith("MSSQL_TemporalHistoryFor_");
}

}

[Fact]
public async Task ShouldDeleteTemporalTablesDataFromNotDefaultSchemas()
{
await _database.ExecuteAsync("CREATE SCHEMA [TableSchema] AUTHORIZATION [dbo];");
await _database.ExecuteAsync("CREATE SCHEMA [HistorySchema] AUTHORIZATION [dbo];");
await _database.ExecuteAsync("CREATE SCHEMA [TableSchema] AUTHORIZATION [dbo];");
await _database.ExecuteAsync("CREATE SCHEMA [HistorySchema] AUTHORIZATION [dbo];");

await _database.ExecuteAsync("create table TableSchema.Foo (Value [int] not null primary key clustered, " +
"ValidFrom datetime2 generated always as row start, " +
Expand Down
5 changes: 1 addition & 4 deletions Respawn/IDbAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ public interface IDbAdapter
string BuildReseedSql(IEnumerable<Table> tablesToDelete);
string BuildTurnOffSystemVersioningCommandText(IEnumerable<TemporalTable> tablesToTurnOffSystemVersioning);
string BuildTurnOnSystemVersioningCommandText(IEnumerable<TemporalTable> tablesToTurnOnSystemVersioning);
Task<bool> CheckSupportsTemporalTables(DbConnection connection)
{
return Task.FromResult(false);
}
Task<bool> CheckSupportsTemporalTables(DbConnection connection);
}
}
Loading

0 comments on commit ee5a0d4

Please sign in to comment.