Skip to content

Commit

Permalink
A bit of cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
erikbra committed Jan 14, 2024
1 parent f5f854b commit 2618fc0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,32 +68,6 @@ public async Task AdminConnectionString(string argName)
cfg?.AdminConnectionString.Should().Be(database);
}

// [Theory]
// [InlineData(grate.MariaDb.Migration.MariaDbDatabase.Type)]
// [InlineData(grate.Oracle.Migration.OracleDatabase.Type)]
// [InlineData(grate.PostgreSql.Migration.PostgreSqlDatabase.Type)]
// [InlineData(grate.Sqlite.Migration.SqliteDatabase.Type)]
// [InlineData(grate.SqlServer.Migration.SqlServerDatabase.Type)]
// public async Task DefaultAdminConnectionString(string databaseType)
// {
// var commandline = $"--connectionstring=;Database=jalla --databasetype={databaseType}";
// var cfg = await ParseGrateConfiguration(commandline);

// var masterDbName = GetMasterDatabaseName(databaseType);

// cfg?.AdminConnectionString.Should().Be($";Database=" + masterDbName);
// }

// private string GetMasterDatabaseName(DatabaseType databaseType) => databaseType switch
// {
// DatabaseType.mariadb => "mysql",
// DatabaseType.oracle => "oracle",
// DatabaseType.postgresql => "postgres",
// DatabaseType.sqlite => "master",
// DatabaseType.sqlserver => "master",
// _ => throw new ArgumentOutOfRangeException(nameof(databaseType), databaseType, "Invalid database type: " + databaseType)
// };

[Theory]
[InlineData("-f ")]
[InlineData("--files=")]
Expand Down
12 changes: 1 addition & 11 deletions unittests/MariaDB/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace MariaDB;

// ReSharper disable once UnusedType.Global
public class Startup
{
public void ConfigureServices(IServiceCollection services, HostBuilderContext context)
Expand All @@ -24,16 +25,6 @@ public void ConfigureServices(IServiceCollection services, HostBuilderContext co
)
.AddSingleton<MariaDbTestContainer>()
.AddSingleton<IGrateMigrator, GrateMigrator>()
// .AddSingleton<Func<GrateConfiguration, IDbMigrator>>(serviceProvider =>
// {
// using var scope = serviceProvider.CreateScope();
// var provider = scope.ServiceProvider;
//
// IDatabase database = provider.GetRequiredService<IDatabase>();
// ILogger<DbMigrator> logger = provider.GetRequiredService<ILogger<DbMigrator>>();
// IHashGenerator hashGenerator = provider.GetRequiredService<IHashGenerator>();
// return config => new DbMigrator(database, logger, hashGenerator, config);
// })
.AddSingleton<Func<GrateConfiguration, GrateMigrator>>(provider =>
config =>
{
Expand All @@ -49,7 +40,6 @@ public void ConfigureServices(IServiceCollection services, HostBuilderContext co
})
.AddSingleton<IHashGenerator, HashGenerator>()

// TODO: Decide whether to register here, or to use IClassFixture<> in the test classes
.AddTransient<IGrateTestContext, MariaDbGrateTestContext>()
//.AddTransient<MariaDbGrateTestContext>()

Expand Down
10 changes: 2 additions & 8 deletions unittests/MariaDB/TestInfrastructure/MariaDbGrateTestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using grate.Infrastructure;
using grate.MariaDb.Migration;
using grate.Migration;
using Microsoft.Extensions.DependencyInjection;
using MySqlConnector;
using TestCommon.TestInfrastructure;

Expand All @@ -19,25 +18,20 @@ public class MariaDbGrateTestContext : IGrateTestContext
private readonly MariaDbTestContainer _testContainer;
private readonly IDatabaseConnectionFactory _databaseConnectionFactory;

//public MariaDbGrateTestContext(IServiceProvider serviceProvider, MariaDbTestContainer container)
public MariaDbGrateTestContext(
IServiceProvider serviceProvider,
//IServiceProvider serviceProvider,
Func<GrateConfiguration, GrateMigrator> getGrateMigrator,
IDatabase dbMigrator,
ISyntax syntax,
IDatabaseConnectionFactory databaseConnectionFactory,
MariaDbTestContainer container)
{
ServiceProvider = null!;
ServiceProvider = serviceProvider;
_getGrateMigrator = getGrateMigrator;
_testContainer = container;
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 All @@ -56,7 +50,7 @@ public MariaDbGrateTestContext(
// public string DatabaseTypeName => "MariaDB Server";
// public string MasterDatabase => "mysql";

public IDatabase DatabaseMigrator { get; init; }
public IDatabase DatabaseMigrator { get; }

public SqlStatements Sql => new()
{
Expand Down

0 comments on commit 2618fc0

Please sign in to comment.