-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from leancodepl/feature/postgres-integration-tests
Add postgres integration test
- Loading branch information
Showing
8 changed files
with
107 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
backend/tests/LeanCode.AppRating.IntegrationTests/TestDatabaseConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using LeanCode.AppRating.DataAccess; | ||
using LeanCode.CQRS.MassTransitRelay.LockProviders; | ||
using LeanCode.DomainModels.EF; | ||
using LeanCode.IntegrationTestHelpers; | ||
using MassTransit; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Configuration; | ||
using Npgsql; | ||
|
||
namespace LeanCode.AppRating.IntegrationTests; | ||
|
||
public abstract class TestDatabaseConfig | ||
{ | ||
public const string ConfigEnvName = "AppReviewIntegrationTests__Database"; | ||
|
||
public abstract SqlDbType DbType { get; } | ||
public abstract ConfigurationOverrides GetConfigurationOverrides(); | ||
public abstract void ConfigureDbContext(DbContextOptionsBuilder builder, IConfiguration config); | ||
|
||
public static TestDatabaseConfig Create() | ||
{ | ||
return Environment.GetEnvironmentVariable(ConfigEnvName) switch | ||
{ | ||
"sqlserver" => new SqlServerTestDatabaseConfig(), | ||
"postgres" => new PostgresTestConfig(), | ||
_ | ||
=> throw new InvalidOperationException( | ||
$"Set the database provider (sqlserver|postgres) via {ConfigEnvName} env variable" | ||
), | ||
}; | ||
} | ||
} | ||
|
||
public class SqlServerTestDatabaseConfig : TestDatabaseConfig | ||
{ | ||
public override SqlDbType DbType => SqlDbType.MsSql; | ||
|
||
public override ConfigurationOverrides GetConfigurationOverrides() => | ||
new("SqlServer__ConnectionStringBase", "SqlServer:ConnectionString"); | ||
|
||
public override void ConfigureDbContext(DbContextOptionsBuilder builder, IConfiguration config) | ||
{ | ||
builder.UseSqlServer(config.GetValue<string>("SqlServer:ConnectionString")); | ||
} | ||
} | ||
|
||
public class PostgresTestConfig : TestDatabaseConfig | ||
{ | ||
public override SqlDbType DbType => SqlDbType.PostgreSql; | ||
|
||
public override ConfigurationOverrides GetConfigurationOverrides() => | ||
new("Postgres__ConnectionStringBase", "Postgres:ConnectionString"); | ||
|
||
public override void ConfigureDbContext(DbContextOptionsBuilder builder, IConfiguration config) | ||
{ | ||
var dataSource = new NpgsqlDataSourceBuilder(config.GetValue<string>("Postgres:ConnectionString")) | ||
.EnableDynamicJson() | ||
.Build(); | ||
builder.UseNpgsql(dataSource); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters