Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
erikbra committed Jan 30, 2024
1 parent a87663d commit 92424c6
Show file tree
Hide file tree
Showing 18 changed files with 107 additions and 166 deletions.
10 changes: 2 additions & 8 deletions unittests/Oracle/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,5 @@
namespace Oracle;

[Collection(nameof(OracleTestContainer))]
public class Database : GenericDatabase, IClassFixture<SimpleService>
{
public Database(OracleTestContainer testContainer, SimpleService simpleService, ITestOutputHelper testOutput)
{
Context = new OracleGrateTestContext(simpleService.ServiceProvider, testContainer);
TestOutput = testOutput;
}
}
public class Database(IGrateTestContext testContext, ITestOutputHelper testOutput)
: GenericDatabase(testContext, testOutput);
8 changes: 2 additions & 6 deletions unittests/Oracle/MigrationTables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@
namespace Oracle;

[Collection(nameof(OracleTestContainer))]
public class MigrationTables : GenericMigrationTables, IClassFixture<SimpleService>
public class MigrationTables(IGrateTestContext testContext, ITestOutputHelper testOutput)
: GenericMigrationTables(testContext, testOutput)
{
public MigrationTables(OracleTestContainer testContainer, SimpleService simpleService, ITestOutputHelper testOutput)
{
Context = new OracleGrateTestContext(simpleService.ServiceProvider, testContainer);
TestOutput = testOutput;
}

protected override Task CheckTableCasing(string tableName, string funnyCasing, Func<GrateConfiguration, string, GrateConfiguration> setTableName)
{
Expand Down
26 changes: 0 additions & 26 deletions unittests/Oracle/TestInfrastructure/SimpleService.cs

This file was deleted.

15 changes: 6 additions & 9 deletions unittests/Sqlite/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@
namespace Sqlite;

[Collection(nameof(SqliteTestContainer))]
public class Database : TestCommon.Generic.GenericDatabase, IClassFixture<SimpleService>
// ReSharper disable once InconsistentNaming
// ReSharper disable once UnusedType.Global
public class Database(IGrateTestContext testContext, ITestOutputHelper testOutput)
: TestCommon.Generic.GenericDatabase(testContext, testOutput)
{

public Database(SqliteTestContainer testContainer, SimpleService simpleService, ITestOutputHelper testOutput)
{
Context = new SqliteGrateTestContext(simpleService.ServiceProvider, testContainer);
TestOutput = testOutput;
}



protected override async Task CreateDatabaseFromConnectionString(string db, string connectionString)
{
await using var conn = new SqliteConnection(connectionString);
Expand Down Expand Up @@ -50,4 +46,5 @@ public override Task Is_created_with_custom_script_if_custom_create_database_fol
[Fact(Skip = "SQLite does not support docker container")]
public override Task Is_up_and_running_with_appropriate_database_version() => Task.CompletedTask;
protected override bool ThrowOnMissingDatabase => false;

}
10 changes: 4 additions & 6 deletions unittests/Sqlite/MigrationTables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
namespace Sqlite;

[Collection(nameof(SqliteTestContainer))]
public class MigrationTables : TestCommon.Generic.GenericMigrationTables, IClassFixture<SimpleService>
// ReSharper disable once InconsistentNaming
// ReSharper disable once UnusedType.Global
public class MigrationTables(IGrateTestContext testContext, ITestOutputHelper testOutput)
: TestCommon.Generic.GenericMigrationTables(testContext, testOutput)
{
public MigrationTables(SqliteTestContainer testContainer, SimpleService simpleService, ITestOutputHelper testOutput)
{
Context = new SqliteGrateTestContext(simpleService.ServiceProvider, testContainer);
TestOutput = testOutput;
}

protected override string CountTableSql(string schemaName, string tableName)
{
Expand Down
14 changes: 4 additions & 10 deletions unittests/Sqlite/Running_MigrationScripts/Anytime_scripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@

namespace Sqlite.Running_MigrationScripts;


[Collection(nameof(SqliteTestContainer))]
// ReSharper disable once InconsistentNaming
public class Anytime_scripts : TestCommon.Generic.Running_MigrationScripts.Anytime_scripts, IClassFixture<SimpleService>
{

public Anytime_scripts(SqliteTestContainer testContainer, SimpleService simpleService, ITestOutputHelper testOutput)
{
Context = new SqliteGrateTestContext(simpleService.ServiceProvider, testContainer);
TestOutput = testOutput;
}

}
// ReSharper disable once UnusedType.Global
public class Anytime_scripts(IGrateTestContext testContext, ITestOutputHelper testOutput)
: TestCommon.Generic.Running_MigrationScripts.Anytime_scripts(testContext, testOutput);
13 changes: 4 additions & 9 deletions unittests/Sqlite/Running_MigrationScripts/DropDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@
namespace Sqlite.Running_MigrationScripts;

[Collection(nameof(SqliteTestContainer))]
public class DropDatabase : TestCommon.Generic.Running_MigrationScripts.DropDatabase, IClassFixture<SimpleService>
{
public DropDatabase(SqliteTestContainer testContainer, SimpleService simpleService, ITestOutputHelper testOutput)
{
Context = new SqliteGrateTestContext(simpleService.ServiceProvider, testContainer);
TestOutput = testOutput;
}

}
// ReSharper disable once InconsistentNaming
// ReSharper disable once UnusedType.Global
public class DropDatabase(IGrateTestContext testContext, ITestOutputHelper testOutput)
: TestCommon.Generic.Running_MigrationScripts.DropDatabase(testContext, testOutput);
11 changes: 3 additions & 8 deletions unittests/Sqlite/Running_MigrationScripts/Environment_scripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ namespace Sqlite.Running_MigrationScripts;

[Collection(nameof(SqliteTestContainer))]
// ReSharper disable once InconsistentNaming
public class Environment_scripts : TestCommon.Generic.Running_MigrationScripts.Environment_scripts, IClassFixture<SimpleService>
{
public Environment_scripts(SqliteTestContainer testContainer, SimpleService simpleService, ITestOutputHelper testOutput)
{
Context = new SqliteGrateTestContext(simpleService.ServiceProvider, testContainer);
TestOutput = testOutput;
}
// ReSharper disable once UnusedType.Global
public class Environment_scripts(IGrateTestContext testContext, ITestOutputHelper testOutput)
: TestCommon.Generic.Running_MigrationScripts.Environment_scripts(testContext, testOutput);

}
12 changes: 3 additions & 9 deletions unittests/Sqlite/Running_MigrationScripts/Everytime_scripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ namespace Sqlite.Running_MigrationScripts;

[Collection(nameof(SqliteTestContainer))]
// ReSharper disable once InconsistentNaming
public class Everytime_scripts : TestCommon.Generic.Running_MigrationScripts.Everytime_scripts, IClassFixture<SimpleService>
{
public Everytime_scripts(SqliteTestContainer testContainer, SimpleService simpleService, ITestOutputHelper testOutput)
{
Context = new SqliteGrateTestContext(simpleService.ServiceProvider, testContainer);
TestOutput = testOutput;
}

}
// ReSharper disable once UnusedType.Global
public class Everytime_scripts(IGrateTestContext testContext, ITestOutputHelper testOutput)
: TestCommon.Generic.Running_MigrationScripts.Everytime_scripts(testContext, testOutput);
11 changes: 3 additions & 8 deletions unittests/Sqlite/Running_MigrationScripts/Failing_Scripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ namespace Sqlite.Running_MigrationScripts;

[Collection(nameof(SqliteTestContainer))]
// ReSharper disable once InconsistentNaming
public class Failing_Scripts : TestCommon.Generic.Running_MigrationScripts.Failing_Scripts, IClassFixture<SimpleService>
// ReSharper disable once UnusedType.Global
public class Failing_Scripts(IGrateTestContext testContext, ITestOutputHelper testOutput)
: TestCommon.Generic.Running_MigrationScripts.Failing_Scripts(testContext, testOutput)
{
public Failing_Scripts(SqliteTestContainer testContainer, SimpleService simpleService, ITestOutputHelper testOutput)
{
Context = new SqliteGrateTestContext(simpleService.ServiceProvider, testContainer);
TestOutput = testOutput;
}


protected override string ExpectedErrorMessageForInvalidSql => "SQLite Error 1: 'no such column: TOP'.";
}
12 changes: 3 additions & 9 deletions unittests/Sqlite/Running_MigrationScripts/One_time_scripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ namespace Sqlite.Running_MigrationScripts;

[Collection(nameof(SqliteTestContainer))]
// ReSharper disable once InconsistentNaming
public class One_time_scripts : TestCommon.Generic.Running_MigrationScripts.One_time_scripts, IClassFixture<SimpleService>
{
public One_time_scripts(SqliteTestContainer testContainer, SimpleService simpleService, ITestOutputHelper testOutput)
{
Context = new SqliteGrateTestContext(simpleService.ServiceProvider, testContainer);
TestOutput = testOutput;
}

}
// ReSharper disable once UnusedType.Global
public class One_time_scripts(IGrateTestContext testContext, ITestOutputHelper testOutput)
: TestCommon.Generic.Running_MigrationScripts.One_time_scripts(testContext, testOutput);
12 changes: 3 additions & 9 deletions unittests/Sqlite/Running_MigrationScripts/Order_Of_Scripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ namespace Sqlite.Running_MigrationScripts;

[Collection(nameof(SqliteTestContainer))]
// ReSharper disable once InconsistentNaming
public class Order_Of_Scripts : TestCommon.Generic.Running_MigrationScripts.Order_Of_Scripts, IClassFixture<SimpleService>
{
public Order_Of_Scripts(SqliteTestContainer testContainer, SimpleService simpleService, ITestOutputHelper testOutput)
{
Context = new SqliteGrateTestContext(simpleService.ServiceProvider, testContainer);
TestOutput = testOutput;
}

}
// ReSharper disable once UnusedType.Global
public class Order_Of_Scripts(IGrateTestContext testContext, ITestOutputHelper testOutput)
: TestCommon.Generic.Running_MigrationScripts.Order_Of_Scripts(testContext, testOutput);
12 changes: 4 additions & 8 deletions unittests/Sqlite/Running_MigrationScripts/ScriptsRun_Table.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
namespace Sqlite.Running_MigrationScripts;

[Collection(nameof(SqliteTestContainer))]
public class ScriptsRun_Table : TestCommon.Generic.Running_MigrationScripts.ScriptsRun_Table, IClassFixture<SimpleService>
{
public ScriptsRun_Table(SqliteTestContainer testContainer, SimpleService simpleService, ITestOutputHelper testOutput)
{
Context = new SqliteGrateTestContext(simpleService.ServiceProvider, testContainer);
TestOutput = testOutput;
}
// ReSharper disable once InconsistentNaming
// ReSharper disable once UnusedType.Global
public class ScriptsRun_Table(IGrateTestContext testContext, ITestOutputHelper testOutput)
: TestCommon.Generic.Running_MigrationScripts.ScriptsRun_Table(testContext, testOutput);

}
12 changes: 4 additions & 8 deletions unittests/Sqlite/Running_MigrationScripts/TokenScripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
namespace Sqlite.Running_MigrationScripts;

[Collection(nameof(SqliteTestContainer))]
public class TokenScripts : TestCommon.Generic.Running_MigrationScripts.TokenScripts, IClassFixture<SimpleService>
{
public TokenScripts(SqliteTestContainer testContainer, SimpleService simpleService, ITestOutputHelper testOutput)
{
Context = new SqliteGrateTestContext(simpleService.ServiceProvider, testContainer);
TestOutput = testOutput;
}
// ReSharper disable once InconsistentNaming
// ReSharper disable once UnusedType.Global
public class TokenScripts(IGrateTestContext testContext, ITestOutputHelper testOutput)
: TestCommon.Generic.Running_MigrationScripts.TokenScripts(testContext, testOutput);

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ namespace Sqlite.Running_MigrationScripts;

[Collection(nameof(SqliteTestContainer))]
// ReSharper disable once InconsistentNaming
public class Versioning_The_Database : TestCommon.Generic.Running_MigrationScripts.Versioning_The_Database, IClassFixture<SimpleService>
{
public Versioning_The_Database(SqliteTestContainer testContainer, SimpleService simpleService, ITestOutputHelper testOutput)
{
Context = new SqliteGrateTestContext(simpleService.ServiceProvider, testContainer);
TestOutput = testOutput;
}
// ReSharper disable once UnusedType.Global
public class Versioning_The_Database(IGrateTestContext testContext, ITestOutputHelper testOutput)
: TestCommon.Generic.Running_MigrationScripts.Versioning_The_Database(testContext, testOutput);

}
2 changes: 2 additions & 0 deletions unittests/Sqlite/Sqlite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<PackageReference Include="xunit.runner.visualstudio"/>
<PackageReference Include="coverlet.collector" />
<PackageReference Include="XunitXml.TestLogger" />
<PackageReference Include="Xunit.DependencyInjection" />
<PackageReference Include="Xunit.DependencyInjection.Logging" />
</ItemGroup>

<ItemGroup>
Expand Down
57 changes: 57 additions & 0 deletions unittests/Sqlite/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using grate.Configuration;
using grate.Infrastructure;
using grate.Migration;
using grate.PostgreSql.Infrastructure;
using grate.PostgreSql.Migration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Sqlite.TestInfrastructure;
using TestCommon.TestInfrastructure;

namespace PostgreSQL;

// ReSharper disable once UnusedType.Global
public class Startup
{
// ReSharper disable once UnusedMember.Global
public void ConfigureServices(IServiceCollection services, HostBuilderContext context)
{
services
.AddLogging(
lb => lb
.AddXUnit()
.AddConsole()
.SetMinimumLevel(TestConfig.GetLogLevel())
)
.AddSingleton<IGrateMigrator, GrateMigrator>()
.AddSingleton<Func<GrateConfiguration, GrateMigrator>>(provider =>
config =>
{
IDatabase database = provider.GetRequiredService<IDatabase>();

ILogger<DbMigrator> dbLogger = provider.GetRequiredService<ILogger<DbMigrator>>();
ILogger<GrateMigrator> grateLogger = provider.GetRequiredService<ILogger<GrateMigrator>>();

IHashGenerator hashGenerator = provider.GetRequiredService<IHashGenerator>();
return
new GrateMigrator(grateLogger,
new DbMigrator(database, dbLogger, hashGenerator, config));
})
.AddSingleton<IHashGenerator, HashGenerator>()

.AddTransient<IGrateTestContext, SqliteGrateTestContext>()

.AddTransient<IDatabase, PostgreSqlDatabase>()
.AddSingleton<ISyntax, PostgreSqlSyntax>()
.AddSingleton<IDatabaseConnectionFactory, SqliteConnectionFactory>()
.AddSingleton<StatementSplitter>()
.AddSingleton(service =>
{
var database = service.GetService<IDatabase>()!;
return new StatementSplitter(database.StatementSeparatorRegex);
});
;

}
}
25 changes: 0 additions & 25 deletions unittests/Sqlite/TestInfrastructure/SimpleService.cs

This file was deleted.

0 comments on commit 92424c6

Please sign in to comment.