Skip to content

Commit

Permalink
Changed connection abstraction (#3)
Browse files Browse the repository at this point in the history
* Changed connection abstraction from IDbConnection to DbConnection
  • Loading branch information
carl-berg authored Feb 19, 2023
1 parent 39058c5 commit 7dbdadd
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions ADatabaseFixture.FluentMigrator.Tests/Core/DatabaseTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq;
using System.Threading.Tasks;
using DataDude;
using Microsoft.Data.SqlClient;
using Respawn;
using Xunit;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<Version>0.3.0</Version>
<Version>0.4.0</Version>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<Version>0.3.0</Version>
<Version>0.4.0</Version>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions ADatabaseFixture.SqlServer/ADatabaseFixture.SqlServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<Version>0.3.0</Version>
<Version>0.4.0</Version>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
Expand All @@ -25,7 +25,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.0.1" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 4 additions & 2 deletions ADatabaseFixture.SqlServer/SqlServerDatabaseAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.Data;
using System.Data.Common;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Data.SqlClient;
Expand Down Expand Up @@ -51,7 +51,8 @@ public virtual async Task<string> CreateDatabase()
return GetDatabaseConnectionString();
}

public virtual IDbConnection CreateNewConnection(string connectionString) => new SqlConnection(connectionString);
public virtual SqlConnection CreateNewConnection(string connectionString) => new(connectionString);
DbConnection IDatabaseAdapter.CreateNewConnection(string connectionString) => CreateNewConnection(connectionString);

/// <summary>
/// Kills open connections, Drops database and tries to remove the file
Expand Down Expand Up @@ -100,6 +101,7 @@ public virtual async Task KillOpenConnections(SqlConnection connection)
SELECT @kill = @kill + 'kill ' + CONVERT(varchar(5), session_id) + ';'
FROM sys.dm_exec_sessions
WHERE database_id = db_id('{_databaseName}')
AND is_user_process = 1;
EXEC(@kill);
""";
await cmd.ExecuteNonQueryAsync();
Expand Down
2 changes: 1 addition & 1 deletion ADatabaseFixture/ADatabaseFixture.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<Version>0.3.0</Version>
<Version>0.4.0</Version>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
Expand Down
3 changes: 2 additions & 1 deletion ADatabaseFixture/DatabaseFixtureBase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Data;
using System.Data.Common;
using System.Threading.Tasks;

namespace ADatabaseFixture
Expand All @@ -26,7 +27,7 @@ protected DatabaseFixtureBase(IDatabaseAdapter databaseAdapter, IMigrator? migra
/// <summary>
/// Creates a new open connection
/// </summary>
public virtual IDbConnection CreateNewConnection()
public virtual DbConnection CreateNewConnection()
{
var connection = _databaseAdapter.CreateNewConnection(ConnectionString);
if (connection.State != ConnectionState.Open)
Expand Down
3 changes: 2 additions & 1 deletion ADatabaseFixture/IDatabaseAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Data;
using System.Data.Common;
using System.Threading.Tasks;

namespace ADatabaseFixture
Expand All @@ -21,6 +22,6 @@ public interface IDatabaseAdapter
/// </summary>
/// <param name="connectionString">Connection string</param>
/// <returns>New connection</returns>
IDbConnection CreateNewConnection(string connectionString);
DbConnection CreateNewConnection(string connectionString);
}
}

0 comments on commit 7dbdadd

Please sign in to comment.