diff --git a/unittests/Basic_tests/Startup.cs b/unittests/Basic_tests/Startup.cs new file mode 100644 index 00000000..55fac66b --- /dev/null +++ b/unittests/Basic_tests/Startup.cs @@ -0,0 +1,6 @@ +namespace Basic_tests; + +// ReSharper disable once UnusedType.Global +public class Startup +{ +} diff --git a/unittests/CommandLine/CommandLine.Common/Startup_T.cs b/unittests/CommandLine/CommandLine.Common/Startup_T.cs new file mode 100644 index 00000000..4aa17ff8 --- /dev/null +++ b/unittests/CommandLine/CommandLine.Common/Startup_T.cs @@ -0,0 +1,25 @@ +using CommandLine.Common.TestInfrastructure; +using grate.Configuration; +using grate.Migration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using TestCommon.TestInfrastructure; + +namespace CommandLine.Common; + +// ReSharper disable once UnusedType.Global +public abstract class Startup< + TTestContainerDatabase, + TExternalDatabase, + TGrateTestContext>: TestCommon.Startup + where TTestContainerDatabase : ITestDatabase + where TExternalDatabase : ITestDatabase + where TGrateTestContext : IGrateTestContext +{ + protected abstract DatabaseType DatabaseType { get; } + + protected override void ConfigureExtraServices(IServiceCollection services, HostBuilderContext context) + { + services.AddSingleton(new CommandLineGrateMigrator(DatabaseType)); + } +} diff --git a/unittests/CommandLine/CommandLine.MariaDB/Startup.cs b/unittests/CommandLine/CommandLine.MariaDB/Startup.cs index 813053aa..809ab0e0 100644 --- a/unittests/CommandLine/CommandLine.MariaDB/Startup.cs +++ b/unittests/CommandLine/CommandLine.MariaDB/Startup.cs @@ -4,10 +4,7 @@ namespace CommandLine.MariaDB; // ReSharper disable once UnusedType.Global -public class Startup: TestCommon.Startup +public class Startup: CommandLine.Common.Startup { protected override DatabaseType DatabaseType => DatabaseType.MariaDB; - protected override Type TestContainerDatabaseType => typeof(MariaDbTestContainerDatabase); - protected override Type ExternalTestDatabaseType => typeof(MariaDBExternalDatabase); - protected override Type TestContextType => typeof(MariaDbGrateTestContext); } diff --git a/unittests/CommandLine/CommandLine.Oracle/Startup.cs b/unittests/CommandLine/CommandLine.Oracle/Startup.cs index a1e8be4a..ff37bfc5 100644 --- a/unittests/CommandLine/CommandLine.Oracle/Startup.cs +++ b/unittests/CommandLine/CommandLine.Oracle/Startup.cs @@ -1,13 +1,12 @@ using grate.Configuration; +using Oraclde.TestInfrastructure; using Oracle.TestInfrastructure; using TestCommon.TestInfrastructure; namespace CommandLine.Oracle; // ReSharper disable once UnusedType.Global -public class Startup: TestCommon.Startup +public class Startup: Common.Startup { protected override DatabaseType DatabaseType => DatabaseType.Oracle; - protected override Type TestContainerDatabaseType => typeof(OracleTestContainerDatabase); - protected override Type TestContextType => typeof(OracleGrateTestContext); } diff --git a/unittests/CommandLine/CommandLine.PostgreSQL/Running_MigrationScripts/Failing_Scripts.cs b/unittests/CommandLine/CommandLine.PostgreSQL/Running_MigrationScripts/Failing_Scripts.cs index e06cdcde..f3426a7e 100644 --- a/unittests/CommandLine/CommandLine.PostgreSQL/Running_MigrationScripts/Failing_Scripts.cs +++ b/unittests/CommandLine/CommandLine.PostgreSQL/Running_MigrationScripts/Failing_Scripts.cs @@ -2,7 +2,7 @@ namespace CommandLine.PostgreSQL.Running_MigrationScripts; -[Collection(nameof(PostgreSqlTestContainer))] +[Collection(nameof(PostgreSqlTestContainerDatabase))] // ReSharper disable once InconsistentNaming public class Failing_Scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.Failing_Scripts(testContext, testOutput) diff --git a/unittests/CommandLine/CommandLine.PostgreSQL/Running_MigrationScripts/One_time_scripts.cs b/unittests/CommandLine/CommandLine.PostgreSQL/Running_MigrationScripts/One_time_scripts.cs index 9e7f9f8a..8ad34f4d 100644 --- a/unittests/CommandLine/CommandLine.PostgreSQL/Running_MigrationScripts/One_time_scripts.cs +++ b/unittests/CommandLine/CommandLine.PostgreSQL/Running_MigrationScripts/One_time_scripts.cs @@ -7,7 +7,7 @@ namespace CommandLine.PostgreSQL.Running_MigrationScripts; -[Collection(nameof(PostgreSqlTestContainer))] +[Collection(nameof(PostgreSqlTestContainerDatabase))] // ReSharper disable once InconsistentNaming public class One_time_scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.One_time_scripts(testContext, testOutput) diff --git a/unittests/CommandLine/CommandLine.PostgreSQL/Startup.cs b/unittests/CommandLine/CommandLine.PostgreSQL/Startup.cs index b1c32e78..f2522be9 100644 --- a/unittests/CommandLine/CommandLine.PostgreSQL/Startup.cs +++ b/unittests/CommandLine/CommandLine.PostgreSQL/Startup.cs @@ -5,9 +5,7 @@ namespace CommandLine.PostgreSQL; // ReSharper disable once UnusedType.Global -public class Startup: TestCommon.Startup +public class Startup: Common.Startup { protected override DatabaseType DatabaseType => DatabaseType.PostgreSQL; - protected override Type TestContainerDatabaseType => typeof(PostgreSqlTestContainer); - protected override Type TestContextType => typeof(PostgreSqlGrateTestContext); } diff --git a/unittests/CommandLine/CommandLine.SqlServer/Startup.cs b/unittests/CommandLine/CommandLine.SqlServer/Startup.cs index 8b72d878..962bed77 100644 --- a/unittests/CommandLine/CommandLine.SqlServer/Startup.cs +++ b/unittests/CommandLine/CommandLine.SqlServer/Startup.cs @@ -4,10 +4,7 @@ namespace CommandLine.SqlServer; // ReSharper disable once UnusedType.Global -public class Startup: CommandLine.Common.Startup +public class Startup: Common.Startup { protected override DatabaseType DatabaseType => DatabaseType.SQLServer; - protected override Type TestContainerDatabaseType => typeof(SqlServerTestContainerDatabase); - protected override Type ExternalTestDatabaseType => typeof(SqlServerExternalDatabase); - protected override Type TestContextType => typeof(SqlServerGrateTestContext); } diff --git a/unittests/CommandLine/CommandLine.Sqlite/Running_MigrationScripts/Failing_Scripts.cs b/unittests/CommandLine/CommandLine.Sqlite/Running_MigrationScripts/Failing_Scripts.cs index 5fb5641b..1bf1b300 100644 --- a/unittests/CommandLine/CommandLine.Sqlite/Running_MigrationScripts/Failing_Scripts.cs +++ b/unittests/CommandLine/CommandLine.Sqlite/Running_MigrationScripts/Failing_Scripts.cs @@ -2,7 +2,7 @@ namespace CommandLine.Sqlite.Running_MigrationScripts; -[Collection(nameof(SqliteTestContainerDatabase))] +[Collection(nameof(SqliteTestDatabase))] // ReSharper disable once InconsistentNaming public class Failing_Scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.Failing_Scripts(testContext, testOutput) diff --git a/unittests/CommandLine/CommandLine.Sqlite/Running_MigrationScripts/One_time_scripts.cs b/unittests/CommandLine/CommandLine.Sqlite/Running_MigrationScripts/One_time_scripts.cs index 831eeb5b..fea9180d 100644 --- a/unittests/CommandLine/CommandLine.Sqlite/Running_MigrationScripts/One_time_scripts.cs +++ b/unittests/CommandLine/CommandLine.Sqlite/Running_MigrationScripts/One_time_scripts.cs @@ -7,7 +7,7 @@ namespace CommandLine.Sqlite.Running_MigrationScripts; -[Collection(nameof(SqliteTestContainerDatabase))] +[Collection(nameof(SqliteTestDatabase))] // ReSharper disable once InconsistentNaming public class One_time_scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.One_time_scripts(testContext, testOutput) diff --git a/unittests/CommandLine/CommandLine.Sqlite/Startup.cs b/unittests/CommandLine/CommandLine.Sqlite/Startup.cs index ed2d8d88..ff25c77a 100644 --- a/unittests/CommandLine/CommandLine.Sqlite/Startup.cs +++ b/unittests/CommandLine/CommandLine.Sqlite/Startup.cs @@ -5,10 +5,7 @@ namespace CommandLine.Sqlite; // ReSharper disable once UnusedType.Global -public class Startup: TestCommon.Startup +public class Startup: CommandLine.Common.Startup { protected override DatabaseType DatabaseType => DatabaseType.SQLite; - protected override Type TestContainerDatabaseType => typeof(SqliteTestContainerDatabase); - protected override Type ExternalTestDatabaseType { get; } - protected override Type TestContextType => typeof(SqliteGrateTestContext); } diff --git a/unittests/MariaDB/Database.cs b/unittests/MariaDB/Database.cs index a40bcc6a..96be28f3 100644 --- a/unittests/MariaDB/Database.cs +++ b/unittests/MariaDB/Database.cs @@ -4,8 +4,8 @@ namespace MariaDB; -//[Collection(nameof(MariaDbTestContainer))] +[Collection(nameof(MariaDbGrateTestContext))] // ReSharper disable once UnusedType.Global -public class Database(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class Database(MariaDbGrateTestContext testContext, ITestOutputHelper testOutput) : GenericDatabase(testContext, testOutput); diff --git a/unittests/MariaDB/DependencyInjection/ServiceCollectionTest.cs b/unittests/MariaDB/DependencyInjection/ServiceCollectionTest.cs index 7855dbec..1aea9546 100644 --- a/unittests/MariaDB/DependencyInjection/ServiceCollectionTest.cs +++ b/unittests/MariaDB/DependencyInjection/ServiceCollectionTest.cs @@ -2,7 +2,7 @@ using TestCommon.TestInfrastructure; namespace MariaDB.DependencyInjection; -//[Collection(nameof(MariaDbTestContainer))] +[Collection(nameof(MariaDbGrateTestContext))] // ReSharper disable once UnusedType.Global -public class ServiceCollectionTest(IGrateTestContext context) +public class ServiceCollectionTest(MariaDbGrateTestContext context) : TestCommon.DependencyInjection.GrateServiceCollectionTest(context); diff --git a/unittests/MariaDB/MigrationTables.cs b/unittests/MariaDB/MigrationTables.cs index 3d5bca49..1d0aee96 100644 --- a/unittests/MariaDB/MigrationTables.cs +++ b/unittests/MariaDB/MigrationTables.cs @@ -4,6 +4,6 @@ namespace MariaDB; -//[Collection(nameof(MariaDbTestContainer))] -public class MigrationTables(IGrateTestContext testContext, ITestOutputHelper testOutput) : +[Collection(nameof(MariaDbGrateTestContext))] +public class MigrationTables(MariaDbGrateTestContext testContext, ITestOutputHelper testOutput) : GenericMigrationTables(testContext, testOutput); diff --git a/unittests/MariaDB/Running_MigrationScripts/Anytime_scripts.cs b/unittests/MariaDB/Running_MigrationScripts/Anytime_scripts.cs index 54c95a00..aa8947fc 100644 --- a/unittests/MariaDB/Running_MigrationScripts/Anytime_scripts.cs +++ b/unittests/MariaDB/Running_MigrationScripts/Anytime_scripts.cs @@ -3,7 +3,7 @@ namespace MariaDB.Running_MigrationScripts; -//[Collection(nameof(MariaDbTestContainer))] +[Collection(nameof(MariaDbGrateTestContext))] // ReSharper disable once InconsistentNaming -public class Anytime_scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class Anytime_scripts(MariaDbGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.Anytime_scripts(testContext, testOutput); diff --git a/unittests/MariaDB/Running_MigrationScripts/DropDatabase.cs b/unittests/MariaDB/Running_MigrationScripts/DropDatabase.cs index f1f63d66..a694f52e 100644 --- a/unittests/MariaDB/Running_MigrationScripts/DropDatabase.cs +++ b/unittests/MariaDB/Running_MigrationScripts/DropDatabase.cs @@ -3,7 +3,7 @@ namespace MariaDB.Running_MigrationScripts; -//[Collection(nameof(MariaDbTestContainer))] +[Collection(nameof(MariaDbGrateTestContext))] // ReSharper disable once UnusedType.Global -public class DropDatabase(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class DropDatabase(MariaDbGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.DropDatabase(testContext, testOutput); diff --git a/unittests/MariaDB/Running_MigrationScripts/Environment_scripts.cs b/unittests/MariaDB/Running_MigrationScripts/Environment_scripts.cs index d7cf9b89..efe88caf 100644 --- a/unittests/MariaDB/Running_MigrationScripts/Environment_scripts.cs +++ b/unittests/MariaDB/Running_MigrationScripts/Environment_scripts.cs @@ -3,7 +3,7 @@ namespace MariaDB.Running_MigrationScripts; -//[Collection(nameof(MariaDbTestContainer))] +[Collection(nameof(MariaDbGrateTestContext))] // ReSharper disable once InconsistentNaming -public class Environment_scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class Environment_scripts(MariaDbGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.Environment_scripts(testContext, testOutput); diff --git a/unittests/MariaDB/Running_MigrationScripts/Everytime_scripts.cs b/unittests/MariaDB/Running_MigrationScripts/Everytime_scripts.cs index 67651250..83d8c7a2 100644 --- a/unittests/MariaDB/Running_MigrationScripts/Everytime_scripts.cs +++ b/unittests/MariaDB/Running_MigrationScripts/Everytime_scripts.cs @@ -3,7 +3,7 @@ namespace MariaDB.Running_MigrationScripts; -//[Collection(nameof(MariaDbTestContainer))] +[Collection(nameof(MariaDbGrateTestContext))] // ReSharper disable once InconsistentNaming -public class Everytime_scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class Everytime_scripts(MariaDbGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.Everytime_scripts(testContext, testOutput); diff --git a/unittests/MariaDB/Running_MigrationScripts/Failing_Scripts.cs b/unittests/MariaDB/Running_MigrationScripts/Failing_Scripts.cs index 9e7f3f17..08560c1c 100644 --- a/unittests/MariaDB/Running_MigrationScripts/Failing_Scripts.cs +++ b/unittests/MariaDB/Running_MigrationScripts/Failing_Scripts.cs @@ -3,9 +3,9 @@ namespace MariaDB.Running_MigrationScripts; -//[Collection(nameof(MariaDbTestContainer))] +[Collection(nameof(MariaDbGrateTestContext))] // ReSharper disable once InconsistentNaming -public class Failing_Scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class Failing_Scripts(MariaDbGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.Failing_Scripts(testContext, testOutput) { protected override string ExpectedErrorMessageForInvalidSql => diff --git a/unittests/MariaDB/Running_MigrationScripts/One_time_scripts.cs b/unittests/MariaDB/Running_MigrationScripts/One_time_scripts.cs index 05a6fb01..08c4f3bf 100644 --- a/unittests/MariaDB/Running_MigrationScripts/One_time_scripts.cs +++ b/unittests/MariaDB/Running_MigrationScripts/One_time_scripts.cs @@ -3,8 +3,8 @@ namespace MariaDB.Running_MigrationScripts; -//[Collection(nameof(MariaDbTestContainer))] +[Collection(nameof(MariaDbGrateTestContext))] // ReSharper disable once InconsistentNaming -public class One_time_scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class One_time_scripts(MariaDbGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.One_time_scripts(testContext, testOutput); diff --git a/unittests/MariaDB/Running_MigrationScripts/Order_Of_Scripts.cs b/unittests/MariaDB/Running_MigrationScripts/Order_Of_Scripts.cs index 43467c72..78ab70ef 100644 --- a/unittests/MariaDB/Running_MigrationScripts/Order_Of_Scripts.cs +++ b/unittests/MariaDB/Running_MigrationScripts/Order_Of_Scripts.cs @@ -3,8 +3,8 @@ namespace MariaDB.Running_MigrationScripts; -//[Collection(nameof(MariaDbTestContainer))] +[Collection(nameof(MariaDbGrateTestContext))] // ReSharper disable once InconsistentNaming -public class Order_Of_Scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class Order_Of_Scripts(MariaDbGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.Order_Of_Scripts(testContext, testOutput); diff --git a/unittests/MariaDB/Running_MigrationScripts/ScriptsRun_Table.cs b/unittests/MariaDB/Running_MigrationScripts/ScriptsRun_Table.cs index 8de837df..ff63d7d7 100644 --- a/unittests/MariaDB/Running_MigrationScripts/ScriptsRun_Table.cs +++ b/unittests/MariaDB/Running_MigrationScripts/ScriptsRun_Table.cs @@ -3,6 +3,6 @@ namespace MariaDB.Running_MigrationScripts; -//[Collection(nameof(MariaDbTestContainer))] -public class ScriptsRun_Table(IGrateTestContext testContext, ITestOutputHelper testOutput) +[Collection(nameof(MariaDbGrateTestContext))] +public class ScriptsRun_Table(MariaDbGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.ScriptsRun_Table(testContext, testOutput); diff --git a/unittests/MariaDB/Running_MigrationScripts/TokenScripts.cs b/unittests/MariaDB/Running_MigrationScripts/TokenScripts.cs index 14c5ae10..38714a73 100644 --- a/unittests/MariaDB/Running_MigrationScripts/TokenScripts.cs +++ b/unittests/MariaDB/Running_MigrationScripts/TokenScripts.cs @@ -3,7 +3,7 @@ namespace MariaDB.Running_MigrationScripts; -//[Collection(nameof(MariaDbTestContainer))] -public class TokenScripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +[Collection(nameof(MariaDbGrateTestContext))] +public class TokenScripts(MariaDbGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.TokenScripts(testContext, testOutput); diff --git a/unittests/MariaDB/Running_MigrationScripts/Versioning_The_Database.cs b/unittests/MariaDB/Running_MigrationScripts/Versioning_The_Database.cs index 0b7c00aa..b83dcc88 100644 --- a/unittests/MariaDB/Running_MigrationScripts/Versioning_The_Database.cs +++ b/unittests/MariaDB/Running_MigrationScripts/Versioning_The_Database.cs @@ -4,9 +4,9 @@ namespace MariaDB.Running_MigrationScripts; -//[Collection(nameof(MariaDbTestContainer))] +[Collection(nameof(MariaDbGrateTestContext))] // ReSharper disable once InconsistentNaming -public class Versioning_The_Database(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class Versioning_The_Database(MariaDbGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.Versioning_The_Database(testContext, testOutput); diff --git a/unittests/Oracle/Database.cs b/unittests/Oracle/Database.cs index e51855aa..8ec85067 100644 --- a/unittests/Oracle/Database.cs +++ b/unittests/Oracle/Database.cs @@ -1,8 +1,9 @@ -using TestCommon.Generic; +using Oracle.TestInfrastructure; +using TestCommon.Generic; using TestCommon.TestInfrastructure; namespace Oracle; -[Collection(nameof(OracleTestContainerDatabase))] -public class Database(IGrateTestContext testContext, ITestOutputHelper testOutput) +[Collection(nameof(OracleGrateTestContext))] +public class Database(OracleGrateTestContext testContext, ITestOutputHelper testOutput) : GenericDatabase(testContext, testOutput); diff --git a/unittests/Oracle/DependencyInjection/ServiceCollectionTest.cs b/unittests/Oracle/DependencyInjection/ServiceCollectionTest.cs index f2531dfe..961cc4b4 100644 --- a/unittests/Oracle/DependencyInjection/ServiceCollectionTest.cs +++ b/unittests/Oracle/DependencyInjection/ServiceCollectionTest.cs @@ -1,12 +1,13 @@ using grate.Infrastructure; using grate.Oracle.Migration; +using Oracle.TestInfrastructure; using TestCommon.DependencyInjection; using TestCommon.TestInfrastructure; namespace Oracle.DependencyInjection; -[Collection(nameof(OracleTestContainerDatabase))] -public class ServiceCollectionTest(IGrateTestContext testContext) +[Collection(nameof(OracleGrateTestContext))] +public class ServiceCollectionTest(OracleGrateTestContext testContext) : GrateServiceCollectionTest(testContext) { protected virtual Type DatabaseType => typeof(OracleDatabase); diff --git a/unittests/Oracle/MigrationTables.cs b/unittests/Oracle/MigrationTables.cs index 3320e4ac..1be19465 100644 --- a/unittests/Oracle/MigrationTables.cs +++ b/unittests/Oracle/MigrationTables.cs @@ -1,11 +1,12 @@ using grate.Configuration; +using Oracle.TestInfrastructure; using TestCommon.Generic; using TestCommon.TestInfrastructure; namespace Oracle; -[Collection(nameof(OracleTestContainerDatabase))] -public class MigrationTables(IGrateTestContext testContext, ITestOutputHelper testOutput) +[Collection(nameof(OracleGrateTestContext))] +public class MigrationTables(OracleGrateTestContext testContext, ITestOutputHelper testOutput) : GenericMigrationTables(testContext, testOutput) { diff --git a/unittests/Oracle/Running_MigrationScripts/Anytime_scripts.cs b/unittests/Oracle/Running_MigrationScripts/Anytime_scripts.cs index aa2cb57a..7a4c4135 100644 --- a/unittests/Oracle/Running_MigrationScripts/Anytime_scripts.cs +++ b/unittests/Oracle/Running_MigrationScripts/Anytime_scripts.cs @@ -1,9 +1,10 @@ -using TestCommon.TestInfrastructure; +using Oracle.TestInfrastructure; +using TestCommon.TestInfrastructure; namespace Oracle.Running_MigrationScripts; -[Collection(nameof(OracleTestContainerDatabase))] +[Collection(nameof(OracleGrateTestContext))] // ReSharper disable once InconsistentNaming -public class Anytime_scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class Anytime_scripts(OracleGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.Anytime_scripts(testContext, testOutput); diff --git a/unittests/Oracle/Running_MigrationScripts/DropDatabase.cs b/unittests/Oracle/Running_MigrationScripts/DropDatabase.cs index 9b0f0c33..31b880fd 100644 --- a/unittests/Oracle/Running_MigrationScripts/DropDatabase.cs +++ b/unittests/Oracle/Running_MigrationScripts/DropDatabase.cs @@ -1,8 +1,9 @@ -using TestCommon.TestInfrastructure; +using Oracle.TestInfrastructure; +using TestCommon.TestInfrastructure; namespace Oracle.Running_MigrationScripts; // ReSharper disable once UnusedType.Global -[Collection(nameof(OracleTestContainerDatabase))] -public class DropDatabase(IGrateTestContext testContext, ITestOutputHelper testOutput) +[Collection(nameof(OracleGrateTestContext))] +public class DropDatabase(OracleGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.DropDatabase(testContext, testOutput); diff --git a/unittests/Oracle/Running_MigrationScripts/Environment_scripts.cs b/unittests/Oracle/Running_MigrationScripts/Environment_scripts.cs index ba2f5fe0..696dcdb2 100644 --- a/unittests/Oracle/Running_MigrationScripts/Environment_scripts.cs +++ b/unittests/Oracle/Running_MigrationScripts/Environment_scripts.cs @@ -1,9 +1,10 @@ -using TestCommon.TestInfrastructure; +using Oracle.TestInfrastructure; +using TestCommon.TestInfrastructure; namespace Oracle.Running_MigrationScripts; // ReSharper disable once UnusedType.Global -[Collection(nameof(OracleTestContainerDatabase))] -public class Environment_scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +[Collection(nameof(OracleGrateTestContext))] +public class Environment_scripts(OracleGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.Environment_scripts(testContext, testOutput); diff --git a/unittests/Oracle/Running_MigrationScripts/Everytime_scripts.cs b/unittests/Oracle/Running_MigrationScripts/Everytime_scripts.cs index 69b44690..0610f53c 100644 --- a/unittests/Oracle/Running_MigrationScripts/Everytime_scripts.cs +++ b/unittests/Oracle/Running_MigrationScripts/Everytime_scripts.cs @@ -1,8 +1,9 @@ -using TestCommon.TestInfrastructure; +using Oracle.TestInfrastructure; +using TestCommon.TestInfrastructure; namespace Oracle.Running_MigrationScripts; -[Collection(nameof(OracleTestContainerDatabase))] -public class Everytime_scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +[Collection(nameof(OracleGrateTestContext))] +public class Everytime_scripts(OracleGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.Everytime_scripts(testContext, testOutput); diff --git a/unittests/Oracle/Running_MigrationScripts/Failing_Scripts.cs b/unittests/Oracle/Running_MigrationScripts/Failing_Scripts.cs index c9e02d01..dcbc68f4 100644 --- a/unittests/Oracle/Running_MigrationScripts/Failing_Scripts.cs +++ b/unittests/Oracle/Running_MigrationScripts/Failing_Scripts.cs @@ -1,9 +1,10 @@ -using TestCommon.TestInfrastructure; +using Oracle.TestInfrastructure; +using TestCommon.TestInfrastructure; namespace Oracle.Running_MigrationScripts; -[Collection(nameof(OracleTestContainerDatabase))] -public class Failing_Scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +[Collection(nameof(OracleGrateTestContext))] +public class Failing_Scripts(OracleGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.Failing_Scripts(testContext, testOutput) { protected override string ExpectedErrorMessageForInvalidSql => diff --git a/unittests/Oracle/Running_MigrationScripts/One_time_scripts.cs b/unittests/Oracle/Running_MigrationScripts/One_time_scripts.cs index a8ae3bda..5ae77224 100644 --- a/unittests/Oracle/Running_MigrationScripts/One_time_scripts.cs +++ b/unittests/Oracle/Running_MigrationScripts/One_time_scripts.cs @@ -1,10 +1,11 @@ -using TestCommon.TestInfrastructure; +using Oracle.TestInfrastructure; +using TestCommon.TestInfrastructure; namespace Oracle.Running_MigrationScripts; -[Collection(nameof(OracleTestContainerDatabase))] -public class One_time_scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +[Collection(nameof(OracleGrateTestContext))] +public class One_time_scripts(OracleGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.One_time_scripts(testContext, testOutput) { protected override string CreateView1 => base.CreateView1 + " FROM DUAL"; diff --git a/unittests/Oracle/Running_MigrationScripts/Order_Of_Scripts.cs b/unittests/Oracle/Running_MigrationScripts/Order_Of_Scripts.cs index 88c2f733..84028391 100644 --- a/unittests/Oracle/Running_MigrationScripts/Order_Of_Scripts.cs +++ b/unittests/Oracle/Running_MigrationScripts/Order_Of_Scripts.cs @@ -1,7 +1,8 @@ -using TestCommon.TestInfrastructure; +using Oracle.TestInfrastructure; +using TestCommon.TestInfrastructure; namespace Oracle.Running_MigrationScripts; -[Collection(nameof(OracleTestContainerDatabase))] -public class Order_Of_Scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +[Collection(nameof(OracleGrateTestContext))] +public class Order_Of_Scripts(OracleGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.Order_Of_Scripts(testContext, testOutput); diff --git a/unittests/Oracle/Running_MigrationScripts/ScriptsRun_Table.cs b/unittests/Oracle/Running_MigrationScripts/ScriptsRun_Table.cs index a5d5c880..fda53c2f 100644 --- a/unittests/Oracle/Running_MigrationScripts/ScriptsRun_Table.cs +++ b/unittests/Oracle/Running_MigrationScripts/ScriptsRun_Table.cs @@ -1,7 +1,8 @@ -using TestCommon.TestInfrastructure; +using Oracle.TestInfrastructure; +using TestCommon.TestInfrastructure; namespace Oracle.Running_MigrationScripts; -[Collection(nameof(OracleTestContainerDatabase))] -public class ScriptsRun_Table(IGrateTestContext testContext, ITestOutputHelper testOutput) +[Collection(nameof(OracleGrateTestContext))] +public class ScriptsRun_Table(OracleGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.ScriptsRun_Table(testContext, testOutput); diff --git a/unittests/Oracle/Running_MigrationScripts/TokenScripts.cs b/unittests/Oracle/Running_MigrationScripts/TokenScripts.cs index 7b50ca62..d199ac0d 100644 --- a/unittests/Oracle/Running_MigrationScripts/TokenScripts.cs +++ b/unittests/Oracle/Running_MigrationScripts/TokenScripts.cs @@ -1,9 +1,10 @@ -using TestCommon.TestInfrastructure; +using Oracle.TestInfrastructure; +using TestCommon.TestInfrastructure; namespace Oracle.Running_MigrationScripts; -[Collection(nameof(OracleTestContainerDatabase))] -public class TokenScripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +[Collection(nameof(OracleGrateTestContext))] +public class TokenScripts(OracleGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.TokenScripts(testContext, testOutput) { protected override string CreateDatabaseName => base.CreateDatabaseName + " FROM DUAL"; diff --git a/unittests/Oracle/Running_MigrationScripts/Versioning_The_Database.cs b/unittests/Oracle/Running_MigrationScripts/Versioning_The_Database.cs index 4bb951e6..b315092b 100644 --- a/unittests/Oracle/Running_MigrationScripts/Versioning_The_Database.cs +++ b/unittests/Oracle/Running_MigrationScripts/Versioning_The_Database.cs @@ -1,11 +1,12 @@ -using TestCommon.TestInfrastructure; +using Oracle.TestInfrastructure; +using TestCommon.TestInfrastructure; namespace Oracle.Running_MigrationScripts; -[Collection(nameof(OracleTestContainerDatabase))] +[Collection(nameof(OracleGrateTestContext))] // ReSharper disable once InconsistentNaming // ReSharper disable once UnusedType.Global -public class Versioning_The_Database(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class Versioning_The_Database(OracleGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.Versioning_The_Database(testContext, testOutput) { [Fact(Skip = "Skip due to Oracle doesn't support dynamic database creation in runtime")] diff --git a/unittests/Oracle/TestInfrastructure/OracleTestContainerDatabase.cs b/unittests/Oracle/TestInfrastructure/OracleTestContainerDatabase.cs index 7a58c519..84abcbc8 100644 --- a/unittests/Oracle/TestInfrastructure/OracleTestContainerDatabase.cs +++ b/unittests/Oracle/TestInfrastructure/OracleTestContainerDatabase.cs @@ -17,7 +17,7 @@ protected override OracleContainer InitializeTestContainer() .WithImage(DockerImage) .WithEnvironment("DOCKER_DEFAULT_PLATFORM", "linux/amd64") .WithPassword(AdminPassword) - .WithPortBinding(Port, true) + .WithPortBinding(InternalPort, true) .Build(); } diff --git a/unittests/PostgreSQL/Database.cs b/unittests/PostgreSQL/Database.cs index 70def1ab..8354f9d0 100644 --- a/unittests/PostgreSQL/Database.cs +++ b/unittests/PostgreSQL/Database.cs @@ -1,8 +1,9 @@ -using TestCommon.Generic; +using PostgreSQL.TestInfrastructure; +using TestCommon.Generic; using TestCommon.TestInfrastructure; namespace PostgreSQL; -[Collection(nameof(PostgreSqlTestContainer))] -public class Database(IGrateTestContext testContext, ITestOutputHelper testOutput) : +[Collection(nameof(PostgreSqlGrateTestContext))] +public class Database(PostgreSqlGrateTestContext testContext, ITestOutputHelper testOutput) : GenericDatabase(testContext, testOutput); diff --git a/unittests/PostgreSQL/DependencyInjection/ServiceCollectionTest.cs b/unittests/PostgreSQL/DependencyInjection/ServiceCollectionTest.cs index 36443175..e2cc7b3a 100644 --- a/unittests/PostgreSQL/DependencyInjection/ServiceCollectionTest.cs +++ b/unittests/PostgreSQL/DependencyInjection/ServiceCollectionTest.cs @@ -1,7 +1,8 @@ -using TestCommon.TestInfrastructure; +using PostgreSQL.TestInfrastructure; +using TestCommon.TestInfrastructure; namespace PostgreSQL.DependencyInjection; -[Collection(nameof(PostgreSqlTestContainer))] -public class ServiceCollectionTest(IGrateTestContext context) +[Collection(nameof(PostgreSqlGrateTestContext))] +public class ServiceCollectionTest(PostgreSqlGrateTestContext context) : TestCommon.DependencyInjection.GrateServiceCollectionTest(context); diff --git a/unittests/PostgreSQL/MigrationTables.cs b/unittests/PostgreSQL/MigrationTables.cs index 721416d0..dbd5c2d4 100644 --- a/unittests/PostgreSQL/MigrationTables.cs +++ b/unittests/PostgreSQL/MigrationTables.cs @@ -1,8 +1,9 @@ -using TestCommon.Generic; +using PostgreSQL.TestInfrastructure; +using TestCommon.Generic; using TestCommon.TestInfrastructure; namespace PostgreSQL; -[Collection(nameof(PostgreSqlTestContainer))] -public class MigrationTables(IGrateTestContext testContext, ITestOutputHelper testOutput) : +[Collection(nameof(PostgreSqlGrateTestContext))] +public class MigrationTables(PostgreSqlGrateTestContext testContext, ITestOutputHelper testOutput) : GenericMigrationTables(testContext, testOutput); diff --git a/unittests/PostgreSQL/Running_MigrationScripts/Anytime_scripts.cs b/unittests/PostgreSQL/Running_MigrationScripts/Anytime_scripts.cs index d3ff7f98..b396218e 100644 --- a/unittests/PostgreSQL/Running_MigrationScripts/Anytime_scripts.cs +++ b/unittests/PostgreSQL/Running_MigrationScripts/Anytime_scripts.cs @@ -1,9 +1,10 @@ -using TestCommon.TestInfrastructure; +using PostgreSQL.TestInfrastructure; +using TestCommon.TestInfrastructure; namespace PostgreSQL.Running_MigrationScripts; -[Collection(nameof(PostgreSqlTestContainer))] +[Collection(nameof(PostgreSqlGrateTestContext))] // ReSharper disable once InconsistentNaming // ReSharper disable once UnusedType.Global -public class Anytime_scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class Anytime_scripts(PostgreSqlGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.Anytime_scripts(testContext, testOutput); diff --git a/unittests/PostgreSQL/Running_MigrationScripts/DropDatabase.cs b/unittests/PostgreSQL/Running_MigrationScripts/DropDatabase.cs index 5cd8d17d..61452119 100644 --- a/unittests/PostgreSQL/Running_MigrationScripts/DropDatabase.cs +++ b/unittests/PostgreSQL/Running_MigrationScripts/DropDatabase.cs @@ -1,7 +1,8 @@ -using TestCommon.TestInfrastructure; +using PostgreSQL.TestInfrastructure; +using TestCommon.TestInfrastructure; namespace PostgreSQL.Running_MigrationScripts; -[Collection(nameof(PostgreSqlTestContainer))] -public class DropDatabase(IGrateTestContext testContext, ITestOutputHelper testOutput) +[Collection(nameof(PostgreSqlGrateTestContext))] +public class DropDatabase(PostgreSqlGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.DropDatabase(testContext, testOutput); diff --git a/unittests/PostgreSQL/Running_MigrationScripts/Environment_scripts.cs b/unittests/PostgreSQL/Running_MigrationScripts/Environment_scripts.cs index 1837e178..8956ba63 100644 --- a/unittests/PostgreSQL/Running_MigrationScripts/Environment_scripts.cs +++ b/unittests/PostgreSQL/Running_MigrationScripts/Environment_scripts.cs @@ -1,9 +1,10 @@ -using TestCommon.TestInfrastructure; +using PostgreSQL.TestInfrastructure; +using TestCommon.TestInfrastructure; namespace PostgreSQL.Running_MigrationScripts; -[Collection(nameof(PostgreSqlTestContainer))] +[Collection(nameof(PostgreSqlGrateTestContext))] // ReSharper disable once InconsistentNaming -public class Environment_scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class Environment_scripts(PostgreSqlGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.Environment_scripts(testContext, testOutput); diff --git a/unittests/PostgreSQL/Running_MigrationScripts/Everytime_scripts.cs b/unittests/PostgreSQL/Running_MigrationScripts/Everytime_scripts.cs index a8cc08c1..38387203 100644 --- a/unittests/PostgreSQL/Running_MigrationScripts/Everytime_scripts.cs +++ b/unittests/PostgreSQL/Running_MigrationScripts/Everytime_scripts.cs @@ -1,14 +1,15 @@ using Dapper; using FluentAssertions; using grate.Configuration; +using PostgreSQL.TestInfrastructure; using TestCommon.TestInfrastructure; using static grate.Configuration.KnownFolderKeys; namespace PostgreSQL.Running_MigrationScripts; -[Collection(nameof(PostgreSqlTestContainer))] +[Collection(nameof(PostgreSqlGrateTestContext))] // ReSharper disable once InconsistentNaming -public class Everytime_scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class Everytime_scripts(PostgreSqlGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.Everytime_scripts(testContext, testOutput) { [Fact] diff --git a/unittests/PostgreSQL/Running_MigrationScripts/Failing_Scripts.cs b/unittests/PostgreSQL/Running_MigrationScripts/Failing_Scripts.cs index fc8043cd..479ddc3d 100644 --- a/unittests/PostgreSQL/Running_MigrationScripts/Failing_Scripts.cs +++ b/unittests/PostgreSQL/Running_MigrationScripts/Failing_Scripts.cs @@ -1,10 +1,11 @@ -using TestCommon.TestInfrastructure; +using PostgreSQL.TestInfrastructure; +using TestCommon.TestInfrastructure; namespace PostgreSQL.Running_MigrationScripts; -[Collection(nameof(PostgreSqlTestContainer))] +[Collection(nameof(PostgreSqlGrateTestContext))] // ReSharper disable once InconsistentNaming -public class Failing_Scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class Failing_Scripts(PostgreSqlGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.Failing_Scripts(testContext, testOutput) { diff --git a/unittests/PostgreSQL/Running_MigrationScripts/One_time_scripts.cs b/unittests/PostgreSQL/Running_MigrationScripts/One_time_scripts.cs index c44a93dd..6222e94d 100644 --- a/unittests/PostgreSQL/Running_MigrationScripts/One_time_scripts.cs +++ b/unittests/PostgreSQL/Running_MigrationScripts/One_time_scripts.cs @@ -1,8 +1,9 @@ -using TestCommon.TestInfrastructure; +using PostgreSQL.TestInfrastructure; +using TestCommon.TestInfrastructure; namespace PostgreSQL.Running_MigrationScripts; -[Collection(nameof(PostgreSqlTestContainer))] +[Collection(nameof(PostgreSqlGrateTestContext))] // ReSharper disable once InconsistentNaming -public class One_time_scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class One_time_scripts(PostgreSqlGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.One_time_scripts(testContext, testOutput); diff --git a/unittests/PostgreSQL/Running_MigrationScripts/Order_Of_Scripts.cs b/unittests/PostgreSQL/Running_MigrationScripts/Order_Of_Scripts.cs index 387bbb8b..6cb20411 100644 --- a/unittests/PostgreSQL/Running_MigrationScripts/Order_Of_Scripts.cs +++ b/unittests/PostgreSQL/Running_MigrationScripts/Order_Of_Scripts.cs @@ -1,8 +1,9 @@ -using TestCommon.TestInfrastructure; +using PostgreSQL.TestInfrastructure; +using TestCommon.TestInfrastructure; namespace PostgreSQL.Running_MigrationScripts; -[Collection(nameof(PostgreSqlTestContainer))] +[Collection(nameof(PostgreSqlGrateTestContext))] // ReSharper disable once InconsistentNaming -public class Order_Of_Scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class Order_Of_Scripts(PostgreSqlGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.Order_Of_Scripts(testContext, testOutput); diff --git a/unittests/PostgreSQL/Running_MigrationScripts/ScriptsRun_Table.cs b/unittests/PostgreSQL/Running_MigrationScripts/ScriptsRun_Table.cs index 4612b74d..ed76e7c8 100644 --- a/unittests/PostgreSQL/Running_MigrationScripts/ScriptsRun_Table.cs +++ b/unittests/PostgreSQL/Running_MigrationScripts/ScriptsRun_Table.cs @@ -1,8 +1,9 @@ -using TestCommon.TestInfrastructure; +using PostgreSQL.TestInfrastructure; +using TestCommon.TestInfrastructure; namespace PostgreSQL.Running_MigrationScripts; -[Collection(nameof(PostgreSqlTestContainer))] -public class ScriptsRun_Table(IGrateTestContext testContext, ITestOutputHelper testOutput) +[Collection(nameof(PostgreSqlGrateTestContext))] +public class ScriptsRun_Table(PostgreSqlGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.ScriptsRun_Table(testContext, testOutput); diff --git a/unittests/PostgreSQL/Running_MigrationScripts/TokenScripts.cs b/unittests/PostgreSQL/Running_MigrationScripts/TokenScripts.cs index b0a28de8..e16bf4f8 100644 --- a/unittests/PostgreSQL/Running_MigrationScripts/TokenScripts.cs +++ b/unittests/PostgreSQL/Running_MigrationScripts/TokenScripts.cs @@ -1,8 +1,9 @@ -using TestCommon.TestInfrastructure; +using PostgreSQL.TestInfrastructure; +using TestCommon.TestInfrastructure; namespace PostgreSQL.Running_MigrationScripts; -[Collection(nameof(PostgreSqlTestContainer))] -public class TokenScripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +[Collection(nameof(PostgreSqlGrateTestContext))] +public class TokenScripts(PostgreSqlGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.TokenScripts(testContext, testOutput); diff --git a/unittests/PostgreSQL/Running_MigrationScripts/Versioning_The_Database.cs b/unittests/PostgreSQL/Running_MigrationScripts/Versioning_The_Database.cs index e38e5a30..ca56dbd8 100644 --- a/unittests/PostgreSQL/Running_MigrationScripts/Versioning_The_Database.cs +++ b/unittests/PostgreSQL/Running_MigrationScripts/Versioning_The_Database.cs @@ -1,8 +1,9 @@ +using PostgreSQL.TestInfrastructure; using TestCommon.TestInfrastructure; namespace PostgreSQL.Running_MigrationScripts; -[Collection(nameof(PostgreSqlTestContainer))] +[Collection(nameof(PostgreSqlGrateTestContext))] // ReSharper disable once InconsistentNaming -public class Versioning_The_Database(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class Versioning_The_Database(PostgreSqlGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.Versioning_The_Database(testContext, testOutput); diff --git a/unittests/PostgreSQL/Startup.cs b/unittests/PostgreSQL/Startup.cs index b16d0735..cbda6c44 100644 --- a/unittests/PostgreSQL/Startup.cs +++ b/unittests/PostgreSQL/Startup.cs @@ -1,34 +1,19 @@ using grate.DependencyInjection; using grate.postgresql.DependencyInjection; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; using PostgreSQL.TestInfrastructure; using TestCommon.TestInfrastructure; namespace PostgreSQL; // ReSharper disable once UnusedType.Global -public class Startup +public class Startup: TestCommon.Startup { - - // ReSharper disable once UnusedMember.Global - public void ConfigureServices(IServiceCollection services, HostBuilderContext context) + protected override void ConfigureExtraServices(IServiceCollection services, HostBuilderContext context) { - services.AddLogging( - lb => lb - .AddXUnit() - .AddConsole() - .SetMinimumLevel(TestConfig.GetLogLevel()) - ); - services .AddGrate() .UsePostgreSQL(); - - services.TryAddSingleton(); - services.TryAddTransient(); } - } diff --git a/unittests/PostgreSQL/TestInfrastructure/PostgreSqlExternalDatabase.cs b/unittests/PostgreSQL/TestInfrastructure/PostgreSqlExternalDatabase.cs new file mode 100644 index 00000000..96f1d1eb --- /dev/null +++ b/unittests/PostgreSQL/TestInfrastructure/PostgreSqlExternalDatabase.cs @@ -0,0 +1,33 @@ +using Npgsql; +using TestCommon.TestInfrastructure; + +namespace PostgreSQL.TestInfrastructure; + +// ReSharper disable once ClassNeverInstantiated.Global +public class PostgreSqlExternalDatabase(GrateTestConfig grateTestConfig) : ITestDatabase +{ + public string AdminConnectionString { get; } = grateTestConfig.AdminConnectionString ?? throw new ArgumentNullException(nameof(grateTestConfig)); + + public string ConnectionString(string database) + { + var builder = new NpgsqlConnectionStringBuilder(AdminConnectionString) + { + Database = database, + Timeout = 2 + }; + return builder.ConnectionString; + } + + public string UserConnectionString(string database) + { + var builder = new NpgsqlConnectionStringBuilder(AdminConnectionString) + { + Database = database, + Username = "zorro", + Password = "batmanZZ4", + Timeout = 2 + }; + return builder.ConnectionString; + } + +} diff --git a/unittests/PostgreSQL/TestInfrastructure/PostgreSqlGrateTestContext.cs b/unittests/PostgreSQL/TestInfrastructure/PostgreSqlGrateTestContext.cs index 298e7bcb..6fb48c75 100644 --- a/unittests/PostgreSQL/TestInfrastructure/PostgreSqlGrateTestContext.cs +++ b/unittests/PostgreSQL/TestInfrastructure/PostgreSqlGrateTestContext.cs @@ -8,51 +8,37 @@ namespace PostgreSQL.TestInfrastructure; -public class PostgreSqlGrateTestContext : IGrateTestContext -{ - private readonly PostgreSqlTestContainer _testContainer; +[CollectionDefinition(nameof(PostgreSqlGrateTestContext))] +public class PostgresqlTestCollection : ICollectionFixture; + +public class PostgreSqlGrateTestContext : GrateTestContext +{ public PostgreSqlGrateTestContext( IGrateMigrator migrator, - PostgreSqlTestContainer container) + ITestDatabase testDatabase) : base(testDatabase) { - _testContainer = container; Migrator = migrator; } - public IGrateMigrator Migrator { get; } - - private string AdminPassword => _testContainer.AdminPassword; - private int? Port => _testContainer.TestContainer.GetMappedPublicPort(_testContainer.Port); - private string Hostname => _testContainer.TestContainer.Hostname; - - - public string AdminConnectionString => - $"Host={Hostname};Port={Port};Database=postgres;Username=postgres;Password={AdminPassword};Include Error Detail=true;Pooling=false"; - - - public string ConnectionString(string database) => - $"Host={_testContainer.TestContainer!.Hostname};Port={Port};Database={database};Username=postgres;Password={AdminPassword};Include Error Detail=true;Pooling=false"; - - public string UserConnectionString(string database) => - $"Host={_testContainer.TestContainer!.Hostname};Port={Port};Database={database};Username=postgres;Password={AdminPassword};Include Error Detail=true;Pooling=false"; - - public IDbConnection GetDbConnection(string connectionString) => new NpgsqlConnection(connectionString); + public override IGrateMigrator Migrator { get; } + + public override IDbConnection GetDbConnection(string connectionString) => new NpgsqlConnection(connectionString); - public ISyntax Syntax => new PostgreSqlSyntax(); - public Type DbExceptionType => typeof(PostgresException); + public override ISyntax Syntax => new PostgreSqlSyntax(); + public override Type DbExceptionType => typeof(PostgresException); - public Type DatabaseType => typeof(PostgreSqlDatabase); - public bool SupportsTransaction => true; + public override Type DatabaseType => typeof(PostgreSqlDatabase); + public override bool SupportsTransaction => true; - public SqlStatements Sql => new() + public override SqlStatements Sql => new() { SelectVersion = "SELECT version()", SleepTwoSeconds = "SELECT pg_sleep(2);" }; - public string ExpectedVersionPrefix => "PostgreSQL 16."; - public bool SupportsCreateDatabase => true; - public bool SupportsSchemas => true; + public override string ExpectedVersionPrefix => "PostgreSQL 16."; + public override bool SupportsCreateDatabase => true; + public override bool SupportsSchemas => true; } diff --git a/unittests/PostgreSQL/TestInfrastructure/PostgreSqlTestContainer.cs b/unittests/PostgreSQL/TestInfrastructure/PostgreSqlTestContainer.cs deleted file mode 100644 index a06d02a0..00000000 --- a/unittests/PostgreSQL/TestInfrastructure/PostgreSqlTestContainer.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Microsoft.Extensions.Logging; - -namespace TestCommon.TestInfrastructure; -public class PostgreSqlTestContainer : TestContainerDatabase -{ - public override string DockerImage => "postgres:16"; - public override int Port => 5432; - - public PostgreSqlTestContainer(ILogger logger) : base(logger) - { - } - - protected override PostgreSqlContainer InitializeTestContainer() - { - return new PostgreSqlBuilder() - .WithImage(DockerImage) - .WithPassword(AdminPassword) - .WithPortBinding(Port, true) - .Build(); - } -} - -[CollectionDefinition(nameof(PostgreSqlTestContainer))] -public class PostgresqlTestCollection : ICollectionFixture -{ -} diff --git a/unittests/PostgreSQL/TestInfrastructure/PostgreSqlTestContainerDatabase.cs b/unittests/PostgreSQL/TestInfrastructure/PostgreSqlTestContainerDatabase.cs new file mode 100644 index 00000000..4a99409b --- /dev/null +++ b/unittests/PostgreSQL/TestInfrastructure/PostgreSqlTestContainerDatabase.cs @@ -0,0 +1,34 @@ +using Microsoft.Extensions.Logging; + +namespace TestCommon.TestInfrastructure; +public class PostgreSqlTestContainerDatabase : TestContainerDatabase +{ + public override string DockerImage => "postgres:16"; + protected override int InternalPort => 5432; + + public PostgreSqlTestContainerDatabase(ILogger logger) : base(logger) + { + } + + protected override PostgreSqlContainer InitializeTestContainer() + { + return new PostgreSqlBuilder() + .WithImage(DockerImage) + .WithPassword(AdminPassword) + .WithPortBinding(InternalPort, true) + .Build(); + } + + public override string AdminConnectionString => + $"Host={TestContainer.Hostname};Port={Port};Database=postgres;Username=postgres;Password={AdminPassword};Include Error Detail=true;Pooling=false"; + + + public override string ConnectionString(string database) => + $"Host={TestContainer.Hostname};Port={Port};Database={database};Username=postgres;Password={AdminPassword};Include Error Detail=true;Pooling=false"; + + public override string UserConnectionString(string database) => + $"Host={TestContainer.Hostname};Port={Port};Database={database};Username=postgres;Password={AdminPassword};Include Error Detail=true;Pooling=false"; + + +} + diff --git a/unittests/SqlServer/Startup.cs b/unittests/SqlServer/Startup.cs index c6ccb5a2..eef4fe45 100644 --- a/unittests/SqlServer/Startup.cs +++ b/unittests/SqlServer/Startup.cs @@ -1,6 +1,7 @@ using grate.DependencyInjection; using grate.sqlserver.DependencyInjection; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Hosting; using SqlServer.TestInfrastructure; @@ -14,5 +15,7 @@ protected override void ConfigureExtraServices(IServiceCollection services, Host services .AddGrate() .UseSqlServer(); + + services.TryAddTransient(); } } diff --git a/unittests/Sqlite/Database.cs b/unittests/Sqlite/Database.cs index ff8ef914..63653cbe 100644 --- a/unittests/Sqlite/Database.cs +++ b/unittests/Sqlite/Database.cs @@ -4,10 +4,10 @@ namespace Sqlite; -[Collection(nameof(SqliteTestContainerDatabase))] +[Collection(nameof(SqliteTestDatabase))] // ReSharper disable once InconsistentNaming // ReSharper disable once UnusedType.Global -public class Database(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class Database(SqliteGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.GenericDatabase(testContext, testOutput) { diff --git a/unittests/Sqlite/DependencyInjection/ServiceCollectionTest.cs b/unittests/Sqlite/DependencyInjection/ServiceCollectionTest.cs index ceee1739..acff87ff 100644 --- a/unittests/Sqlite/DependencyInjection/ServiceCollectionTest.cs +++ b/unittests/Sqlite/DependencyInjection/ServiceCollectionTest.cs @@ -1,9 +1,10 @@ using grate.Infrastructure; using grate.Sqlite.Migration; +using Sqlite.TestInfrastructure; using TestCommon.TestInfrastructure; namespace Sqlite.DependencyInjection; -public class ServiceCollectionTest(IGrateTestContext context) : TestCommon.DependencyInjection.GrateServiceCollectionTest(context) +public class ServiceCollectionTest(SqliteGrateTestContext context) : TestCommon.DependencyInjection.GrateServiceCollectionTest(context) { protected virtual Type DatabaseType => typeof(SqliteDatabase); protected virtual ISyntax Syntax => SqliteDatabase.Syntax; diff --git a/unittests/Sqlite/MigrationTables.cs b/unittests/Sqlite/MigrationTables.cs index a8e1962a..ded0ccaf 100644 --- a/unittests/Sqlite/MigrationTables.cs +++ b/unittests/Sqlite/MigrationTables.cs @@ -3,10 +3,10 @@ namespace Sqlite; -[Collection(nameof(SqliteTestContainerDatabase))] +[Collection(nameof(SqliteTestDatabase))] // ReSharper disable once InconsistentNaming // ReSharper disable once UnusedType.Global -public class MigrationTables(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class MigrationTables(SqliteGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.GenericMigrationTables(testContext, testOutput) { diff --git a/unittests/Sqlite/Running_MigrationScripts/Anytime_scripts.cs b/unittests/Sqlite/Running_MigrationScripts/Anytime_scripts.cs index 53613541..047cc9e6 100644 --- a/unittests/Sqlite/Running_MigrationScripts/Anytime_scripts.cs +++ b/unittests/Sqlite/Running_MigrationScripts/Anytime_scripts.cs @@ -4,8 +4,8 @@ namespace Sqlite.Running_MigrationScripts; -[Collection(nameof(SqliteTestContainerDatabase))] +[Collection(nameof(SqliteTestDatabase))] // ReSharper disable once InconsistentNaming // ReSharper disable once UnusedType.Global -public class Anytime_scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class Anytime_scripts(SqliteGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.Anytime_scripts(testContext, testOutput); diff --git a/unittests/Sqlite/Running_MigrationScripts/DropDatabase.cs b/unittests/Sqlite/Running_MigrationScripts/DropDatabase.cs index a792fa9e..4b26114e 100644 --- a/unittests/Sqlite/Running_MigrationScripts/DropDatabase.cs +++ b/unittests/Sqlite/Running_MigrationScripts/DropDatabase.cs @@ -3,8 +3,8 @@ namespace Sqlite.Running_MigrationScripts; -[Collection(nameof(SqliteTestContainerDatabase))] +[Collection(nameof(SqliteTestDatabase))] // ReSharper disable once InconsistentNaming // ReSharper disable once UnusedType.Global -public class DropDatabase(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class DropDatabase(SqliteGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.DropDatabase(testContext, testOutput); diff --git a/unittests/Sqlite/Running_MigrationScripts/Environment_scripts.cs b/unittests/Sqlite/Running_MigrationScripts/Environment_scripts.cs index 870b620b..973d0cc4 100644 --- a/unittests/Sqlite/Running_MigrationScripts/Environment_scripts.cs +++ b/unittests/Sqlite/Running_MigrationScripts/Environment_scripts.cs @@ -3,9 +3,9 @@ namespace Sqlite.Running_MigrationScripts; -[Collection(nameof(SqliteTestContainerDatabase))] +[Collection(nameof(SqliteTestDatabase))] // ReSharper disable once InconsistentNaming // ReSharper disable once UnusedType.Global -public class Environment_scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class Environment_scripts(SqliteGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.Environment_scripts(testContext, testOutput); diff --git a/unittests/Sqlite/Running_MigrationScripts/Everytime_scripts.cs b/unittests/Sqlite/Running_MigrationScripts/Everytime_scripts.cs index 577eb932..adb67d2a 100644 --- a/unittests/Sqlite/Running_MigrationScripts/Everytime_scripts.cs +++ b/unittests/Sqlite/Running_MigrationScripts/Everytime_scripts.cs @@ -3,8 +3,8 @@ namespace Sqlite.Running_MigrationScripts; -[Collection(nameof(SqliteTestContainerDatabase))] +[Collection(nameof(SqliteTestDatabase))] // ReSharper disable once InconsistentNaming // ReSharper disable once UnusedType.Global -public class Everytime_scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class Everytime_scripts(SqliteGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.Everytime_scripts(testContext, testOutput); diff --git a/unittests/Sqlite/Running_MigrationScripts/Failing_Scripts.cs b/unittests/Sqlite/Running_MigrationScripts/Failing_Scripts.cs index d434a767..b65d6c94 100644 --- a/unittests/Sqlite/Running_MigrationScripts/Failing_Scripts.cs +++ b/unittests/Sqlite/Running_MigrationScripts/Failing_Scripts.cs @@ -3,10 +3,10 @@ namespace Sqlite.Running_MigrationScripts; -[Collection(nameof(SqliteTestContainerDatabase))] +[Collection(nameof(SqliteTestDatabase))] // ReSharper disable once InconsistentNaming // ReSharper disable once UnusedType.Global -public class Failing_Scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class Failing_Scripts(SqliteGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.Failing_Scripts(testContext, testOutput) { protected override string ExpectedErrorMessageForInvalidSql => diff --git a/unittests/Sqlite/Running_MigrationScripts/One_time_scripts.cs b/unittests/Sqlite/Running_MigrationScripts/One_time_scripts.cs index 944c70ba..c8970ae6 100644 --- a/unittests/Sqlite/Running_MigrationScripts/One_time_scripts.cs +++ b/unittests/Sqlite/Running_MigrationScripts/One_time_scripts.cs @@ -3,8 +3,8 @@ namespace Sqlite.Running_MigrationScripts; -[Collection(nameof(SqliteTestContainerDatabase))] +[Collection(nameof(SqliteTestDatabase))] // ReSharper disable once InconsistentNaming // ReSharper disable once UnusedType.Global -public class One_time_scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class One_time_scripts(SqliteGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.One_time_scripts(testContext, testOutput); diff --git a/unittests/Sqlite/Running_MigrationScripts/Order_Of_Scripts.cs b/unittests/Sqlite/Running_MigrationScripts/Order_Of_Scripts.cs index f1016c75..ff234fe8 100644 --- a/unittests/Sqlite/Running_MigrationScripts/Order_Of_Scripts.cs +++ b/unittests/Sqlite/Running_MigrationScripts/Order_Of_Scripts.cs @@ -3,8 +3,8 @@ namespace Sqlite.Running_MigrationScripts; -[Collection(nameof(SqliteTestContainerDatabase))] +[Collection(nameof(SqliteTestDatabase))] // ReSharper disable once InconsistentNaming // ReSharper disable once UnusedType.Global -public class Order_Of_Scripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class Order_Of_Scripts(SqliteGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.Order_Of_Scripts(testContext, testOutput); diff --git a/unittests/Sqlite/Running_MigrationScripts/ScriptsRun_Table.cs b/unittests/Sqlite/Running_MigrationScripts/ScriptsRun_Table.cs index f5e3c85d..11a266d6 100644 --- a/unittests/Sqlite/Running_MigrationScripts/ScriptsRun_Table.cs +++ b/unittests/Sqlite/Running_MigrationScripts/ScriptsRun_Table.cs @@ -3,9 +3,9 @@ namespace Sqlite.Running_MigrationScripts; -[Collection(nameof(SqliteTestContainerDatabase))] +[Collection(nameof(SqliteTestDatabase))] // ReSharper disable once InconsistentNaming // ReSharper disable once UnusedType.Global -public class ScriptsRun_Table(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class ScriptsRun_Table(SqliteGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.ScriptsRun_Table(testContext, testOutput); diff --git a/unittests/Sqlite/Running_MigrationScripts/TokenScripts.cs b/unittests/Sqlite/Running_MigrationScripts/TokenScripts.cs index 4f42b483..c391ecc1 100644 --- a/unittests/Sqlite/Running_MigrationScripts/TokenScripts.cs +++ b/unittests/Sqlite/Running_MigrationScripts/TokenScripts.cs @@ -3,9 +3,9 @@ namespace Sqlite.Running_MigrationScripts; -[Collection(nameof(SqliteTestContainerDatabase))] +[Collection(nameof(SqliteTestDatabase))] // ReSharper disable once InconsistentNaming // ReSharper disable once UnusedType.Global -public class TokenScripts(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class TokenScripts(SqliteGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.TokenScripts(testContext, testOutput); diff --git a/unittests/Sqlite/Running_MigrationScripts/Versioning_The_Database.cs b/unittests/Sqlite/Running_MigrationScripts/Versioning_The_Database.cs index 96283e0f..a22275e8 100644 --- a/unittests/Sqlite/Running_MigrationScripts/Versioning_The_Database.cs +++ b/unittests/Sqlite/Running_MigrationScripts/Versioning_The_Database.cs @@ -4,9 +4,9 @@ namespace Sqlite.Running_MigrationScripts; -[Collection(nameof(SqliteTestContainerDatabase))] +[Collection(nameof(SqliteTestDatabase))] // ReSharper disable once InconsistentNaming // ReSharper disable once UnusedType.Global -public class Versioning_The_Database(IGrateTestContext testContext, ITestOutputHelper testOutput) +public class Versioning_The_Database(SqliteGrateTestContext testContext, ITestOutputHelper testOutput) : TestCommon.Generic.Running_MigrationScripts.Versioning_The_Database(testContext, testOutput); diff --git a/unittests/Sqlite/Startup.cs b/unittests/Sqlite/Startup.cs index de0b793d..c35676f5 100644 --- a/unittests/Sqlite/Startup.cs +++ b/unittests/Sqlite/Startup.cs @@ -1,39 +1,19 @@ -using grate.Configuration; using grate.DependencyInjection; -using grate.Infrastructure; -using grate.Migration; using grate.sqlite.DependencyInjection; -using grate.Sqlite.Infrastructure; -using grate.Sqlite.Migration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; using Sqlite.TestInfrastructure; using TestCommon.TestInfrastructure; namespace Sqlite; // ReSharper disable once UnusedType.Global -public class Startup +public class Startup: TestCommon.Startup { - - // ReSharper disable once UnusedMember.Global - public void ConfigureServices(IServiceCollection services, HostBuilderContext context) + protected override void ConfigureExtraServices(IServiceCollection services, HostBuilderContext context) { - services.AddLogging( - lb => lb - .AddXUnit() - .AddConsole() - .SetMinimumLevel(TestConfig.GetLogLevel()) - ); - services .AddGrate() .UseSqlite(); - - services.TryAddSingleton(); - services.TryAddTransient(); } - } diff --git a/unittests/Sqlite/TestInfrastructure/SqliteExternalDatabase.cs b/unittests/Sqlite/TestInfrastructure/SqliteExternalDatabase.cs new file mode 100644 index 00000000..ab0d41a6 --- /dev/null +++ b/unittests/Sqlite/TestInfrastructure/SqliteExternalDatabase.cs @@ -0,0 +1,84 @@ +// using Microsoft.Data.Sqlite; +// using Xunit.Sdk; +// namespace TestCommon.TestInfrastructure; +// public class SqliteExternalDatabase(GrateTestConfig grateTestConfig) : ITestDatabase +// { +// public string AdminConnectionString { get; } = grateTestConfig.AdminConnectionString ?? throw new ArgumentNullException(nameof(grateTestConfig)); +// +// public string ConnectionString(string database) +// { +// var builder = new SqliteConnectionStringBuilder(AdminConnectionString) +// { +// DataSource = $"{database}.db", +// DefaultTimeout = 2 +// }; +// return builder.ConnectionString; +// } +// +// public string UserConnectionString(string database) +// { +// var builder = new SqliteConnectionStringBuilder(AdminConnectionString) +// { +// DataSource = $"{database}.db", +// DefaultTimeout = 2 +// }; +// return builder.ConnectionString; +// } +// +// private readonly IMessageSink _messageSink; +// +// public SqliteExternalDatabase(IMessageSink messageSink) +// { +// _messageSink = messageSink; +// } +// public Task DisposeAsync() +// { +// SqliteConnection.ClearAllPools(); +// +// var currentDirectory = Directory.GetCurrentDirectory(); +// var dbFiles = Directory.GetFiles(currentDirectory, "*.db"); +// var message = new DiagnosticMessage("After tests. Deleting DB files."); +// _messageSink.OnMessage(message); +// foreach (var dbFile in dbFiles) +// { +// var deleteMessage = new DiagnosticMessage("File: {0}", dbFile); +// _messageSink.OnMessage(deleteMessage); +// File.Delete(dbFile); +// } +// return Task.CompletedTask; +// } +// +// public Task InitializeAsync() +// { +// var currentDirectory = Directory.GetCurrentDirectory(); +// var dbFiles = Directory.GetFiles(currentDirectory, "*.db"); +// var message = new DiagnosticMessage("Before tests. Deleting old DB files."); +// _messageSink.OnMessage(message); +// foreach (var dbFile in dbFiles) +// { +// TryDeletingFile(dbFile); +// } +// return Task.CompletedTask; +// } +// private void TryDeletingFile(string dbFile) +// { +// var i = 0; +// var sleepTime = 300; +// const int maxTries = 5; +// while (i++ < maxTries) +// { +// try +// { +// var message = new DiagnosticMessage("File: {0}", dbFile); +// _messageSink.OnMessage(message); +// File.Delete(dbFile); +// return; +// } +// catch (IOException) when (i <= maxTries) +// { +// Thread.Sleep(sleepTime); +// } +// } +// } +// +// } diff --git a/unittests/Sqlite/TestInfrastructure/SqliteGrateTestContext.cs b/unittests/Sqlite/TestInfrastructure/SqliteGrateTestContext.cs index b95c22f0..f1302763 100644 --- a/unittests/Sqlite/TestInfrastructure/SqliteGrateTestContext.cs +++ b/unittests/Sqlite/TestInfrastructure/SqliteGrateTestContext.cs @@ -17,14 +17,11 @@ public class SqliteGrateTestContext : IGrateTestContext { public SqliteGrateTestContext( IGrateMigrator migrator, - SqliteTestContainerDatabase _) + ITestDatabase _) { Migrator = migrator; } - public string AdminPassword { get; set; } = default!; - public int? Port { get; set; } - public string AdminConnectionString => $"Data Source=grate-sqlite.db"; public string ConnectionString(string database) => $"Data Source={database}.db"; public string UserConnectionString(string database) => $"Data Source={database}.db"; diff --git a/unittests/Sqlite/TestInfrastructure/SqliteTestContainerDatabase.cs b/unittests/Sqlite/TestInfrastructure/SqliteTestContainerDatabase.cs deleted file mode 100644 index 962e26d2..00000000 --- a/unittests/Sqlite/TestInfrastructure/SqliteTestContainerDatabase.cs +++ /dev/null @@ -1,64 +0,0 @@ - - -using Microsoft.Data.Sqlite; -using Xunit.Sdk; -namespace TestCommon.TestInfrastructure; -public class SqliteTestContainerDatabase : IAsyncLifetime -{ - private readonly IMessageSink _messageSink; - - public SqliteTestContainerDatabase(IMessageSink messageSink) - { - _messageSink = messageSink; - } - public Task DisposeAsync() - { - SqliteConnection.ClearAllPools(); - - var currentDirectory = Directory.GetCurrentDirectory(); - var dbFiles = Directory.GetFiles(currentDirectory, "*.db"); - var message = new DiagnosticMessage("After tests. Deleting DB files."); - _messageSink.OnMessage(message); - foreach (var dbFile in dbFiles) - { - var deleteMessage = new DiagnosticMessage("File: {0}", dbFile); - _messageSink.OnMessage(deleteMessage); - File.Delete(dbFile); - } - return Task.CompletedTask; - } - - public Task InitializeAsync() - { - var currentDirectory = Directory.GetCurrentDirectory(); - var dbFiles = Directory.GetFiles(currentDirectory, "*.db"); - var message = new DiagnosticMessage("Before tests. Deleting old DB files."); - _messageSink.OnMessage(message); - foreach (var dbFile in dbFiles) - { - TryDeletingFile(dbFile); - } - return Task.CompletedTask; - } - private void TryDeletingFile(string dbFile) - { - var i = 0; - var sleepTime = 300; - const int maxTries = 5; - while (i++ < maxTries) - { - try - { - var message = new DiagnosticMessage("File: {0}", dbFile); - _messageSink.OnMessage(message); - File.Delete(dbFile); - return; - } - catch (IOException) when (i <= maxTries) - { - Thread.Sleep(sleepTime); - } - } - } - -} diff --git a/unittests/Sqlite/TestInfrastructure/ExternalSqliteDatabase.cs b/unittests/Sqlite/TestInfrastructure/SqliteTestDatabase.cs similarity index 74% rename from unittests/Sqlite/TestInfrastructure/ExternalSqliteDatabase.cs rename to unittests/Sqlite/TestInfrastructure/SqliteTestDatabase.cs index 8ab5138a..b6f9ead8 100644 --- a/unittests/Sqlite/TestInfrastructure/ExternalSqliteDatabase.cs +++ b/unittests/Sqlite/TestInfrastructure/SqliteTestDatabase.cs @@ -1,17 +1,10 @@  -using grate.Migration; using Microsoft.Data.Sqlite; using Xunit.Sdk; namespace TestCommon.TestInfrastructure; -public class ExternalSqliteDatabase : ITestDatabase +public class SqliteTestDatabase(IMessageSink messageSink) : ITestDatabase { - private readonly IMessageSink _messageSink; - - public ExternalSqliteDatabase(IMessageSink messageSink) - { - _messageSink = messageSink; - } public Task DisposeAsync() { SqliteConnection.ClearAllPools(); @@ -19,11 +12,11 @@ public Task DisposeAsync() var currentDirectory = Directory.GetCurrentDirectory(); var dbFiles = Directory.GetFiles(currentDirectory, "*.db"); var message = new DiagnosticMessage("After tests. Deleting DB files."); - _messageSink.OnMessage(message); + messageSink.OnMessage(message); foreach (var dbFile in dbFiles) { var deleteMessage = new DiagnosticMessage("File: {0}", dbFile); - _messageSink.OnMessage(deleteMessage); + messageSink.OnMessage(deleteMessage); File.Delete(dbFile); } return Task.CompletedTask; @@ -34,7 +27,7 @@ public Task InitializeAsync() var currentDirectory = Directory.GetCurrentDirectory(); var dbFiles = Directory.GetFiles(currentDirectory, "*.db"); var message = new DiagnosticMessage("Before tests. Deleting old DB files."); - _messageSink.OnMessage(message); + messageSink.OnMessage(message); foreach (var dbFile in dbFiles) { TryDeletingFile(dbFile); @@ -51,7 +44,7 @@ private void TryDeletingFile(string dbFile) try { var message = new DiagnosticMessage("File: {0}", dbFile); - _messageSink.OnMessage(message); + messageSink.OnMessage(message); File.Delete(dbFile); return; } @@ -61,5 +54,8 @@ private void TryDeletingFile(string dbFile) } } } - + + public string AdminConnectionString => $"Data Source=grate-sqlite.db"; + public string ConnectionString(string database) => $"Data Source={database}.db"; + public string UserConnectionString(string database) => $"Data Source={database}.db"; }