Skip to content

Commit

Permalink
tests: moved back to SqlServer for tests, fixed FK issue with deletes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris S committed Sep 17, 2016
1 parent 1fc62de commit 6d48832
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
Expand Up @@ -141,7 +141,10 @@ public void DeletePage(Page page)
{
connection.Open();

string sql = $"delete from {PagesTableName} where id=@Id";
string sql = $"delete from {PageContentsTableName} where pageid=@Id";
connection.Execute(sql, new { Id = page.Id });

sql = $"delete from {PagesTableName} where id=@Id";
connection.Execute(sql, new { Id = page.Id });
}
}
Expand Down
Expand Up @@ -14,35 +14,35 @@ public class DapperInstallerRepositoryTests : InstallerRepositoryTests
{
protected override string ConnectionString
{
get { return TestConstants.POSTGRES_CONNECTION_STRING; }
get { return TestConstants.SQLSERVER_CONNECTION_STRING; }
}

protected override string InvalidConnectionString
{
get { return "User ID=postgres;Password=mysecretpassword;Host=localhost;Port=5432;Database=doesntexist;"; }
get
{
return TestConstants.SQLSERVER_CONNECTION_STRING.Replace("Database=roadkill", "Database=doesntexist");
}
}

private IDbConnectionFactory GetDbFactory(string connectionString = "")
{
if (string.IsNullOrEmpty(connectionString))
connectionString = ConnectionString;

return new PostgresConnectionFactory(connectionString);
return new SqlConnectionFactory(connectionString);
}

protected override IInstallerRepository GetRepository(string connectionString)
{
var schema = new PostgresSchema();
var schema = new SqlServerSchema();
return new DapperInstallerRepository(GetDbFactory(connectionString), schema);
}

protected override void Clearup()
{
//TestHelpers.SqlServerSetup.RecreateTables();
//TestHelpers.SqlServerSetup.ClearDatabase();

TestHelpers.PostgresSetup.RecreateTables();
TestHelpers.PostgresSetup.ClearDatabase();
TestHelpers.SqlServerSetup.RecreateTables();
TestHelpers.SqlServerSetup.ClearDatabase();
}

protected override bool HasEmptyTables()
Expand Down
Expand Up @@ -11,19 +11,19 @@ public class DapperPageRepositoryTests : PageRepositoryTests
{
protected override string ConnectionString
{
get { return TestConstants.POSTGRES_CONNECTION_STRING; }
get { return TestConstants.SQLSERVER_CONNECTION_STRING; }
}

protected override IPageRepository GetRepository()
{
var factory = new PostgresConnectionFactory(ConnectionString);
var factory = new SqlConnectionFactory(ConnectionString);
return new DapperPageRepository(factory);
}

protected override void Clearup()
{
TestHelpers.PostgresSetup.RecreateTables();
TestHelpers.PostgresSetup.ClearDatabase();
TestHelpers.SqlServerSetup.RecreateTables();
TestHelpers.SqlServerSetup.ClearDatabase();
}
}
}
Expand Up @@ -9,26 +9,26 @@ namespace Roadkill.Tests.Integration.Repository.Dapper
[Category("Integration")]
public class DapperSettingsRepositoryTests : SettingsRepositoryTests
{
protected override string ConnectionString => TestConstants.POSTGRES_CONNECTION_STRING;
protected override string ConnectionString => TestConstants.SQLSERVER_CONNECTION_STRING;

protected override string InvalidConnectionString
{
get { return "User ID=postgres;Password=mysecretpassword;Host=localhost;Port=5432;Database=doesntexist;"; }
get
{
return TestConstants.SQLSERVER_CONNECTION_STRING.Replace("Database=roadkill", "Database=doesntexist");
}
}

protected override ISettingsRepository GetRepository()
{
var factory = new PostgresConnectionFactory(ConnectionString);
var factory = new SqlConnectionFactory(ConnectionString);
return new DapperSettingsRepository(factory);
}

protected override void Clearup()
{
//TestHelpers.SqlServerSetup.RecreateTables();
//TestHelpers.SqlServerSetup.ClearDatabase();

TestHelpers.PostgresSetup.RecreateTables();
TestHelpers.PostgresSetup.ClearDatabase();
TestHelpers.SqlServerSetup.RecreateTables();
TestHelpers.SqlServerSetup.ClearDatabase();
}
}
}
Expand Up @@ -9,21 +9,18 @@ namespace Roadkill.Tests.Integration.Repository.Dapper
[Category("Integration")]
public class DapperUserRepositoryTests : UserRepositoryTests
{
protected override string ConnectionString => TestConstants.POSTGRES_CONNECTION_STRING;
protected override string ConnectionString => TestConstants.SQLSERVER_CONNECTION_STRING;

protected override IUserRepository GetRepository()
{
var factory = new PostgresConnectionFactory(ConnectionString);
var factory = new SqlConnectionFactory(ConnectionString);
return new DapperUserRepository(factory);
}

protected override void Clearup()
{
//TestHelpers.SqlServerSetup.RecreateTables();
//TestHelpers.SqlServerSetup.ClearDatabase();

TestHelpers.PostgresSetup.RecreateTables();
TestHelpers.PostgresSetup.ClearDatabase();
TestHelpers.SqlServerSetup.RecreateTables();
TestHelpers.SqlServerSetup.ClearDatabase();
}
}
}
4 changes: 2 additions & 2 deletions src/Roadkill.Tests/TestConstants.cs
Expand Up @@ -20,7 +20,7 @@ public class TestConstants
public static readonly string WEB_SITENAME = "RoadkillTests";
public static readonly string WEB_BASEURL = "http://localhost:" +WEB_PORT;

public static readonly string SQLSERVER_CONNECTION_STRING = "Server=(local);Integrated Security=true;Connect Timeout=5;database=Roadkill";
public static readonly string SQLSERVER_CONNECTION_STRING = "Server=(local);Integrated Security=true;Connect Timeout=5;Database=roadkill";
public static readonly string POSTGRES_CONNECTION_STRING = "User ID=postgres;Password=mysecretpassword;Host=localhost;Port=5432;Database=roadkill;";

public static readonly string REST_API_KEY = "apikey1";
Expand Down Expand Up @@ -51,7 +51,7 @@ static TestConstants()
else
{
// This should match connectionStrings.dev.config
SQLSERVER_CONNECTION_STRING = "Server=(local);Integrated Security=true;Connect Timeout=5;database=Roadkill";
SQLSERVER_CONNECTION_STRING = "Server=(local);Integrated Security=true;Connect Timeout=5;Database=roadkill";
}
}
}
Expand Down

0 comments on commit 6d48832

Please sign in to comment.