diff --git a/src/grate.core/Configuration/GrateConfiguration.cs b/src/grate.core/Configuration/GrateConfiguration.cs
index ca775e95..62059fdd 100644
--- a/src/grate.core/Configuration/GrateConfiguration.cs
+++ b/src/grate.core/Configuration/GrateConfiguration.cs
@@ -137,8 +137,6 @@ public record GrateConfiguration
private static DirectoryInfo CurrentDirectory => new(Directory.GetCurrentDirectory());
- public LogLevel Verbosity { get; init; } = LogLevel.Information;
-
///
/// If true grate will not store script text in the database to save space in small/embedded databases.
///
diff --git a/src/grate.core/Migration/DbMigrator.cs b/src/grate.core/Migration/DbMigrator.cs
index 26e2e897..d7b00ef8 100644
--- a/src/grate.core/Migration/DbMigrator.cs
+++ b/src/grate.core/Migration/DbMigrator.cs
@@ -9,12 +9,12 @@ namespace grate.Migration;
internal record DbMigrator : IDbMigrator
{
- private readonly ILogger _logger;
+ public ILogger Logger { get; set; }
private readonly IHashGenerator _hashGenerator;
public DbMigrator(IDatabase database, ILogger logger, IHashGenerator hashGenerator, GrateConfiguration? configuration = null)
{
- _logger = logger;
+ Logger = logger;
_hashGenerator = hashGenerator;
Configuration = configuration ?? throw new ArgumentException("No configuration passed to DbMigrator. Container setup error?", nameof(configuration));
Database = database;
@@ -54,7 +54,7 @@ public Task VersionTheDatabase(string newVersion)
{
if (Configuration.DryRun)
{
- _logger.LogDebug("Skipping writing database version row due to --dryrun");
+ Logger.LogDebug("Skipping writing database version row due to --dryrun");
return Task.FromResult(-1L);
}
else
@@ -78,7 +78,7 @@ public async Task RunSql(string sql, string scriptName, MigrationsFolder f
async Task LogAndRunSql()
{
- _logger.LogInformation(" Running '{ScriptName}'.", scriptName);
+ Logger.LogInformation(" Running '{ScriptName}'.", scriptName);
if (Configuration.DryRun)
{
@@ -122,13 +122,13 @@ async Task LogAndRunSql()
case MigrationType.Once when changeHandling == ChangedScriptHandling.WarnAndRun:
LogScriptChangedWarning(scriptName);
- _logger.LogDebug("Running script anyway due to WarnOnOneTimeScriptChanges option being set.");
+ Logger.LogDebug("Running script anyway due to WarnOnOneTimeScriptChanges option being set.");
theSqlWasRun = await LogAndRunSql();
break;
case MigrationType.Once when changeHandling == ChangedScriptHandling.WarnAndIgnore:
LogScriptChangedWarning(scriptName);
- _logger.LogDebug("Ignoring script but marking as run due to WarnAndIgnoreOnOneTimeScriptChanges option being set.");
+ Logger.LogDebug("Ignoring script but marking as run due to WarnAndIgnoreOnOneTimeScriptChanges option being set.");
await RecordScriptInScriptsRunTable(scriptName, sql, type, versionId, transactionHandling);
break;
@@ -140,7 +140,7 @@ async Task LogAndRunSql()
}
else
{
- _logger.LogDebug(" Skipped {ScriptName} - {Reason}.", scriptName, "No changes were found to run");
+ Logger.LogDebug(" Skipped {ScriptName} - {Reason}.", scriptName, "No changes were found to run");
}
}
else
@@ -160,7 +160,7 @@ public async Task RunSqlWithoutLogging(
{
async Task PrintLogAndRunSql()
{
- _logger.LogInformation(" Running '{ScriptName}'.", scriptName);
+ Logger.LogInformation(" Running '{ScriptName}'.", scriptName);
if (Configuration.DryRun)
{
@@ -281,7 +281,7 @@ private async Task RunTheActualSql(string sql,
}
catch (Exception ex)
{
- _logger.LogError("{ScriptName}: {ErrorMessage}", scriptName, ex.Message);
+ Logger.LogError("{ScriptName}: {ErrorMessage}", scriptName, ex.Message);
if (Transaction.Current is not null)
{
@@ -320,7 +320,7 @@ private async Task RunTheActualSqlWithoutLogging(
}
catch (Exception ex)
{
- _logger.LogError("{ScriptName}: {ErrorMessage}", scriptName, ex.Message);
+ Logger.LogError("{ScriptName}: {ErrorMessage}", scriptName, ex.Message);
if (Transaction.Current is not null)
{
@@ -339,7 +339,7 @@ private async Task RunTheActualSqlWithoutLogging(
private void LogScriptChangedWarning(string scriptName)
{
- _logger.LogWarning("{ScriptName} is a one time script that has changed since it was run.", scriptName);
+ Logger.LogWarning("{ScriptName} is a one time script that has changed since it was run.", scriptName);
}
///
@@ -354,7 +354,7 @@ private void LogScriptChangedWarning(string scriptName)
///
private async Task OneTimeScriptChanged(MigrationsFolder folder, string sql, string scriptName, long versionId)
{
- _logger.LogError("{ScriptName}: {ErrorMessage}", scriptName, "One time script changed");
+ Logger.LogError("{ScriptName}: {ErrorMessage}", scriptName, "One time script changed");
Database.Rollback();
await Database.CloseConnection();
@@ -383,12 +383,12 @@ private Task RecordScriptInScriptsRunTable(string scriptName, string sql, Migrat
if (Configuration.DryRun)
{
- _logger.LogTrace("Skipping recording {ScriptName} script ran on {ServerName} - {DatabaseName}, --dryrun prevents sql writes", scriptName, Database.ServerName, Database.DatabaseName);
+ Logger.LogTrace("Skipping recording {ScriptName} script ran on {ServerName} - {DatabaseName}, --dryrun prevents sql writes", scriptName, Database.ServerName, Database.DatabaseName);
return Task.CompletedTask;
}
else
{
- _logger.LogTrace("Recording {ScriptName} script ran on {ServerName} - {DatabaseName}.", scriptName, Database.ServerName, Database.DatabaseName);
+ Logger.LogTrace("Recording {ScriptName} script ran on {ServerName} - {DatabaseName}.", scriptName, Database.ServerName, Database.DatabaseName);
return Database.InsertScriptRun(scriptName, sqlToStore, hash, migrationType == MigrationType.Once, versionId, transactionHandling);
}
}
diff --git a/src/grate.core/Migration/GrateMigrator.cs b/src/grate.core/Migration/GrateMigrator.cs
index 5005ada8..a2285865 100644
--- a/src/grate.core/Migration/GrateMigrator.cs
+++ b/src/grate.core/Migration/GrateMigrator.cs
@@ -10,17 +10,23 @@ namespace grate.Migration;
internal record GrateMigrator : IGrateMigrator
{
- private readonly ILogger _logger;
+ private readonly ILoggerFactory _loggerFactory;
+ private readonly ILogger _logger;
internal IDbMigrator DbMigrator { get; private init; }
+
+ private string LogCategory => $"Grate.Migration{(IsInternalMigration() ? ".Internal" : "")}";
public GrateConfiguration Configuration
{
get => DbMigrator.Configuration;
private init
{
+ _logger = _loggerFactory.CreateLogger(LogCategory);
+
DbMigrator = (IDbMigrator) DbMigrator.Clone();
DbMigrator.Configuration = value;
+ DbMigrator.Logger = _logger;
}
}
@@ -49,10 +55,11 @@ public IGrateMigrator WithConfiguration(Action builde
public IGrateMigrator WithDatabase(IDatabase database) => this with { Database = database };
- public GrateMigrator(ILogger logger, IDbMigrator migrator)
+ public GrateMigrator(ILoggerFactory loggerFactory, IDbMigrator migrator)
{
- _logger = logger;
DbMigrator = migrator;
+ _loggerFactory = loggerFactory;
+ _logger = loggerFactory.CreateLogger(LogCategory);
}
public async Task Migrate()
@@ -271,6 +278,9 @@ private async Task CreateGrateStructure(IDbMigrator dbMigrator)
}
}
}
+
+ private bool IsInternalMigration() => GrateEnvironment.Internal == this.Configuration?.Environment
+ || GrateEnvironment.InternalBootstrap == this.Configuration?.Environment;
private async Task<(long, string)> VersionTheDatabase(IDbMigrator dbMigrator)
@@ -616,7 +626,6 @@ private async Task GetInternalGrateConfiguration(string inte
AccessToken = thisConfig.AccessToken,
CommandTimeout = thisConfig.CommandTimeout,
AdminCommandTimeout = thisConfig.AdminCommandTimeout,
- Verbosity = LogLevel.Critical,
OutputPath = thisConfig.OutputPath.CreateSubdirectory("grate-internal"),
Baseline = baseline,
diff --git a/src/grate.core/Migration/IDbMigrator.cs b/src/grate.core/Migration/IDbMigrator.cs
index c8215fcd..1979e519 100644
--- a/src/grate.core/Migration/IDbMigrator.cs
+++ b/src/grate.core/Migration/IDbMigrator.cs
@@ -1,5 +1,6 @@
using grate.Configuration;
using grate.Infrastructure;
+using Microsoft.Extensions.Logging;
namespace grate.Migration;
@@ -7,6 +8,7 @@ internal interface IDbMigrator : IAsyncDisposable, ICloneable
{
GrateConfiguration Configuration { get; set; }
IDatabase Database { get; set; }
+ ILogger Logger { get; set; }
Task InitializeConnections();
Task CreateDatabase();
diff --git a/src/grate.core/grate.core.csproj b/src/grate.core/grate.core.csproj
index 5d474ff0..e3a04f86 100644
--- a/src/grate.core/grate.core.csproj
+++ b/src/grate.core/grate.core.csproj
@@ -5,7 +5,7 @@
enable
grate
build$([System.DateTime]::UtcNow.ToString("O"))
-
+ false
diff --git a/src/grate.mariadb/grate.mariadb.csproj b/src/grate.mariadb/grate.mariadb.csproj
index 7120c6bf..5ea931fc 100644
--- a/src/grate.mariadb/grate.mariadb.csproj
+++ b/src/grate.mariadb/grate.mariadb.csproj
@@ -3,6 +3,7 @@
$(NetTargetFrameworks)
enable
+ false
diff --git a/src/grate.oracle/grate.oracle.csproj b/src/grate.oracle/grate.oracle.csproj
index ec0e3992..e1a9f899 100644
--- a/src/grate.oracle/grate.oracle.csproj
+++ b/src/grate.oracle/grate.oracle.csproj
@@ -3,6 +3,7 @@
$(NetTargetFrameworks)
enable
+ false
diff --git a/src/grate.postgresql/grate.postgresql.csproj b/src/grate.postgresql/grate.postgresql.csproj
index 01a463c3..30e63ecc 100644
--- a/src/grate.postgresql/grate.postgresql.csproj
+++ b/src/grate.postgresql/grate.postgresql.csproj
@@ -3,6 +3,7 @@
$(NetTargetFrameworks)
enable
+ false
diff --git a/src/grate.sqlite/grate.sqlite.csproj b/src/grate.sqlite/grate.sqlite.csproj
index 1c392d20..d2faea6f 100644
--- a/src/grate.sqlite/grate.sqlite.csproj
+++ b/src/grate.sqlite/grate.sqlite.csproj
@@ -3,6 +3,7 @@
$(NetTargetFrameworks)
enable
+ false
diff --git a/src/grate.sqlserver/grate.sqlserver.csproj b/src/grate.sqlserver/grate.sqlserver.csproj
index 5f39ec3b..94e02a1b 100644
--- a/src/grate.sqlserver/grate.sqlserver.csproj
+++ b/src/grate.sqlserver/grate.sqlserver.csproj
@@ -3,6 +3,7 @@
$(NetTargetFrameworks)
enable
+ false
diff --git a/src/grate/Configuration/CommandLineGrateConfiguration.cs b/src/grate/Configuration/CommandLineGrateConfiguration.cs
index 3b8c7601..2b0fe674 100644
--- a/src/grate/Configuration/CommandLineGrateConfiguration.cs
+++ b/src/grate/Configuration/CommandLineGrateConfiguration.cs
@@ -1,3 +1,5 @@
+using Microsoft.Extensions.Logging;
+
namespace grate.Configuration;
internal record CommandLineGrateConfiguration : GrateConfiguration
@@ -6,5 +8,6 @@ internal record CommandLineGrateConfiguration : GrateConfiguration
/// Database type to use.
///
public DatabaseType DatabaseType { get; set; }
-
+
+ public LogLevel Verbosity { get; init; } = LogLevel.Information;
}
diff --git a/src/grate/Program.cs b/src/grate/Program.cs
index 36974ea3..9dd44319 100644
--- a/src/grate/Program.cs
+++ b/src/grate/Program.cs
@@ -125,6 +125,7 @@ private static ServiceProvider BuildServiceProvider(CommandLineGrateConfiguratio
options.FormatterName = GrateConsoleFormatter.FormatterName;
options.LogToStandardErrorThreshold = LogLevel.Warning;
})
+ .AddFilter("Grate.Migration.Internal", LogLevel.Critical)
.SetMinimumLevel(config.Verbosity)
.AddConsoleFormatter());
diff --git a/src/grate/grate.csproj b/src/grate/grate.csproj
index 9d4c834d..c5bd3653 100644
--- a/src/grate/grate.csproj
+++ b/src/grate/grate.csproj
@@ -66,7 +66,9 @@
-
+
+
+
diff --git a/unittests/Basic_tests/Basic_tests.csproj b/unittests/Basic_tests/Basic_tests.csproj
index 65370bca..bbd76904 100644
--- a/unittests/Basic_tests/Basic_tests.csproj
+++ b/unittests/Basic_tests/Basic_tests.csproj
@@ -6,6 +6,7 @@
enable
false
+ false
true
Basic_tests
diff --git a/unittests/Basic_tests/GrateMigrator_.cs b/unittests/Basic_tests/GrateMigrator_.cs
index 532e6c26..9226d5e6 100644
--- a/unittests/Basic_tests/GrateMigrator_.cs
+++ b/unittests/Basic_tests/GrateMigrator_.cs
@@ -1,4 +1,5 @@
-using FluentAssertions;
+using Basic_tests.Infrastructure;
+using FluentAssertions;
using grate.Configuration;
using grate.Infrastructure;
using grate.Migration;
@@ -10,43 +11,65 @@ namespace Basic_tests;
// ReSharper disable once InconsistentNaming
public class GrateMigrator_
{
- private IDatabase _database = Substitute.For();
- private GrateConfiguration? _config = new GrateConfiguration();
+ private readonly IDatabase _database = Substitute.For();
+ private readonly GrateConfiguration? _config = new GrateConfiguration();
[Fact]
public void Setting_the_config_does_not_change_the_original()
{
var config = new GrateConfiguration() { ConnectionString = "Server=server1" };
var dbMigrator = new DbMigrator(_database, null!, null!, config);
-
- var grateMigrator = new GrateMigrator(null!, dbMigrator);
-
+
+ var grateMigrator = new GrateMigrator(new MockGrateLoggerFactory(), dbMigrator);
+
grateMigrator.Configuration.Should().BeEquivalentTo(config);
-
+
var changedConfig = config with { ConnectionString = "Server=server2" };
var changedMigrator = grateMigrator.WithConfiguration(changedConfig);
-
+
grateMigrator.Configuration.ConnectionString.Should().Be("Server=server1");
changedMigrator.Configuration.ConnectionString.Should().Be("Server=server2");
}
-
+
[Fact]
public void Setting_the_Database_does_not_change_the_original()
{
_database.DatabaseName.Returns("server1");
var dbMigrator = new DbMigrator(_database, null!, null!, _config);
-
- var grateMigrator = new GrateMigrator(null!, dbMigrator);
-
+
+ var grateMigrator = new GrateMigrator(new MockGrateLoggerFactory(), dbMigrator);
+
grateMigrator.Database.DatabaseName.Should().Be("server1");
-
+
var changedDatabase = Substitute.For();
changedDatabase.DatabaseName.Returns("server2");
-
+
var changedMigrator = grateMigrator.WithDatabase(changedDatabase) as GrateMigrator;
grateMigrator.Database.DatabaseName.Should().Be("server1");
changedMigrator!.Database.DatabaseName.Should().Be("server2");
}
+ [Theory]
+ [MemberData(nameof(Environments))]
+ public void Logger_has_the_correct_LogCategory(GrateEnvironment environment, string logCategory)
+ {
+ var config = new GrateConfiguration() { Environment = environment };
+ var dbMigrator = new DbMigrator(_database, null!, null!, config);
+
+ var loggerFactory = Substitute.For();
+ _ = new GrateMigrator(loggerFactory, dbMigrator);
+
+ loggerFactory.Received().CreateLogger(logCategory);
+ }
+
+ public static TheoryData Environments() => new()
+ {
+ { GrateEnvironment.Internal, "Grate.Migration.Internal" },
+ { GrateEnvironment.InternalBootstrap, "Grate.Migration.Internal" },
+ { new GrateEnvironment("Development"), "Grate.Migration" },
+ { new GrateEnvironment("Test"), "Grate.Migration" },
+ { new GrateEnvironment("Production"), "Grate.Migration" },
+ };
+
}
diff --git a/unittests/Basic_tests/Infrastructure/MockDbMigrator.cs b/unittests/Basic_tests/Infrastructure/MockDbMigrator.cs
index 63990837..2f9b12f1 100644
--- a/unittests/Basic_tests/Infrastructure/MockDbMigrator.cs
+++ b/unittests/Basic_tests/Infrastructure/MockDbMigrator.cs
@@ -2,6 +2,7 @@
using grate.Infrastructure;
using grate.Migration;
using grate.Sqlite.Migration;
+using Microsoft.Extensions.Logging;
using NSubstitute;
namespace Basic_tests.Infrastructure;
@@ -14,6 +15,8 @@ public record MockDbMigrator: IDbMigrator
public GrateConfiguration Configuration { get; set; } = null!;
public IDatabase Database { get; set; } = Substitute.For();
+ public ILogger Logger { get; set; } = Substitute.For();
+
public Task InitializeConnections()
{
return Task.CompletedTask;
diff --git a/unittests/Basic_tests/Infrastructure/MockGrateLogger.cs b/unittests/Basic_tests/Infrastructure/MockGrateLogger.cs
index e2a424b5..b43b1d62 100644
--- a/unittests/Basic_tests/Infrastructure/MockGrateLogger.cs
+++ b/unittests/Basic_tests/Infrastructure/MockGrateLogger.cs
@@ -25,5 +25,28 @@ public bool IsEnabled(LogLevel logLevel)
}
public IList LoggedMessages { get; } = new List();
-
+}
+
+public record MockGrateLoggerFactory: ILoggerFactory
+{
+ private readonly MockGrateLogger _logger;
+
+ public MockGrateLoggerFactory(MockGrateLogger? logger = null)
+ {
+ _logger = logger ?? new MockGrateLogger();
+ }
+
+ public void Dispose()
+ {
+ }
+
+ public ILogger CreateLogger(string categoryName)
+ {
+ return _logger;
+ }
+
+ public void AddProvider(ILoggerProvider provider)
+ {
+ throw new NotImplementedException();
+ }
}
diff --git a/unittests/Basic_tests/Migration.cs b/unittests/Basic_tests/Migration.cs
index d33e9501..0731a478 100644
--- a/unittests/Basic_tests/Migration.cs
+++ b/unittests/Basic_tests/Migration.cs
@@ -9,17 +9,19 @@ namespace Basic_tests;
public class Migration
{
private readonly MockGrateLogger _logger;
+ private readonly MockGrateLoggerFactory _loggerFactory;
public Migration()
{
_logger = new MockGrateLogger();
+ _loggerFactory = new MockGrateLoggerFactory(_logger);
}
[Fact]
- public async Task Does_not_output_no_sql_run_in_dryrun_mode()
+ public async Task Does_not_output_qny_sql_run_in_dryrun_mode()
{
var dbMigrator = GetDbMigrator(true);
- var migrator = new GrateMigrator(_logger, dbMigrator);
+ var migrator = new GrateMigrator(_loggerFactory, dbMigrator);
await migrator.Migrate();
_logger.LoggedMessages.Should().NotContain(" No sql run, either an empty folder, or all files run against destination previously.");
}
@@ -28,7 +30,7 @@ public async Task Does_not_output_no_sql_run_in_dryrun_mode()
public async Task Outputs_no_sql_run_in_live_mode()
{
var dbMigrator = GetDbMigrator(false);
- var migrator = new GrateMigrator(_logger, dbMigrator);
+ var migrator = new GrateMigrator(_loggerFactory, dbMigrator);
await migrator.Migrate();
_logger.LoggedMessages.Should().Contain(" No sql run, either an empty folder, or all files run against destination previously.");
}
diff --git a/unittests/CommandLine/CommandLine.Common/CommandLine.Common.csproj b/unittests/CommandLine/CommandLine.Common/CommandLine.Common.csproj
index 9347f583..fc1fbc8a 100644
--- a/unittests/CommandLine/CommandLine.Common/CommandLine.Common.csproj
+++ b/unittests/CommandLine/CommandLine.Common/CommandLine.Common.csproj
@@ -5,6 +5,7 @@
enable
enable
+ false
false
false
diff --git a/unittests/CommandLine/CommandLine.MariaDB/CommandLine.MariaDB.csproj b/unittests/CommandLine/CommandLine.MariaDB/CommandLine.MariaDB.csproj
index 92070270..a162a899 100644
--- a/unittests/CommandLine/CommandLine.MariaDB/CommandLine.MariaDB.csproj
+++ b/unittests/CommandLine/CommandLine.MariaDB/CommandLine.MariaDB.csproj
@@ -5,6 +5,7 @@
enable
enable
+ false
false
true
diff --git a/unittests/CommandLine/CommandLine.Oracle/CommandLine.Oracle.csproj b/unittests/CommandLine/CommandLine.Oracle/CommandLine.Oracle.csproj
index b4e5ecb9..915d93e8 100644
--- a/unittests/CommandLine/CommandLine.Oracle/CommandLine.Oracle.csproj
+++ b/unittests/CommandLine/CommandLine.Oracle/CommandLine.Oracle.csproj
@@ -5,6 +5,7 @@
enable
enable
+ false
false
true
diff --git a/unittests/CommandLine/CommandLine.PostgreSQL/CommandLine.PostgreSQL.csproj b/unittests/CommandLine/CommandLine.PostgreSQL/CommandLine.PostgreSQL.csproj
index e524c1a5..841b2cf0 100644
--- a/unittests/CommandLine/CommandLine.PostgreSQL/CommandLine.PostgreSQL.csproj
+++ b/unittests/CommandLine/CommandLine.PostgreSQL/CommandLine.PostgreSQL.csproj
@@ -5,6 +5,7 @@
enable
enable
+ false
false
true
diff --git a/unittests/CommandLine/CommandLine.SqlServer/CommandLine.SqlServer.csproj b/unittests/CommandLine/CommandLine.SqlServer/CommandLine.SqlServer.csproj
index 5ac48ef8..773c17a8 100644
--- a/unittests/CommandLine/CommandLine.SqlServer/CommandLine.SqlServer.csproj
+++ b/unittests/CommandLine/CommandLine.SqlServer/CommandLine.SqlServer.csproj
@@ -5,6 +5,7 @@
enable
enable
+ false
false
true
diff --git a/unittests/CommandLine/CommandLine.Sqlite/CommandLine.Sqlite.csproj b/unittests/CommandLine/CommandLine.Sqlite/CommandLine.Sqlite.csproj
index bb81a62f..d4a2db5e 100644
--- a/unittests/CommandLine/CommandLine.Sqlite/CommandLine.Sqlite.csproj
+++ b/unittests/CommandLine/CommandLine.Sqlite/CommandLine.Sqlite.csproj
@@ -5,6 +5,7 @@
enable
enable
+ false
false
true
diff --git a/unittests/Docker/Docker.Common/Docker.Common.csproj b/unittests/Docker/Docker.Common/Docker.Common.csproj
index ceb8fca8..b83dab4b 100644
--- a/unittests/Docker/Docker.Common/Docker.Common.csproj
+++ b/unittests/Docker/Docker.Common/Docker.Common.csproj
@@ -5,6 +5,7 @@
enable
enable
+ false
false
false
diff --git a/unittests/Docker/Docker.Common/TestInfrastructure/DockerGrateMigrator.cs b/unittests/Docker/Docker.Common/TestInfrastructure/DockerGrateMigrator.cs
index 59a83b67..4597858f 100644
--- a/unittests/Docker/Docker.Common/TestInfrastructure/DockerGrateMigrator.cs
+++ b/unittests/Docker/Docker.Common/TestInfrastructure/DockerGrateMigrator.cs
@@ -108,7 +108,6 @@ public IGrateMigrator WithConfiguration(GrateConfiguration configuration)
// Need to overwrite the output path, as we don't have the same tmp folders on the host as in the container,
// and the root file system is read-only in the test container
OutputPath = new DirectoryInfo(Path.Combine("/tmp", "grate-tests-output", Directory.CreateTempSubdirectory().Name)),
- Verbosity = LogLevel.Debug
}
};
}
diff --git a/unittests/Docker/Docker.MariaDB/Docker.MariaDB.csproj b/unittests/Docker/Docker.MariaDB/Docker.MariaDB.csproj
index daf980d5..fd3f5944 100644
--- a/unittests/Docker/Docker.MariaDB/Docker.MariaDB.csproj
+++ b/unittests/Docker/Docker.MariaDB/Docker.MariaDB.csproj
@@ -5,6 +5,7 @@
enable
enable
+ false
false
true
diff --git a/unittests/Docker/Docker.Oracle/Docker.Oracle.csproj b/unittests/Docker/Docker.Oracle/Docker.Oracle.csproj
index e19627be..f2416bf4 100644
--- a/unittests/Docker/Docker.Oracle/Docker.Oracle.csproj
+++ b/unittests/Docker/Docker.Oracle/Docker.Oracle.csproj
@@ -5,6 +5,7 @@
enable
enable
+ false
false
true
diff --git a/unittests/Docker/Docker.PostgreSQL/Docker.PostgreSQL.csproj b/unittests/Docker/Docker.PostgreSQL/Docker.PostgreSQL.csproj
index fa2a1710..393b7474 100644
--- a/unittests/Docker/Docker.PostgreSQL/Docker.PostgreSQL.csproj
+++ b/unittests/Docker/Docker.PostgreSQL/Docker.PostgreSQL.csproj
@@ -5,6 +5,7 @@
enable
enable
+ false
false
true
diff --git a/unittests/Docker/Docker.SqlServer/Docker.SqlServer.csproj b/unittests/Docker/Docker.SqlServer/Docker.SqlServer.csproj
index daa4f49b..a06d9df3 100644
--- a/unittests/Docker/Docker.SqlServer/Docker.SqlServer.csproj
+++ b/unittests/Docker/Docker.SqlServer/Docker.SqlServer.csproj
@@ -5,6 +5,7 @@
enable
enable
+ false
false
true
diff --git a/unittests/Docker/Docker.Sqlite/Docker.Sqlite.csproj b/unittests/Docker/Docker.Sqlite/Docker.Sqlite.csproj
index ceb02f9d..4ec396a7 100644
--- a/unittests/Docker/Docker.Sqlite/Docker.Sqlite.csproj
+++ b/unittests/Docker/Docker.Sqlite/Docker.Sqlite.csproj
@@ -5,6 +5,7 @@
enable
enable
+ false
false
true
diff --git a/unittests/MariaDB/MariaDB.csproj b/unittests/MariaDB/MariaDB.csproj
index e26a694f..b7a60bfa 100644
--- a/unittests/MariaDB/MariaDB.csproj
+++ b/unittests/MariaDB/MariaDB.csproj
@@ -1,22 +1,24 @@
- net8.0
- enable
- enable
+ net8.0
+ enable
+ enable
- false
+ true
+ false
+ false
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
diff --git a/unittests/Oracle/Oracle.csproj b/unittests/Oracle/Oracle.csproj
index 5757d832..e5b720a1 100644
--- a/unittests/Oracle/Oracle.csproj
+++ b/unittests/Oracle/Oracle.csproj
@@ -1,11 +1,13 @@
- net8.0
- enable
- enable
+ net8.0
+ enable
+ enable
- false
+ true
+ false
+ false
diff --git a/unittests/Oracle/TestInfrastructure/OracleGrateTestContext.cs b/unittests/Oracle/TestInfrastructure/OracleGrateTestContext.cs
index 9e8eeacc..4ac9084a 100644
--- a/unittests/Oracle/TestInfrastructure/OracleGrateTestContext.cs
+++ b/unittests/Oracle/TestInfrastructure/OracleGrateTestContext.cs
@@ -1,4 +1,5 @@
using System.Data;
+using System.Diagnostics.CodeAnalysis;
using Docker.DotNet.Models;
using grate.Infrastructure;
using grate.Migration;
diff --git a/unittests/PostgreSQL/PostgreSQL.csproj b/unittests/PostgreSQL/PostgreSQL.csproj
index 24604fba..f1c9528e 100644
--- a/unittests/PostgreSQL/PostgreSQL.csproj
+++ b/unittests/PostgreSQL/PostgreSQL.csproj
@@ -1,11 +1,13 @@
- net8.0
- enable
- enable
+ net8.0
+ enable
+ enable
- false
+ true
+ false
+ false
diff --git a/unittests/SqlServer/SqlServer.csproj b/unittests/SqlServer/SqlServer.csproj
index 33f5ccc0..c5c043be 100644
--- a/unittests/SqlServer/SqlServer.csproj
+++ b/unittests/SqlServer/SqlServer.csproj
@@ -1,14 +1,16 @@
- net8.0
- enable
- enable
+ net8.0
+ enable
+ enable
- false
+ true
+ false
+ false
-
+
@@ -17,7 +19,7 @@
-
+
diff --git a/unittests/SqlServer/TestInfrastructure/SqlServerGrateTestContext.cs b/unittests/SqlServer/TestInfrastructure/SqlServerGrateTestContext.cs
index 732c5057..49893c2e 100644
--- a/unittests/SqlServer/TestInfrastructure/SqlServerGrateTestContext.cs
+++ b/unittests/SqlServer/TestInfrastructure/SqlServerGrateTestContext.cs
@@ -1,4 +1,5 @@
using System.Data;
+using System.Diagnostics.CodeAnalysis;
using grate.Infrastructure;
using grate.Migration;
using grate.SqlServer.Infrastructure;
diff --git a/unittests/SqlServerCaseSensitive/SqlServerCaseSensitive.csproj b/unittests/SqlServerCaseSensitive/SqlServerCaseSensitive.csproj
index 33f5ccc0..fe3d7495 100644
--- a/unittests/SqlServerCaseSensitive/SqlServerCaseSensitive.csproj
+++ b/unittests/SqlServerCaseSensitive/SqlServerCaseSensitive.csproj
@@ -1,11 +1,13 @@
- net8.0
- enable
- enable
+ net8.0
+ enable
+ enable
- false
+ true
+ false
+ false
diff --git a/unittests/Sqlite/Sqlite.csproj b/unittests/Sqlite/Sqlite.csproj
index fe1ec155..f4daa195 100644
--- a/unittests/Sqlite/Sqlite.csproj
+++ b/unittests/Sqlite/Sqlite.csproj
@@ -1,11 +1,13 @@
- net8.0
- enable
- enable
+ net8.0
+ enable
+ enable
- false
+ true
+ false
+ false
diff --git a/unittests/TestCommon/Startup.cs b/unittests/TestCommon/Startup.cs
index 77de9c7f..a43abc79 100644
--- a/unittests/TestCommon/Startup.cs
+++ b/unittests/TestCommon/Startup.cs
@@ -1,10 +1,12 @@
+using System.Diagnostics.CodeAnalysis;
using DotNet.Testcontainers.Builders;
-using grate.Configuration;
+using grate.Infrastructure;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Logging.Console;
using TestCommon.TestInfrastructure;
namespace TestCommon;
@@ -23,7 +25,13 @@ public void ConfigureServices(IServiceCollection services, HostBuilderContext co
services.AddLogging(
lb => lb
.AddXUnit()
- .AddConsole()
+ .AddConsole(options =>
+ {
+ options.FormatterName = GrateConsoleFormatter.FormatterName;
+ options.LogToStandardErrorThreshold = LogLevel.Critical;
+ })
+ .AddFilter("Grate.Migration.Internal", LogLevel.Critical)
+ .AddConsoleFormatter()
.SetMinimumLevel(TestConfig.GetLogLevel())
);
@@ -38,8 +46,13 @@ public void ConfigureServices(IServiceCollection services, HostBuilderContext co
RegisterTestDatabase(services, context.Configuration);
}
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
protected abstract Type TestContainerDatabaseType { get; }
+
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
protected abstract Type ExternalTestDatabaseType { get; }
+
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
protected abstract Type TestContextType { get; }
// ReSharper disable once UnassignedGetOnlyAutoProperty
diff --git a/unittests/TestCommon/Startup_T.cs b/unittests/TestCommon/Startup_T.cs
index dc3aac2e..affd8331 100644
--- a/unittests/TestCommon/Startup_T.cs
+++ b/unittests/TestCommon/Startup_T.cs
@@ -1,16 +1,22 @@
+using System.Diagnostics.CodeAnalysis;
using TestCommon.TestInfrastructure;
namespace TestCommon;
public abstract class Startup<
- TTestContainerDatabase,
- TExternalDatabase,
- TGrateTestContext>: Startup
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TTestContainerDatabase,
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TExternalDatabase,
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TGrateTestContext>: Startup
where TTestContainerDatabase : ITestDatabase
where TExternalDatabase : ITestDatabase
where TGrateTestContext : IGrateTestContext
{
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
protected override Type TestContainerDatabaseType => typeof(TTestContainerDatabase);
+
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
protected override Type ExternalTestDatabaseType => typeof(TExternalDatabase);
+
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
protected override Type TestContextType => typeof(TGrateTestContext);
}
diff --git a/unittests/TestCommon/TestCommon.csproj b/unittests/TestCommon/TestCommon.csproj
index 4b481bbd..9ef4c946 100644
--- a/unittests/TestCommon/TestCommon.csproj
+++ b/unittests/TestCommon/TestCommon.csproj
@@ -5,7 +5,9 @@
enable
enable
false
+ false
false
+ IL2072;IL2075;IL2026
diff --git a/unittests/TestCommon/TestInfrastructure/GrateTestContext.cs b/unittests/TestCommon/TestInfrastructure/GrateTestContext.cs
index dceee4d6..472ec186 100644
--- a/unittests/TestCommon/TestInfrastructure/GrateTestContext.cs
+++ b/unittests/TestCommon/TestInfrastructure/GrateTestContext.cs
@@ -1,4 +1,5 @@
using System.Data;
+using System.Diagnostics.CodeAnalysis;
using Dapper;
using grate.Infrastructure;
using grate.Migration;
@@ -41,7 +42,9 @@ public async Task DropDatabase(string databaseName)
public abstract ISyntax Syntax { get; }
public abstract Type DbExceptionType { get; }
+
public abstract Type DatabaseType { get; }
+
public abstract bool SupportsTransaction { get; }
public abstract SqlStatements Sql { get; }
public abstract string ExpectedVersionPrefix { get; }
diff --git a/unittests/TestCommon/TestInfrastructure/IGrateTestContext.cs b/unittests/TestCommon/TestInfrastructure/IGrateTestContext.cs
index 36e1fe0e..4edc5d9d 100644
--- a/unittests/TestCommon/TestInfrastructure/IGrateTestContext.cs
+++ b/unittests/TestCommon/TestInfrastructure/IGrateTestContext.cs
@@ -1,4 +1,5 @@
using System.Data;
+using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using grate.Configuration;
using grate.Infrastructure;