Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set TargetFrameworks solely to "netstandard2.0" #139

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Respawn/IDbAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ public interface IDbAdapter
string BuildReseedSql(IEnumerable<Table> tablesToDelete);
string BuildTurnOffSystemVersioningCommandText(IEnumerable<TemporalTable> tablesToTurnOffSystemVersioning);
string BuildTurnOnSystemVersioningCommandText(IEnumerable<TemporalTable> tablesToTurnOnSystemVersioning);
Task<bool> CheckSupportsTemporalTables(DbConnection connection)
{
return Task.FromResult(false);
}
Task<bool> CheckSupportsTemporalTables(DbConnection connection);
}
}
5 changes: 3 additions & 2 deletions Respawn/Respawn.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Description>Intelligent resetting for database tests</Description>
<Copyright>Copyright Jimmy Bogard</Copyright>
<Authors>Jimmy Bogard</Authors>
<TargetFrameworks>netstandard2.1</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<AssemblyName>Respawn</AssemblyName>
<PackageId>Respawn</PackageId>
<PackageTags>tests;integration tests;database tests</PackageTags>
Expand All @@ -26,9 +26,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.1" Condition="'$(TargetFramework)' == 'netstandard2.0'"/>
<PackageReference Include="Microsoft.Data.SqlClient" Version="4.0.5" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="2.5.0" PrivateAssets="All" />
</ItemGroup>

</Project>
56 changes: 55 additions & 1 deletion Respawn/Respawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,15 @@ public static async Task<Respawner> CreateAsync(string nameOrConnectionString, R
throw new ArgumentException("This overload only supports the SqlDataAdapter. To use an alternative adapter, use the overload that supplies a DbConnection.", nameof(options.DbAdapter));
}

#if NETSTANDARD2_0
using var connection = new SqlConnection(nameOrConnectionString);

connection.Open();
#else
await using var connection = new SqlConnection(nameOrConnectionString);

await connection.OpenAsync();
#endif

var respawner = new Respawner(options);

Expand All @@ -48,7 +54,7 @@ public static async Task<Respawner> CreateAsync(string nameOrConnectionString, R
}

/// <summary>
/// Creates a <see cref="Respawner"/> based on the supplied connection and options.
/// Creates a <see cref="Respawner"/> based on the supplied connection and options.
/// </summary>
/// <param name="connection">Connection object for your target database</param>
/// <param name="options">Options</param>
Expand All @@ -67,9 +73,15 @@ public static async Task<Respawner> CreateAsync(DbConnection connection, Respawn

public virtual async Task ResetAsync(string nameOrConnectionString)
{
#if NETSTANDARD2_0
using var connection = new SqlConnection(nameOrConnectionString);

connection.Open();
#else
await using var connection = new SqlConnection(nameOrConnectionString);

await connection.OpenAsync();
#endif

await ResetAsync(connection);
}
Expand Down Expand Up @@ -98,22 +110,36 @@ public virtual async Task ResetAsync(DbConnection connection)

private async Task ExecuteAlterSystemVersioningAsync(DbConnection connection, string commandText)
{
#if NETSTANDARD2_0
using var tx = connection.BeginTransaction();
using var cmd = connection.CreateCommand();
#else
await using var tx = await connection.BeginTransactionAsync();
await using var cmd = connection.CreateCommand();
#endif

cmd.CommandTimeout = Options.CommandTimeout ?? cmd.CommandTimeout;
cmd.CommandText = commandText;
cmd.Transaction = tx;

await cmd.ExecuteNonQueryAsync();

#if NETSTANDARD2_0
tx.Commit();
#else
await tx.CommitAsync();
#endif
}

private async Task ExecuteDeleteSqlAsync(DbConnection connection)
{
#if NETSTANDARD2_0
using var tx = connection.BeginTransaction();
using var cmd = connection.CreateCommand();
#else
await using var tx = await connection.BeginTransactionAsync();
await using var cmd = connection.CreateCommand();
#endif

cmd.CommandTimeout = Options.CommandTimeout ?? cmd.CommandTimeout;
cmd.CommandText = DeleteSql;
Expand All @@ -127,7 +153,11 @@ private async Task ExecuteDeleteSqlAsync(DbConnection connection)
await cmd.ExecuteNonQueryAsync();
}

#if NETSTANDARD2_0
tx.Commit();
#else
await tx.CommitAsync();
#endif
}

private async Task BuildDeleteTables(DbConnection connection)
Expand Down Expand Up @@ -158,11 +188,19 @@ private async Task<HashSet<Relationship>> GetRelationships(DbConnection connecti
var relationships = new HashSet<Relationship>();
var commandText = Options.DbAdapter.BuildRelationshipCommandText(Options);

#if NETSTANDARD2_0
using var cmd = connection.CreateCommand();

cmd.CommandText = commandText;

using var reader = cmd.ExecuteReader();
#else
await using var cmd = connection.CreateCommand();

cmd.CommandText = commandText;

await using var reader = await cmd.ExecuteReaderAsync();
#endif

while (await reader.ReadAsync())
{
Expand All @@ -181,11 +219,19 @@ private async Task<HashSet<Table>> GetAllTables(DbConnection connection)

var commandText = Options.DbAdapter.BuildTableCommandText(Options);

#if NETSTANDARD2_0
using var cmd = connection.CreateCommand();

cmd.CommandText = commandText;

using var reader = cmd.ExecuteReader();
#else
await using var cmd = connection.CreateCommand();

cmd.CommandText = commandText;

await using var reader = await cmd.ExecuteReaderAsync();
#endif

while (await reader.ReadAsync())
{
Expand All @@ -201,11 +247,19 @@ private async Task<IList<TemporalTable>> GetAllTemporalTables(DbConnection conne

var commandText = Options.DbAdapter.BuildTemporalTableCommandText(Options);

#if NETSTANDARD2_0
using var cmd = connection.CreateCommand();

cmd.CommandText = commandText;

using var reader = cmd.ExecuteReader();
#else
await using var cmd = connection.CreateCommand();

cmd.CommandText = commandText;

await using var reader = await cmd.ExecuteReaderAsync();
#endif

while (await reader.ReadAsync())
{
Expand Down
8 changes: 8 additions & 0 deletions Respawn/SqlServerDbAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,11 @@ public async Task<bool> CheckSupportsTemporalTables(DbConnection connection)

private static async Task<int> GetEngineEdition(DbConnection connection)
{
#if NETSTANDARD2_0
using var command = connection.CreateCommand();
#else
await using var command = connection.CreateCommand();
#endif
command.CommandText = @"
SELECT SERVERPROPERTY('EngineEdition');";
var engineEdition = await command.ExecuteScalarAsync();
Expand All @@ -326,7 +330,11 @@ private static async Task<int> GetEngineEdition(DbConnection connection)

private static async Task<byte> GetCompatibilityLevel(DbConnection connection)
{
#if NETSTANDARD2_0
using var command = connection.CreateCommand();
#else
await using var command = connection.CreateCommand();
#endif
command.CommandText = $@"
SELECT compatibility_level
FROM sys.databases
Expand Down