diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cb6841bc..f2c57794 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -85,10 +85,14 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Setup .NET 9 + - name: Setup .NET 9 and earlier uses: actions/setup-dotnet@v4 with: - dotnet-version: 9.0.x + dotnet-version: | + 6.0.x + 7.0.x + 8.0.x + 9.0.x - name: Restore dependencies run: dotnet restore @@ -121,9 +125,10 @@ jobs: dotnet-version: 9.0.x - name: Publish self-contained ${{ matrix.arch }} - run: dotnet publish ./src/grate/grate.csproj -f net9.0 -r ${{ matrix.arch }} -c release --self-contained -p:SelfContained=true -o ./publish/${{ matrix.arch }}/self-contained + run: dotnet publish ./src/grate/grate.csproj -r ${{ matrix.arch }} -c release --self-contained -p:SelfContained=true -o ./publish/${{ matrix.arch }}/self-contained env: VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }} + TargetFramework: net9.0 - name: Upload self-contained ${{ matrix.arch }} @@ -157,9 +162,10 @@ jobs: dotnet-version: 9.0.x - name: Publish self-contained ${{ matrix.arch }} - run: dotnet publish ./src/grate/grate.csproj -f net9.0 -r ${{ matrix.arch }} -c release --self-contained -p:SelfContained=true -o ./publish/${{ matrix.arch }}/self-contained + run: dotnet publish ./src/grate/grate.csproj -r ${{ matrix.arch }} -c release --self-contained -p:SelfContained=true -o ./publish/${{ matrix.arch }}/self-contained env: VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }} + TargetFramework: net9.0 - name: Upload self-contained ${{ matrix.arch }} #if: ${{ needs.set-version-number.outputs.is-release == 'true' }} @@ -294,10 +300,14 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Setup .NET 9 + - name: Setup .NET 9 and earlier uses: actions/setup-dotnet@v4 with: - dotnet-version: 9.0.x + dotnet-version: | + 6.0.x + 7.0.x + 8.0.x + 9.0.x - name: Test run: > dotnet test diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b27f6718..cc54beb6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,15 +21,19 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Setup .NET 9 + - name: Setup .NET 9 and earlier uses: actions/setup-dotnet@v4 with: - dotnet-version: 9.0.x + dotnet-version: | + 6.0.x + 7.0.x + 8.0.x + 9.0.x - name: Restore dependencies run: | dotnet restore -r linux-x64 grate.sln - name: Build - run: dotnet build -f net9.0 --no-restore --no-self-contained -r linux-x64 src/grate/grate.csproj -c release + run: dotnet build --no-restore --no-self-contained -r linux-x64 src/grate/grate.csproj -c release analyze: @@ -44,7 +48,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Setup .NET 9 + - name: Setup .NET 9 and earlier uses: actions/setup-dotnet@v4 with: dotnet-version: | @@ -79,7 +83,11 @@ jobs: - name: Setup .NET 9 uses: actions/setup-dotnet@v4 with: - dotnet-version: 9.0.x + dotnet-version: | + 6.0.x + 7.0.x + 8.0.x + 9.0.x - name: Test run: | dotnet test \ diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 396de91a..70110550 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -70,9 +70,10 @@ jobs: dotnet-version: 9.0.x - name: Publish self-contained ${{ matrix.arch }} - run: dotnet publish ./src/grate/grate.csproj -f net9.0 -r ${{ matrix.arch }} -c release --self-contained -p:SelfContained=true -o ./publish/${{ matrix.arch }}/self-contained + run: dotnet publish ./src/grate/grate.csproj -r ${{ matrix.arch }} -c release --self-contained -p:SelfContained=true -o ./publish/${{ matrix.arch }}/self-contained env: VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }} + TargetFramework: net9.0 - name: Upload self-contained ${{ matrix.arch }} uses: actions/upload-artifact@v4 @@ -104,9 +105,10 @@ jobs: dotnet-version: 9.0.x - name: Publish self-contained ${{ matrix.arch }} - run: dotnet publish ./src/grate/grate.csproj -f net9.0 -r ${{ matrix.arch }} -c release --self-contained -p:SelfContained=true -o ./publish/${{ matrix.arch }}/self-contained + run: dotnet publish ./src/grate/grate.csproj -r ${{ matrix.arch }} -c release --self-contained -p:SelfContained=true -o ./publish/${{ matrix.arch }}/self-contained env: VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }} + TargetFramework: net9.0 - name: Upload self-contained ${{ matrix.arch }} uses: actions/upload-artifact@v4 @@ -130,12 +132,16 @@ jobs: - name: Setup .NET 9 uses: actions/setup-dotnet@v4 with: - dotnet-version: 9.0.x + dotnet-version: | + 6.0.x + 7.0.x + 8.0.x + 9.0.x - name: Build Test DLLs ${{ matrix.arch }} run: | dotnet restore -r ${{ matrix.arch }} unittests/UnitTests.slnf - dotnet publish -f net9.0 -r ${{ matrix.arch }} -c release --no-restore ./unittests/UnitTests.slnf -o ./integration-tests/${{ matrix.arch }} + dotnet publish -r ${{ matrix.arch }} -c release --no-restore ./unittests/UnitTests.slnf -o ./integration-tests/${{ matrix.arch }} env: VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }} @@ -158,15 +164,17 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Setup .NET 9 + - name: Setup .NET 8 & 9 uses: actions/setup-dotnet@v4 with: - dotnet-version: 9.0.x + dotnet-version: | + 8.0.x + 9.0.x - name: Build Test DLLs ${{ matrix.arch }} run: | dotnet restore -r ${{ matrix.arch }} unittests/UnitTests.slnf - dotnet publish -f net9.0 -r ${{ matrix.arch }} -c release --no-restore ./unittests/UnitTests.slnf -o ./integration-tests/${{ matrix.arch }} + dotnet publish -r ${{ matrix.arch }} -c release --no-restore ./unittests/UnitTests.slnf -o ./integration-tests/${{ matrix.arch }} env: VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }} diff --git a/Directory.Build.props b/Directory.Build.props index ce394e13..07cdbf35 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -21,10 +21,12 @@ - net9.0 - - net6.0;net7.0;net8.0;net9.0 - + net6.0;net7.0;net8.0;net9.0 + + + + true + $(NoWarn);NETSDK1138 diff --git a/Directory.Packages.props b/Directory.Packages.props index 89275ca0..9c495ddf 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,4 +1,9 @@ + + true + true + + diff --git a/src/grate.core/grate.core.csproj b/src/grate.core/grate.core.csproj index e3a04f86..35a377c7 100644 --- a/src/grate.core/grate.core.csproj +++ b/src/grate.core/grate.core.csproj @@ -1,7 +1,6 @@ - $(NetTargetFrameworks) enable grate build$([System.DateTime]::UtcNow.ToString("O")) diff --git a/src/grate.mariadb/grate.mariadb.csproj b/src/grate.mariadb/grate.mariadb.csproj index 5ea931fc..4eb33381 100644 --- a/src/grate.mariadb/grate.mariadb.csproj +++ b/src/grate.mariadb/grate.mariadb.csproj @@ -1,7 +1,6 @@ - $(NetTargetFrameworks) enable false diff --git a/src/grate.oracle/grate.oracle.csproj b/src/grate.oracle/grate.oracle.csproj index e1a9f899..4bc12cd7 100644 --- a/src/grate.oracle/grate.oracle.csproj +++ b/src/grate.oracle/grate.oracle.csproj @@ -1,7 +1,6 @@ - $(NetTargetFrameworks) enable false diff --git a/src/grate.postgresql/grate.postgresql.csproj b/src/grate.postgresql/grate.postgresql.csproj index 30e63ecc..21675484 100644 --- a/src/grate.postgresql/grate.postgresql.csproj +++ b/src/grate.postgresql/grate.postgresql.csproj @@ -1,7 +1,6 @@ - $(NetTargetFrameworks) enable false diff --git a/src/grate.sqlite/grate.sqlite.csproj b/src/grate.sqlite/grate.sqlite.csproj index d2faea6f..b5a30faa 100644 --- a/src/grate.sqlite/grate.sqlite.csproj +++ b/src/grate.sqlite/grate.sqlite.csproj @@ -1,7 +1,6 @@ - $(NetTargetFrameworks) enable false diff --git a/src/grate.sqlserver/grate.sqlserver.csproj b/src/grate.sqlserver/grate.sqlserver.csproj index 94e02a1b..0452d68b 100644 --- a/src/grate.sqlserver/grate.sqlserver.csproj +++ b/src/grate.sqlserver/grate.sqlserver.csproj @@ -1,7 +1,6 @@ - $(NetTargetFrameworks) enable false diff --git a/src/grate/grate.csproj b/src/grate/grate.csproj index ddf6df7f..319ebe3e 100644 --- a/src/grate/grate.csproj +++ b/src/grate/grate.csproj @@ -2,7 +2,6 @@ Exe - $(TargetFramework) Embedded enable diff --git a/unittests/Basic_tests/Basic_tests.csproj b/unittests/Basic_tests/Basic_tests.csproj index 5e9311d0..c1ab16da 100644 --- a/unittests/Basic_tests/Basic_tests.csproj +++ b/unittests/Basic_tests/Basic_tests.csproj @@ -1,7 +1,6 @@ - $(TargetFramework) enable enable diff --git a/unittests/Basic_tests/CommandLineParsing/Basic_CommandLineParsing.cs b/unittests/Basic_tests/CommandLineParsing/Basic_CommandLineParsing.cs index 85085ba7..b7596ae6 100644 --- a/unittests/Basic_tests/CommandLineParsing/Basic_CommandLineParsing.cs +++ b/unittests/Basic_tests/CommandLineParsing/Basic_CommandLineParsing.cs @@ -9,6 +9,12 @@ using grate.Exceptions; using grate.Infrastructure; +#if NET6_0 +using Dir = TestCommon.TestInfrastructure.Net6PolyFills.Directory; +#else +using Dir = System.IO.Directory; +#endif + namespace Basic_tests.CommandLineParsing; // ReSharper disable once InconsistentNaming @@ -71,7 +77,7 @@ public async Task AdminConnectionString(string argName) [InlineData("--sqlfilesdirectory=")] public async Task SqlFilesDirectory(string argName) { - var folder = Directory.CreateTempSubdirectory(); + var folder = Dir.CreateTempSubdirectory(); var commandline = argName + folder; var cfg = await ParseGrateConfiguration(commandline); diff --git a/unittests/Basic_tests/GrateMigrator_MigrationStatus/IsUpToDate_.cs b/unittests/Basic_tests/GrateMigrator_MigrationStatus/IsUpToDate_.cs index 9efc977b..20b31ef4 100644 --- a/unittests/Basic_tests/GrateMigrator_MigrationStatus/IsUpToDate_.cs +++ b/unittests/Basic_tests/GrateMigrator_MigrationStatus/IsUpToDate_.cs @@ -5,12 +5,18 @@ using grate.Migration; using NSubstitute; +#if NET6_0 +using Dir = TestCommon.TestInfrastructure.Net6PolyFills.Directory; +#else +using Dir = System.IO.Directory; +#endif + namespace Basic_tests.GrateMigrator_MigrationStatus; // ReSharper disable once InconsistentNaming public class IsUpToDate_: IDisposable { - private static readonly DirectoryInfo SqlFilesDirectory = Directory.CreateTempSubdirectory(); + private static readonly DirectoryInfo SqlFilesDirectory = Dir.CreateTempSubdirectory(); [Theory] [InlineData(true)] diff --git a/unittests/Basic_tests/GrateMigrator_MigrationStatus/MigrationStatus_.cs b/unittests/Basic_tests/GrateMigrator_MigrationStatus/MigrationStatus_.cs index 0e05955f..1320779f 100644 --- a/unittests/Basic_tests/GrateMigrator_MigrationStatus/MigrationStatus_.cs +++ b/unittests/Basic_tests/GrateMigrator_MigrationStatus/MigrationStatus_.cs @@ -5,12 +5,18 @@ using grate.Migration; using NSubstitute; +#if NET6_0 +using Dir = TestCommon.TestInfrastructure.Net6PolyFills.Directory; +#else +using Dir = System.IO.Directory; +#endif + namespace Basic_tests.GrateMigrator_MigrationStatus; // ReSharper disable once InconsistentNaming public class MigrationStatus_: IDisposable { - private static readonly DirectoryInfo SqlFilesDirectory = Directory.CreateTempSubdirectory(); + private static readonly DirectoryInfo SqlFilesDirectory = Dir.CreateTempSubdirectory(); [Fact] public async Task Includes_list_of_ScriptsRun() diff --git a/unittests/Basic_tests/Infrastructure/MockDatabase.cs b/unittests/Basic_tests/Infrastructure/MockDatabase.cs new file mode 100644 index 00000000..d126af6f --- /dev/null +++ b/unittests/Basic_tests/Infrastructure/MockDatabase.cs @@ -0,0 +1,66 @@ +using System.Data.Common; +using grate.Configuration; +using grate.Migration; +using Microsoft.Extensions.Logging; + +namespace Basic_tests.Infrastructure; + +public record MockDatabase : IDatabase +{ + public ValueTask DisposeAsync() => ValueTask.CompletedTask; + + object ICloneable.Clone() => this with { }; + + public string? ServerName { get; set; } + public string? DatabaseName { get; set; } + public string DatabaseType { get; } = "Mock"; + public string MasterDatabaseName { get; } = "Mock"; + public bool SupportsDdlTransactions { get; set; } + public bool SplitBatchStatements { get; set; } + public string ScriptsRunTable { get; } = "ScriptsRun"; + public string ScriptsRunErrorsTable { get; } = "ScriptsRunErrors"; + public string VersionTable { get; } = "Version"; + public DbConnection ActiveConnection { get; set; } = null!; + public bool SupportsSchemas { get; set; } + public Task InitializeConnections(GrateConfiguration configuration) => Task.CompletedTask; + + public Task OpenConnection() => Task.CompletedTask; + public Task CloseConnection() => Task.CompletedTask; + public Task OpenAdminConnection() => Task.CompletedTask; + public Task CloseAdminConnection() => Task.CompletedTask; + public Task CreateDatabase() => Task.CompletedTask; + public Task RestoreDatabase(string backupPath) => Task.CompletedTask; + public void SetLogger(ILogger logger) { } + public Task DropDatabase() => Task.CompletedTask; + public Task DatabaseExists() => Task.FromResult(false); + public Task GetCurrentVersion() => Task.FromResult(string.Empty); + public Task VersionTheDatabase(string newVersion) => Task.FromResult(0L); + public void Rollback() { } + + public Task RunSql(string sql, ConnectionType connectionType, TransactionHandling transactionHandling) => Task.CompletedTask; + public Task GetCurrentHash(string scriptName) => Task.FromResult(string.Empty)!; + public Task HasRun(string scriptName, TransactionHandling transactionHandling) => Task.FromResult(false); + public Task InsertScriptRun(string scriptName, string? sql, string hash, bool runOnce, long versionId, + TransactionHandling transactionHandling) => Task.CompletedTask; + + public Task InsertScriptRunError(string scriptName, string? sql, string errorSql, string errorMessage, long versionId) => Task.CompletedTask; + + public Task VersionTableExists() => Task.FromResult(false); + + public Task GrateInternalTablesAreProperlyLogged() => Task.FromResult(false); + + public Task ChangeVersionStatus(string status, long versionId) => Task.CompletedTask; + + public Task DeleteVersionRecord(long versionId) => Task.CompletedTask; + + public void SetDefaultConnectionActive() { } + + public Task OpenNewActiveConnection() => Task.FromResult(new HttpClient()); + + public Task OpenActiveConnection() => Task.CompletedTask; + public Task ExistingTable(string schemaName, string tableName) => Task.FromResult(string.Empty)!; + + public IEnumerable GetStatements(string sql) => new List(); + public void ThrowScriptFailed(MigrationsFolder folder, string file, string? scriptText, Exception exception) { } + +} diff --git a/unittests/Basic_tests/Infrastructure/MockDbMigrator.cs b/unittests/Basic_tests/Infrastructure/MockDbMigrator.cs index e46d1a39..4a377ce3 100644 --- a/unittests/Basic_tests/Infrastructure/MockDbMigrator.cs +++ b/unittests/Basic_tests/Infrastructure/MockDbMigrator.cs @@ -14,7 +14,11 @@ public record MockDbMigrator: IDbMigrator object ICloneable.Clone() => this with { }; public GrateConfiguration Configuration { get; set; } = null!; - public IDatabase Database { get; set; } = Substitute.For(); + + public IDatabase Database { get; set; } = new MockDatabase(); + // This doesn't work in .NET 6 - so we must create an explicit implementation of IDatabase + //public IDatabase Database { get; set; } = Substitute.For(); + public ILogger Logger { get; set; } = Substitute.For(); public Task InitializeConnections() diff --git a/unittests/CommandLine/CommandLine.Common/CommandLine.Common.csproj b/unittests/CommandLine/CommandLine.Common/CommandLine.Common.csproj index d1e4daf7..596401d5 100644 --- a/unittests/CommandLine/CommandLine.Common/CommandLine.Common.csproj +++ b/unittests/CommandLine/CommandLine.Common/CommandLine.Common.csproj @@ -1,7 +1,6 @@ - $(TargetFramework) enable enable diff --git a/unittests/CommandLine/CommandLine.Common/TestInfrastructure/CommandLineGrateMigrator.cs b/unittests/CommandLine/CommandLine.Common/TestInfrastructure/CommandLineGrateMigrator.cs index 4ed7c097..ecf9ce8e 100644 --- a/unittests/CommandLine/CommandLine.Common/TestInfrastructure/CommandLineGrateMigrator.cs +++ b/unittests/CommandLine/CommandLine.Common/TestInfrastructure/CommandLineGrateMigrator.cs @@ -22,8 +22,13 @@ public async Task Migrate() // Add the database type commandLineArguments.Add("--databasetype=" + DatabaseType.ToString().ToLowerInvariant()); + // Run the command-line tool with the arguments + #if NET8_0_OR_GREATER var processInfo = new ProcessStartInfo(GrateExecutable, commandLineArguments) + #else + var processInfo = new ProcessStartInfo(GrateExecutable, string.Join(' ', commandLineArguments)) + #endif { RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, }; diff --git a/unittests/CommandLine/CommandLine.MariaDB/CommandLine.MariaDB.csproj b/unittests/CommandLine/CommandLine.MariaDB/CommandLine.MariaDB.csproj index 8736abf5..4d2c9227 100644 --- a/unittests/CommandLine/CommandLine.MariaDB/CommandLine.MariaDB.csproj +++ b/unittests/CommandLine/CommandLine.MariaDB/CommandLine.MariaDB.csproj @@ -1,7 +1,6 @@ - $(TargetFramework) enable enable diff --git a/unittests/CommandLine/CommandLine.Oracle/CommandLine.Oracle.csproj b/unittests/CommandLine/CommandLine.Oracle/CommandLine.Oracle.csproj index 39748140..fe391f9e 100644 --- a/unittests/CommandLine/CommandLine.Oracle/CommandLine.Oracle.csproj +++ b/unittests/CommandLine/CommandLine.Oracle/CommandLine.Oracle.csproj @@ -1,7 +1,6 @@ - $(TargetFramework) enable enable diff --git a/unittests/CommandLine/CommandLine.PostgreSQL/CommandLine.PostgreSQL.csproj b/unittests/CommandLine/CommandLine.PostgreSQL/CommandLine.PostgreSQL.csproj index 8d0c29c5..86e0e241 100644 --- a/unittests/CommandLine/CommandLine.PostgreSQL/CommandLine.PostgreSQL.csproj +++ b/unittests/CommandLine/CommandLine.PostgreSQL/CommandLine.PostgreSQL.csproj @@ -1,7 +1,6 @@ - $(TargetFramework) enable enable diff --git a/unittests/CommandLine/CommandLine.SqlServer/CommandLine.SqlServer.csproj b/unittests/CommandLine/CommandLine.SqlServer/CommandLine.SqlServer.csproj index 7266f408..7f4647f0 100644 --- a/unittests/CommandLine/CommandLine.SqlServer/CommandLine.SqlServer.csproj +++ b/unittests/CommandLine/CommandLine.SqlServer/CommandLine.SqlServer.csproj @@ -1,7 +1,6 @@ - $(TargetFramework) enable enable diff --git a/unittests/CommandLine/CommandLine.Sqlite/CommandLine.Sqlite.csproj b/unittests/CommandLine/CommandLine.Sqlite/CommandLine.Sqlite.csproj index 08497588..96c00293 100644 --- a/unittests/CommandLine/CommandLine.Sqlite/CommandLine.Sqlite.csproj +++ b/unittests/CommandLine/CommandLine.Sqlite/CommandLine.Sqlite.csproj @@ -1,7 +1,6 @@ - $(TargetFramework) enable enable diff --git a/unittests/Docker/Docker.Common/Docker.Common.csproj b/unittests/Docker/Docker.Common/Docker.Common.csproj index 34ed4b52..b16c5fd4 100644 --- a/unittests/Docker/Docker.Common/Docker.Common.csproj +++ b/unittests/Docker/Docker.Common/Docker.Common.csproj @@ -1,7 +1,6 @@ - $(TargetFramework) enable enable diff --git a/unittests/Docker/Docker.Common/TestInfrastructure/DockerGrateMigrator.cs b/unittests/Docker/Docker.Common/TestInfrastructure/DockerGrateMigrator.cs index d900de56..55b6d8ad 100644 --- a/unittests/Docker/Docker.Common/TestInfrastructure/DockerGrateMigrator.cs +++ b/unittests/Docker/Docker.Common/TestInfrastructure/DockerGrateMigrator.cs @@ -9,6 +9,12 @@ using grate.Migration; using Microsoft.Extensions.Logging; +#if NET6_0 +using Dir = TestCommon.TestInfrastructure.Net6PolyFills.Directory; +#else +using Dir = System.IO.Directory; +#endif + namespace Docker.Common.TestInfrastructure; public record DockerGrateMigrator( @@ -29,7 +35,7 @@ public async Task Migrate() // if not, we get an error like this: // /home/app/.net/grate/fdcA3gxdjBiIcVt0mGoBJ5IgxSbD0kE=/libe_sqlite3.so: failed to map segment from shared object // (similarly) /tmp/dotnet-bundle-extract/grate/fdcA3gxdjBiIcVt0mGoBJ5IgxSbD0kE=/libe_sqlite3.so: failed to map segment from shared object - var tmpFolder = Directory.CreateTempSubdirectory().ToString(); + var tmpFolder = Dir.CreateTempSubdirectory().ToString(); // Need to map the SQL files directory to the container var sqlFilesDirectory = Configuration.SqlFilesDirectory.ToString(); @@ -138,7 +144,7 @@ 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)), + OutputPath = new DirectoryInfo(Path.Combine("/tmp", "grate-tests-output", Dir.CreateTempSubdirectory().Name)), } }; } @@ -151,7 +157,7 @@ public IGrateMigrator WithConfiguration(Action builde { // 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)) + OutputPath = new DirectoryInfo(Path.Combine("/tmp", "grate-tests-output", Dir.CreateTempSubdirectory().Name)) }}; } diff --git a/unittests/Docker/Docker.MariaDB/Docker.MariaDB.csproj b/unittests/Docker/Docker.MariaDB/Docker.MariaDB.csproj index 5435c304..cb1db8b6 100644 --- a/unittests/Docker/Docker.MariaDB/Docker.MariaDB.csproj +++ b/unittests/Docker/Docker.MariaDB/Docker.MariaDB.csproj @@ -1,7 +1,6 @@ - $(TargetFramework) enable enable diff --git a/unittests/Docker/Docker.Oracle/Docker.Oracle.csproj b/unittests/Docker/Docker.Oracle/Docker.Oracle.csproj index 0d76a6c2..879e8708 100644 --- a/unittests/Docker/Docker.Oracle/Docker.Oracle.csproj +++ b/unittests/Docker/Docker.Oracle/Docker.Oracle.csproj @@ -1,7 +1,6 @@ - $(TargetFramework) enable enable diff --git a/unittests/Docker/Docker.PostgreSQL/Docker.PostgreSQL.csproj b/unittests/Docker/Docker.PostgreSQL/Docker.PostgreSQL.csproj index bfe75f79..d3487e15 100644 --- a/unittests/Docker/Docker.PostgreSQL/Docker.PostgreSQL.csproj +++ b/unittests/Docker/Docker.PostgreSQL/Docker.PostgreSQL.csproj @@ -1,7 +1,6 @@ - $(TargetFramework) enable enable diff --git a/unittests/Docker/Docker.SqlServer/Docker.SqlServer.csproj b/unittests/Docker/Docker.SqlServer/Docker.SqlServer.csproj index 2e8d0d32..fc6b770c 100644 --- a/unittests/Docker/Docker.SqlServer/Docker.SqlServer.csproj +++ b/unittests/Docker/Docker.SqlServer/Docker.SqlServer.csproj @@ -1,7 +1,6 @@ - $(TargetFramework) enable enable diff --git a/unittests/Docker/Docker.Sqlite/Docker.Sqlite.csproj b/unittests/Docker/Docker.Sqlite/Docker.Sqlite.csproj index f2e39af8..0d64fef6 100644 --- a/unittests/Docker/Docker.Sqlite/Docker.Sqlite.csproj +++ b/unittests/Docker/Docker.Sqlite/Docker.Sqlite.csproj @@ -1,7 +1,6 @@ - $(TargetFramework) enable enable diff --git a/unittests/MariaDB/MariaDB.csproj b/unittests/MariaDB/MariaDB.csproj index e01f6a09..54146169 100644 --- a/unittests/MariaDB/MariaDB.csproj +++ b/unittests/MariaDB/MariaDB.csproj @@ -1,7 +1,6 @@ - $(TargetFramework) enable enable diff --git a/unittests/Oracle/Oracle.csproj b/unittests/Oracle/Oracle.csproj index e868eaef..f2f25b1a 100644 --- a/unittests/Oracle/Oracle.csproj +++ b/unittests/Oracle/Oracle.csproj @@ -1,7 +1,6 @@ - $(TargetFramework) enable enable diff --git a/unittests/PostgreSQL/PostgreSQL.csproj b/unittests/PostgreSQL/PostgreSQL.csproj index 941a4105..b9cf8e09 100644 --- a/unittests/PostgreSQL/PostgreSQL.csproj +++ b/unittests/PostgreSQL/PostgreSQL.csproj @@ -1,7 +1,6 @@ - $(TargetFramework) enable enable diff --git a/unittests/SqlServer/SqlServer.csproj b/unittests/SqlServer/SqlServer.csproj index eeffb246..b45949a4 100644 --- a/unittests/SqlServer/SqlServer.csproj +++ b/unittests/SqlServer/SqlServer.csproj @@ -1,7 +1,6 @@ - $(TargetFramework) enable enable diff --git a/unittests/SqlServerCaseSensitive/SqlServerCaseSensitive.csproj b/unittests/SqlServerCaseSensitive/SqlServerCaseSensitive.csproj index 401df7aa..995d9c84 100644 --- a/unittests/SqlServerCaseSensitive/SqlServerCaseSensitive.csproj +++ b/unittests/SqlServerCaseSensitive/SqlServerCaseSensitive.csproj @@ -1,7 +1,6 @@ - $(TargetFramework) enable enable diff --git a/unittests/Sqlite/Sqlite.csproj b/unittests/Sqlite/Sqlite.csproj index dcd18db7..91e32755 100644 --- a/unittests/Sqlite/Sqlite.csproj +++ b/unittests/Sqlite/Sqlite.csproj @@ -1,7 +1,6 @@ - $(TargetFramework) enable enable diff --git a/unittests/Sqlite/TestInfrastructure/SqliteTestDatabase.cs b/unittests/Sqlite/TestInfrastructure/SqliteTestDatabase.cs index d6885e9c..6d718b22 100644 --- a/unittests/Sqlite/TestInfrastructure/SqliteTestDatabase.cs +++ b/unittests/Sqlite/TestInfrastructure/SqliteTestDatabase.cs @@ -1,11 +1,17 @@ using Xunit.Sdk; +#if NET6_0 +using Dir = TestCommon.TestInfrastructure.Net6PolyFills.Directory; +#else +using Dir = System.IO.Directory; +#endif + namespace TestCommon.TestInfrastructure; // ReSharper disable once ClassNeverInstantiated.Global public class SqliteTestDatabase : ITestDatabase, IAsyncLifetime { - private readonly string _root = Directory.CreateTempSubdirectory("grate-sqlite-tests-").ToString(); + private readonly string _root = Dir.CreateTempSubdirectory("grate-sqlite-tests-").ToString(); public Task DisposeAsync() { diff --git a/unittests/TestCommon/TestCommon.csproj b/unittests/TestCommon/TestCommon.csproj index fe1bbdfb..60f426a0 100644 --- a/unittests/TestCommon/TestCommon.csproj +++ b/unittests/TestCommon/TestCommon.csproj @@ -1,7 +1,6 @@ - $(TargetFramework) enable enable false diff --git a/unittests/TestCommon/TestInfrastructure/DatabaseHelpers.cs b/unittests/TestCommon/TestInfrastructure/DatabaseHelpers.cs index bc305fd4..966e0cf9 100644 --- a/unittests/TestCommon/TestInfrastructure/DatabaseHelpers.cs +++ b/unittests/TestCommon/TestInfrastructure/DatabaseHelpers.cs @@ -5,6 +5,12 @@ using Xunit.Abstractions; using Xunit.Sdk; +#if NET6_0 +using Dir = TestCommon.TestInfrastructure.Net6PolyFills.Directory; +#else +using Dir = System.IO.Directory; +#endif + namespace TestCommon.TestInfrastructure; public static class DatabaseHelpers @@ -118,7 +124,7 @@ public static async Task CreateSqliteDatabaseFromConnectionString(string connect public static async Task> GetSqliteDatabases(this IGrateTestContext context) { var builder = new SqliteConnectionStringBuilder(context.AdminConnectionString); - var root = Path.GetDirectoryName(builder.DataSource) ?? Directory.CreateTempSubdirectory().ToString() ; + var root = Path.GetDirectoryName(builder.DataSource) ?? Dir.CreateTempSubdirectory().ToString() ; var dbFiles = Directory.EnumerateFiles(root, "*.db"); IEnumerable dbNames = dbFiles .Select(Path.GetFileNameWithoutExtension) diff --git a/unittests/TestCommon/TestInfrastructure/IGrateTestContext.cs b/unittests/TestCommon/TestInfrastructure/IGrateTestContext.cs index 4edc5d9d..b258ea54 100644 --- a/unittests/TestCommon/TestInfrastructure/IGrateTestContext.cs +++ b/unittests/TestCommon/TestInfrastructure/IGrateTestContext.cs @@ -6,6 +6,12 @@ using grate.Migration; using Microsoft.Extensions.Logging; +#if NET6_0 +using Dir = TestCommon.TestInfrastructure.Net6PolyFills.Directory; +#else +using Dir = System.IO.Directory; +#endif + namespace TestCommon.TestInfrastructure; public interface IGrateTestContext @@ -37,7 +43,7 @@ public interface IGrateTestContext AlterDatabase = true, NonInteractive = true, Transaction = SupportsTransaction, - OutputPath = Directory.CreateTempSubdirectory() + OutputPath = Dir.CreateTempSubdirectory() }; public Task DropDatabase(string databaseName); diff --git a/unittests/TestCommon/TestInfrastructure/Net6PolyFills.cs b/unittests/TestCommon/TestInfrastructure/Net6PolyFills.cs new file mode 100644 index 00000000..5fd53abe --- /dev/null +++ b/unittests/TestCommon/TestInfrastructure/Net6PolyFills.cs @@ -0,0 +1,18 @@ +namespace TestCommon.TestInfrastructure; +using System.IO; + +#if NET6_0 +public static class Net6PolyFills +{ + public static class Directory + { + public static DirectoryInfo CreateTempSubdirectory() + => CreateTempSubdirectory(Path.GetRandomFileName()); + + public static DirectoryInfo CreateTempSubdirectory(string name) + { + return new DirectoryInfo(Path.GetTempPath()).CreateSubdirectory(name); + } + } +} +#endif diff --git a/unittests/TestCommon/TestInfrastructure/TestConfig.cs b/unittests/TestCommon/TestInfrastructure/TestConfig.cs index e96eb265..bdbb4e09 100644 --- a/unittests/TestCommon/TestInfrastructure/TestConfig.cs +++ b/unittests/TestCommon/TestInfrastructure/TestConfig.cs @@ -2,6 +2,12 @@ using static System.StringComparison; using static System.StringSplitOptions; +#if NET6_0 +using Dir = TestCommon.TestInfrastructure.Net6PolyFills.Directory; +#else +using Dir = System.IO.Directory; +#endif + namespace TestCommon.TestInfrastructure; public static class TestConfig @@ -12,7 +18,7 @@ public static class TestConfig public static DirectoryInfo CreateRandomTempDirectory() { - return Directory.CreateTempSubdirectory(); + return Dir.CreateTempSubdirectory(); } public static DirectoryInfo Wrap(DirectoryInfo root, string? subFolder) => new(Path.Combine(root.ToString(), subFolder ?? ""));