Skip to content

Commit

Permalink
Add .NET 7 support (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
lecaillon authored Jun 30, 2023
1 parent d7c3a03 commit 1a032d9
Show file tree
Hide file tree
Showing 46 changed files with 363 additions and 719 deletions.
6 changes: 3 additions & 3 deletions build/common.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<Version>3.2.0-alpha2</Version>
<AssemblyVersion>3.1.0.0</AssemblyVersion>
<FileVersion>3.1.0.0</FileVersion>
<Version>3.2.0</Version>
<AssemblyVersion>3.2.0.0</AssemblyVersion>
<FileVersion>3.2.0.0</FileVersion>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/Evolve.Cli/Evolve.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<PublishTrimmed>true</PublishTrimmed>
<RootNamespace>EvolveDb.Cli</RootNamespace>
</PropertyGroup>
Expand Down
202 changes: 104 additions & 98 deletions src/Evolve.Cli/Program.cs

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/Evolve.Tool/Evolve.Tool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<PackAsTool>true</PackAsTool>
<ToolCommandName>evolve</ToolCommandName>
<RootNamespace>EvolveDb.Tool</RootNamespace>
Expand All @@ -24,7 +24,8 @@ Every time you build your project, it will automatically ensure that your databa
<PackageTags>evolve flyway dotnet tool sql database migration mysql sqlserver cassandra mariadb sqlite postgresql cockroachdb</PackageTags>
<PackageReleaseNotes>## Features
- #293 Add timeout for ambient transactions
- #189 Enabled use of Evolve CLI/Tool Placeholders with ':' in their value</PackageReleaseNotes>
- #189 Enabled use of Evolve CLI/Tool Placeholders with ':' in their value
- Add .NET 7 support, drop .NET 5 support</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Evolve/Evolve.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="..\..\build\common.props" />

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net7.0</TargetFrameworks>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<LangVersion>latest</LangVersion>
Expand Down
82 changes: 45 additions & 37 deletions test/Evolve.Tests/Cli/CliTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,38 @@
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using EvolveDb.Tests.Infrastructure;
using Xunit;
using Xunit.Abstractions;

namespace EvolveDb.Tests.Cli
{
[Collection("Database collection")]
public class CliTest
{
private readonly PostgreSqlFixture _pgContainer;
private readonly MySQLFixture _mySQLContainer;
private readonly SQLServerFixture _sqlServerContainer;
private readonly CassandraFixture _cassandraContainer;
private readonly CockroachDBFixture _cockroachDBContainer;
private readonly ITestOutputHelper _output;

public CliTest(PostgreSqlFixture pgContainer, MySQLFixture mySQLContainer, SQLServerFixture sqlServerContainer, CassandraFixture cassandraContainer, CockroachDBFixture cockroachDBContainer, ITestOutputHelper output)
public CliTest(ITestOutputHelper output)
{
_pgContainer = pgContainer;
_mySQLContainer = mySQLContainer;
_sqlServerContainer = sqlServerContainer;
_cassandraContainer = cassandraContainer;
_cockroachDBContainer = cockroachDBContainer;
_output = output;

if (TestContext.Local || TestContext.AzureDevOps)
{
pgContainer.Run();
sqlServerContainer.Run();
cassandraContainer.Run();
cockroachDBContainer.Run();
if (TestContext.Local)
{
mySQLContainer.Run();
}
}
}

[FactSkippedOnAppVeyor]
[Category(Test.Cli, Test.CockroachDB)]
public void CockroachDB_Should_Run_All_Cli_Commands()
public async Task CockroachDB_Should_Run_All_Cli_Commands()
{
var container = new CockroachDBContainer();
if (TestContext.Local || TestContext.AzureDevOps)
{
await container.Start();
}

foreach (var command in new[] { "erase", "migrate", "repair", "info" })
{
string stderr = RunCli(
db: "cockroachdb",
command: command,
cnxStr: _cockroachDBContainer.CnxStr,
cnxStr: container.CnxStr,
location: TestContext.CockroachDB.MigrationFolder,
args: "-s evolve -s defaultdb");

Expand All @@ -59,16 +43,22 @@ public void CockroachDB_Should_Run_All_Cli_Commands()

[FactSkippedOnAppVeyor]
[Category(Test.Cli, Test.Cassandra)]
public void Cassandra_Should_Run_All_Cli_Commands()
public async Task Cassandra_Should_Run_All_Cli_Commands()
{
var container = new CassandraContainer();
if (TestContext.Local || TestContext.AzureDevOps)
{
await container.Start();
}

string metadataKeyspaceName = "my_keyspace_3";

foreach (var command in new[] { "erase", "migrate", "repair", "info" })
{
string stderr = RunCli(
db: "cassandra",
command: command,
cnxStr: _cassandraContainer.CnxStr,
cnxStr: container.CnxStr,
location: TestContext.CassandraDb.MigrationFolder,
args: $"--scripts-suffix .cql -p keyspace:{metadataKeyspaceName} --keyspace {metadataKeyspaceName} --metadata-table-keyspace evolve_change_log");

Expand All @@ -78,14 +68,20 @@ public void Cassandra_Should_Run_All_Cli_Commands()

[Fact]
[Category(Test.Cli, Test.MySQL)]
public void MySQL_With_Embedded_Resources_Should_Run_All_Cli_Commands()
public async Task MySQL_With_Embedded_Resources_Should_Run_All_Cli_Commands()
{
var container = new MySQLContainer();
if (TestContext.Local || TestContext.AzureDevOps)
{
await container.Start();
}

foreach (var command in new[] { "erase", "migrate", "repair", "info" })
{
string stderr = RunCli(
db: "mysql",
command: command,
cnxStr: _mySQLContainer.CnxStr,
cnxStr: container.CnxStr,
location: null,
args: $"-a Evolve.Tests.dll -f {TestContext.MySQL.MigrationFolderFilter}");

Expand All @@ -95,34 +91,46 @@ public void MySQL_With_Embedded_Resources_Should_Run_All_Cli_Commands()

[Fact]
[Category(Test.Cli, Test.PostgreSQL)]
public void PostgreSql_Should_Run_All_Cli_Commands()
public async Task PostgreSql_Should_Run_All_Cli_Commands()
{
foreach (var command in new [] { "erase", "migrate", "repair", "info" })
var container = new PostgreSqlContainer();
if (TestContext.Local || TestContext.AzureDevOps)
{
await container.Start();
}

foreach (var command in new[] { "erase", "migrate", "repair", "info" })
{
string stderr = RunCli(
db: "postgresql",
command: command,
cnxStr: _pgContainer.CnxStr.Replace(PostgreSqlContainer.DbPwd, "${pwd}"), // add secret to the connection string
cnxStr: container.CnxStr.Replace(PostgreSqlContainer.DbPwd, "${pwd}"), // add secret to the connection string
location: TestContext.PostgreSQL.MigrationFolder,
args: $"-s public -s unittest --metadata-table-schema unittest --erase-disabled false -p schema1:unittest -p pwd;{PostgreSqlContainer.DbPwd}");
args: $"-s public -s unittest --metadata-table-schema unittest --erase-disabled false -p schema1:unittest -p pwd:{PostgreSqlContainer.DbPwd}");

Assert.True(string.IsNullOrEmpty(stderr), stderr);
}
}

[Fact]
[Category(Test.Cli, Test.SQLServer)]
public void SQLServer_Should_Run_All_Cli_Commands()
public async Task SQLServer_Should_Run_All_Cli_Commands()
{
var container = new SQLServerContainer();
if (TestContext.Local || TestContext.AzureDevOps)
{
await container.Start();
}

string dbName = "my_database_3";
TestUtil.CreateSqlServerDatabase(dbName, _sqlServerContainer.GetCnxStr("master"));
TestUtil.CreateSqlServerDatabase(dbName, container.CnxStr);

foreach (var command in new[] { "erase", "migrate", "repair", "info" })
{
string stderr = RunCli(
db: "sqlserver",
command: command,
cnxStr: _sqlServerContainer.GetCnxStr(dbName),
cnxStr: container.CnxStr,
location: TestContext.SqlServer.MigrationFolder,
args: $"-p db:{dbName} -p schema2:dbo --target-version 8_9");

Expand Down
26 changes: 5 additions & 21 deletions test/Evolve.Tests/Connection/WrappedConnectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,8 @@

namespace EvolveDb.Tests.Connection
{
[Collection("PostgreSql collection")]
public class WrappedConnectionTest
public record WrappedConnectionTest : DbContainerFixture<PostgreSqlContainer>
{
private static PostgreSqlFixture _pgContainer;

public WrappedConnectionTest(PostgreSqlFixture pgContainer)
{
if (_pgContainer is null)
{
_pgContainer = pgContainer;

if (TestContext.Local || TestContext.AzureDevOps)
{
pgContainer.Run();
}
}
}

[Fact]
[Category(Test.Connection)]
public void Inner_dbconnection_can_not_be_null()
Expand All @@ -36,7 +20,7 @@ public void Inner_dbconnection_can_not_be_null()
[Category(Test.Connection)]
public void When_disposed_inner_dbconnection_is_closed()
{
var cnn = _pgContainer.CreateDbConnection();
var cnn = CreateDbConnection();
using (var wrappedConnection = new WrappedConnection(cnn))
{
wrappedConnection.Open();
Expand All @@ -49,7 +33,7 @@ public void When_disposed_inner_dbconnection_is_closed()
[Category(Test.Connection)]
public void Commit_a_null_transaction_throws_InvalidOperationException()
{
var cnn = _pgContainer.CreateDbConnection();
var cnn = CreateDbConnection();
using (var wrappedConnection = new WrappedConnection(cnn))
{
Assert.Throws<InvalidOperationException>(() => wrappedConnection.Commit());
Expand All @@ -62,7 +46,7 @@ public void Commit_a_null_transaction_throws_InvalidOperationException()
[Category(Test.Connection)]
public void Rollback_a_null_transaction_throws_InvalidOperationException()
{
var cnn = _pgContainer.CreateDbConnection();
var cnn = CreateDbConnection();
using (var wrappedConnection = new WrappedConnection(cnn))
{
Assert.Throws<InvalidOperationException>(() => wrappedConnection.Rollback());
Expand All @@ -75,7 +59,7 @@ public void Rollback_a_null_transaction_throws_InvalidOperationException()
[Category(Test.Connection)]
public void BeginTransaction_opens_a_connection_and_returns_a_transaction()
{
var cnn = _pgContainer.CreateDbConnection();
var cnn = CreateDbConnection();
using (var wrappedConnection = new WrappedConnection(cnn))
{
var tx = wrappedConnection.BeginTransaction();
Expand Down
8 changes: 4 additions & 4 deletions test/Evolve.Tests/Evolve.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<IsPackable>false</IsPackable>
<LangVersion>latest</LangVersion>
<RootNamespace>EvolveDb.Tests</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="altcover" Version="8.4.840" />
<PackageReference Include="altcover" Version="8.6.61" />
<PackageReference Include="CassandraCSharpDriver" Version="3.18.0" />
<PackageReference Include="Docker.DotNet" Version="3.125.11" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="Docker.DotNet" Version="3.125.15" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="MySqlConnector" Version="2.1.13" />
<PackageReference Include="Npgsql" Version="6.0.7" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Data.Common;
using System.Threading.Tasks;
using Cassandra.Data;

namespace EvolveDb.Tests.Infrastructure
Expand All @@ -12,15 +13,14 @@ public class CassandraContainer : IDbContainer
public const string DbUser = "postgres";

private DockerContainer _container;
private bool _disposedValue = false;

public string Id => _container?.Id;
public string CnxStr => $"Contact Points=127.0.0.1;Port={HostPort};Cluster Name={ClusterName}";
public int TimeOutInSec => 60;

public bool Start(bool fromScratch = false)
public async Task<bool> Start(bool fromScratch = false)
{
_container = new DockerContainerBuilder(new DockerContainerBuilderOptions
_container = await new DockerContainerBuilder(new DockerContainerBuilderOptions
{
FromImage = "cassandra",
Tag = "latest",
Expand All @@ -31,27 +31,9 @@ public bool Start(bool fromScratch = false)
RemovePreviousContainer = fromScratch
}).Build();

return _container.Start();
return await _container.Start();
}

public DbConnection CreateDbConnection() => new CqlConnection(CnxStr);

protected virtual void Dispose(bool disposing)
{
if (!_disposedValue)
{
if (disposing)
{
_container?.Dispose();
}

_disposedValue = true;
}
}

public void Dispose()
{
Dispose(true);
}
}
}
19 changes: 0 additions & 19 deletions test/Evolve.Tests/Infrastructure/CockroachDb/CockroachDbFixture.cs

This file was deleted.

Loading

0 comments on commit 1a032d9

Please sign in to comment.