Skip to content

Commit

Permalink
WIP: Tests are working
Browse files Browse the repository at this point in the history
  • Loading branch information
erikbra committed Jan 14, 2024
1 parent c33d872 commit 6157303
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/grate.core/Migration/AnsiSqlDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,8 @@ private static async Task Close(DbConnection? conn)

protected virtual async Task Open(DbConnection? conn)
{
//if (conn != null && conn.State != ConnectionState.Open)
if (conn is not null && conn is not { State: ConnectionState.Open or ConnectionState.Connecting })
if (conn != null && conn.State != ConnectionState.Open)
//if (conn is not null && conn is not { State: ConnectionState.Open or ConnectionState.Connecting })
{
await conn.OpenAsync();
await conn.QueryAsync<string>(_syntax.CurrentDatabase);
Expand Down
10 changes: 8 additions & 2 deletions unittests/MariaDB/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ public class Database : GenericDatabase, IClassFixture<SimpleService>

protected ITestOutputHelper TestOutput { get; }

public Database(IGrateTestContext testContext, ITestOutputHelper testOutput)
public Database(MariaDbTestContainer testContainer, SimpleService simpleService, ITestOutputHelper testOutput)
{
Context = testContext;
Context = new MariaDbGrateTestContext(simpleService.ServiceProvider, testContainer);
TestOutput = testOutput;
}

// public Database(IGrateTestContext testContext, ITestOutputHelper testOutput)
// {
// Context = testContext;
// TestOutput = testOutput;
// }
}
10 changes: 8 additions & 2 deletions unittests/MariaDB/MigrationTables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ public class MigrationTables : GenericMigrationTables, IClassFixture<SimpleServi

protected ITestOutputHelper TestOutput { get; }

public MigrationTables(IGrateTestContext testContext, ITestOutputHelper testOutput)
// public MigrationTables(IGrateTestContext testContext, ITestOutputHelper testOutput)
// {
// Context = testContext;
// TestOutput = testOutput;
// }
public MigrationTables(MariaDbTestContainer testContainer, SimpleService simpleService, ITestOutputHelper testOutput)
{
Context = testContext;
Context = new MariaDbGrateTestContext(simpleService.ServiceProvider, testContainer);
TestOutput = testOutput;
}

}
10 changes: 8 additions & 2 deletions unittests/MariaDB/Running_MigrationScripts/Failing_Scripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ public class Failing_Scripts : TestCommon.Generic.Running_MigrationScripts.Faili

protected override ITestOutputHelper TestOutput { get; }

public Failing_Scripts(IGrateTestContext testContext, ITestOutputHelper testOutput)
public Failing_Scripts(MariaDbTestContainer testContainer, SimpleService simpleService, ITestOutputHelper testOutput)
{
Context = testContext;
Context = new MariaDbGrateTestContext(simpleService.ServiceProvider, testContainer);
TestOutput = testOutput;
}

// public Failing_Scripts(IGrateTestContext testContext, ITestOutputHelper testOutput)
// {
// Context = testContext;
// TestOutput = testOutput;
// }

protected override string ExpectedErrorMessageForInvalidSql => "Unknown column 'TOP' in 'field list'";
}
10 changes: 8 additions & 2 deletions unittests/MariaDB/Running_MigrationScripts/One_time_scripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ public class One_time_scripts : TestCommon.Generic.Running_MigrationScripts.One_

protected override ITestOutputHelper TestOutput { get; }

public One_time_scripts(IGrateTestContext testContext, ITestOutputHelper testOutput)
public One_time_scripts(MariaDbTestContainer testContainer, SimpleService simpleService, ITestOutputHelper testOutput)
{
Context = testContext;
Context = new MariaDbGrateTestContext(simpleService.ServiceProvider, testContainer);
TestOutput = testOutput;
}

// public One_time_scripts(IGrateTestContext testContext, ITestOutputHelper testOutput)
// {
// Context = testContext;
// TestOutput = testOutput;
// }

}
2 changes: 1 addition & 1 deletion unittests/MariaDB/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void ConfigureServices(IServiceCollection services, HostBuilderContext co
// new DbMigrator(database, dbLogger, hashGenerator, config));
})
.AddSingleton<IHashGenerator, HashGenerator>()
.AddSingleton<IGrateTestContext, MariaDbGrateTestContext>()
.AddScoped<IGrateTestContext, MariaDbGrateTestContext>()
.AddSingleton<IDatabase, MariaDbDatabase>()
.AddSingleton<ISyntax, MariaDbSyntax>()
.AddSingleton<IDatabaseConnectionFactory, MariaDbConnectionFactory>()
Expand Down
21 changes: 12 additions & 9 deletions unittests/MariaDB/TestInfrastructure/MariaDbGrateTestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,29 @@ public class MariaDbGrateTestContext : IGrateTestContext
public int? Port => _testContainer.TestContainer!.GetMappedPublicPort(_testContainer.Port);
public IServiceProvider ServiceProvider { get; private set; }
//private readonly IGrateMigrator _grateMigrator;
private readonly Func<GrateConfiguration, GrateMigrator> _getGrateMigrator;
//private readonly Func<GrateConfiguration, GrateMigrator> _getGrateMigrator;
private readonly MariaDbTestContainer _testContainer;
private readonly IDatabaseConnectionFactory _databaseConnectionFactory;

//public MariaDbGrateTestContext(IServiceProvider serviceProvider, MariaDbTestContainer container)
public MariaDbGrateTestContext(
IServiceProvider serviceProvider,
Func<GrateConfiguration, GrateMigrator> getGrateMigrator,
IDatabase dbMigrator,
ISyntax syntax,
IDatabaseConnectionFactory databaseConnectionFactory,
//Func<GrateConfiguration, GrateMigrator> getGrateMigrator,
//IDatabase dbMigrator,
//ISyntax syntax,
//IDatabaseConnectionFactory databaseConnectionFactory,
MariaDbTestContainer container)
{
//ServiceProvider = null!;
ServiceProvider = serviceProvider;
_getGrateMigrator = getGrateMigrator;
//_getGrateMigrator = getGrateMigrator;
_testContainer = container;
DatabaseMigrator = dbMigrator;
Syntax = syntax;
_databaseConnectionFactory = databaseConnectionFactory;
//DatabaseMigrator = dbMigrator;
//Syntax = syntax;
//_databaseConnectionFactory = databaseConnectionFactory;
DatabaseMigrator = ServiceProvider.GetService<IDatabase>()!;
Syntax = ServiceProvider.GetService<ISyntax>()!;
_databaseConnectionFactory = ServiceProvider.GetService<IDatabaseConnectionFactory>()!;
}

//public IGrateMigrator GetMigrator(GrateConfiguration config) => _getGrateMigrator(config);
Expand Down

0 comments on commit 6157303

Please sign in to comment.