Skip to content

Commit

Permalink
#23 Update project targeted frameworks, tools and libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
savornicesei committed Feb 28, 2018
1 parent 0ef7a6c commit fe01950
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 23 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*.sln.docstates
.vs
.sonar*
*.userprefs

# Build results
[Dd]ebug/
Expand All @@ -23,6 +24,7 @@ bld/

# Roslyn cache directories
*.ide/
*.idea/

# MSTest test Results
[Tt]est[Rr]esult*/
Expand Down Expand Up @@ -188,4 +190,4 @@ FakesAssemblies/
#Jekyll
_site
.sass-cache
.jekyll-metadata
.jekyll-metadata
7 changes: 4 additions & 3 deletions NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<configuration>
<!-- see https://docs.microsoft.com/en-us/nuget/schema/nuget-config-file -->
<config>
<add key="repositoryPath" value="..\packages" />
<add key="globalPackagesFolder" value="..\packages" />
<add key="repositoryPath" value="packages" />
<add key="globalPackagesFolder" value="packages" />
</config>
<packageRestore>
<!-- Allow NuGet to download missing packages -->
Expand All @@ -14,5 +14,6 @@
<packageSources>
<add key="NuGet official package source" value="https://api.nuget.org/v3/index.json" />
<add key="DotNet Core extensions source" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
</packageSources>
<add key="Bintray unstable package source" value="https://api.bintray.com/nuget/savornicesei/NDbUnit2" />
</packageSources>
</configuration>
14 changes: 8 additions & 6 deletions src/NDbUnit.SqlLite/NDbUnit.SqlLite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@

<!-- .NET Standard 2.0 references and build options -->
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.Data.Sqlite.Core">
<Version>2.0.0</Version>
</PackageReference>
</ItemGroup>

<!-- .NET 4.5.2 references and build options -->
<ItemGroup Condition=" '$(TargetFramework)' == 'net452'">
<PackageReference Include="System.Data.SQLite.Core">
<Version>1.0.107</Version>
</PackageReference>
</ItemGroup>

<!-- .NET standard references and build options -->
<ItemGroup Condition="$(DefineConstants.Contains(NETSTANDARD))">
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="2.0.0" />
</ItemGroup>

<!-- .NET framework references and build options -->
Expand All @@ -30,6 +29,9 @@
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup Condition="$(DefineConstants.Contains(NETFULL))">
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.107" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\NDbUnit.Core\NDbUnit.Core.csproj" />
Expand Down
71 changes: 70 additions & 1 deletion src/NDbUnit.SqlLite/SqlLiteDbCommandBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@

namespace NDbUnit.Core.SqlLite
{
#if NETSTANDARD
public class SqlLiteDbCommandBuilder : DbCommandBuilder<SqliteConnection>
#else
public class SqlLiteDbCommandBuilder : DbCommandBuilder<SQLiteConnection>
#endif
{
private new DataTable _dataTableSchema;

#if NETSTANDARD
public SqlLiteDbCommandBuilder(DbConnectionManager<SqliteConnection> connectionManager )
: base(connectionManager)
#else
public SqlLiteDbCommandBuilder(DbConnectionManager<SQLiteConnection> connectionManager )
: base(connectionManager)
#endif
{
}

Expand All @@ -37,7 +45,11 @@ public override string QuoteSuffix

protected override IDbCommand CreateDbCommand()
{
#if NETSTANDARD
var command = new SqliteCommand();
#else
var command = new SQLiteCommand();
#endif

if (CommandTimeOutSeconds != 0)
command.CommandTimeout = CommandTimeOutSeconds;
Expand All @@ -47,16 +59,25 @@ protected override IDbCommand CreateDbCommand()

protected override IDbCommand CreateDeleteAllCommand(string tableName)
{
#if NETSTANDARD
return
new SqliteCommand("DELETE FROM " + TableNameHelper.FormatTableName(tableName, QuotePrefix, QuoteSuffix));
#else
return
new SQLiteCommand("DELETE FROM " + TableNameHelper.FormatTableName(tableName, QuotePrefix, QuoteSuffix));
#endif
}

protected override IDbCommand CreateDeleteCommand(IDbCommand selectCommand, string tableName)
{
StringBuilder sb = new StringBuilder();
sb.Append("DELETE FROM " + TableNameHelper.FormatTableName(tableName, QuotePrefix, QuoteSuffix) + " WHERE ");

#if NETSTANDARD
SqliteCommand sqlDeleteCommand = CreateDbCommand() as SqliteCommand;
#else
SQLiteCommand sqlDeleteCommand = CreateDbCommand() as SQLiteCommand;
#endif

int count = 1;
DbParameter sqlParameter;
Expand All @@ -72,7 +93,11 @@ protected override IDbCommand CreateDeleteCommand(IDbCommand selectCommand, stri
sb.Append(QuotePrefix + dataRow[SchemaColumns.ColumnName] + QuoteSuffix);
sb.Append("=@p" + count);

#if NETSTANDARD
sqlParameter = (SqliteParameter)CreateNewSqlParameter(count, dataRow);
#else
sqlParameter = (SQLiteParameter)CreateNewSqlParameter(count, dataRow);
#endif
sqlDeleteCommand.Parameters.Add(sqlParameter);

++count;
Expand All @@ -92,7 +117,12 @@ protected override IDbCommand CreateInsertCommand(IDbCommand selectCommand, stri
sb.Append("INSERT INTO " + TableNameHelper.FormatTableName(tableName, QuotePrefix, QuoteSuffix) + "(");
StringBuilder sbParam = new StringBuilder();
DbParameter sqlParameter = null;

#if NETSTANDARD
SqliteCommand sqlInsertCommand = CreateDbCommand() as SqliteCommand;
#else
SQLiteCommand sqlInsertCommand = CreateDbCommand() as SQLiteCommand;
#endif
foreach (DataRow dataRow in _dataTableSchema.Rows)
{
if (ColumnOKToInclude(dataRow) && !IsAutoIncrementing(dataRow)) // Not an identity column.
Expand All @@ -108,7 +138,11 @@ protected override IDbCommand CreateInsertCommand(IDbCommand selectCommand, stri
sb.Append(QuotePrefix + dataRow[SchemaColumns.ColumnName] + QuoteSuffix);
sbParam.Append("@p" + count);

#if NETSTANDARD
sqlParameter = (SqliteParameter)CreateNewSqlParameter(count, dataRow);
#else
sqlParameter = (SQLiteParameter)CreateNewSqlParameter(count, dataRow);
#endif
sqlInsertCommand.Parameters.Add(sqlParameter);

++count;
Expand All @@ -130,7 +164,12 @@ protected override IDbCommand CreateInsertIdentityCommand(IDbCommand selectComma
sb.Append("INSERT INTO " + TableNameHelper.FormatTableName(tableName, QuotePrefix, QuoteSuffix) + "(");
StringBuilder sbParam = new StringBuilder();
DbParameter sqlParameter = null;

#if NETSTANDARD
SqliteCommand sqlInsertIdentityCommand = CreateDbCommand() as SqliteCommand;
#else
SQLiteCommand sqlInsertIdentityCommand = CreateDbCommand() as SQLiteCommand;
#endif
foreach (DataRow dataRow in _dataTableSchema.Rows)
{
if (ColumnOKToInclude(dataRow))
Expand All @@ -146,7 +185,11 @@ protected override IDbCommand CreateInsertIdentityCommand(IDbCommand selectComma
sb.Append(QuotePrefix + dataRow[SchemaColumns.ColumnName] + QuoteSuffix);
sbParam.Append("@p" + count);

#if NETSTANDARD
sqlParameter = (SqliteParameter)CreateNewSqlParameter(count, dataRow);
#else
sqlParameter = (SQLiteParameter)CreateNewSqlParameter(count, dataRow);
#endif
sqlInsertIdentityCommand.Parameters.Add(sqlParameter);

++count;
Expand All @@ -163,14 +206,24 @@ protected override IDbCommand CreateInsertIdentityCommand(IDbCommand selectComma

protected override IDataParameter CreateNewSqlParameter(int index, DataRow dataRow)
{
#if NETSTANDARD
return new SqliteParameter("@p" + index, (SqliteType)dataRow[SchemaColumns.ProviderType],
(int)dataRow[SchemaColumns.ColumnSize],
(string)dataRow[SchemaColumns.ColumnName]);
#else
return new SQLiteParameter("@p" + index, (DbType)dataRow[SchemaColumns.ProviderType],
(int)dataRow[SchemaColumns.ColumnSize],
(string)dataRow[SchemaColumns.ColumnName]);
#endif
}

protected override IDbCommand CreateSelectCommand(DataSet ds, string tableName)
{
#if NETSTANDARD
SqliteCommand sqlSelectCommand = CreateDbCommand() as SqliteCommand;
#else
SQLiteCommand sqlSelectCommand = CreateDbCommand() as SQLiteCommand;
#endif

bool notFirstColumn = false;
StringBuilder sb = new StringBuilder("SELECT ");
Expand Down Expand Up @@ -214,7 +267,11 @@ protected override IDbCommand CreateUpdateCommand(IDbCommand selectCommand, stri
StringBuilder sb = new StringBuilder();
sb.Append("UPDATE " + TableNameHelper.FormatTableName(tableName, QuotePrefix, QuoteSuffix) + " SET ");

#if NETSTANDARD
SqliteCommand sqlUpdateCommand = CreateDbCommand() as SqliteCommand;
#else
SQLiteCommand sqlUpdateCommand = CreateDbCommand() as SQLiteCommand;
#endif

int count = 1;
bool notFirstKey = false;
Expand Down Expand Up @@ -249,7 +306,11 @@ protected override IDbCommand CreateUpdateCommand(IDbCommand selectCommand, stri
sbPrimaryKey.Append(QuotePrefix + dataRow[SchemaColumns.ColumnName] + QuoteSuffix);
sbPrimaryKey.Append("=@p" + count);

#if NETSTANDARD
sqlParameter = (SqliteParameter)CreateNewSqlParameter(count, dataRow);
#else
sqlParameter = (SQLiteParameter)CreateNewSqlParameter(count, dataRow);
#endif
sqlUpdateCommand.Parameters.Add(sqlParameter);

++count;
Expand All @@ -268,7 +329,11 @@ protected override IDbCommand CreateUpdateCommand(IDbCommand selectCommand, stri
sb.Append(QuotePrefix + dataRow[SchemaColumns.ColumnName] + QuoteSuffix);
sb.Append("=@p" + count);

#if NETSTANDARD
sqlParameter = (SqliteParameter)CreateNewSqlParameter(count, dataRow);
#else
sqlParameter = (SQLiteParameter)CreateNewSqlParameter(count, dataRow);
#endif
sqlUpdateCommand.Parameters.Add(sqlParameter);

++count;
Expand All @@ -285,7 +350,11 @@ protected override IDbCommand CreateUpdateCommand(IDbCommand selectCommand, stri

protected override IDbConnection GetConnection(string connectionString)
{
#if NETSTANDARD
return new SqliteConnection(connectionString);
#else
return new SQLiteConnection(connectionString);
#endif
}

/// <summary>
Expand Down
15 changes: 14 additions & 1 deletion src/NDbUnit.SqlLite/SqlLiteDbOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,34 @@
* This source code is released under the Apache 2.0 License; see the accompanying license file.
*
*/
using System;
using System.Data;
#if NETSTANDARD
using Microsoft.Data.Sqlite;
#else
using System.Data.SQLite;
#endif

namespace NDbUnit.Core.SqlLite
{
public class SqlLiteDbOperation : DbOperation
{
protected override IDbDataAdapter CreateDbDataAdapter()
{
return new SQliteDataAdapter();
#if NETSTANDARD
throw new NotImplementedException("Microsoft.Data.Sqlite does not implement IDbAdapter");
#else
return new SQLiteDataAdapter();
#endif
}

protected override IDbCommand CreateDbCommand(string cmdText)
{
#if NETSTANDARD
return new SqliteCommand(cmdText);
#else
return new SQLiteCommand(cmdText);
#endif
}

/// <summary>
Expand Down
42 changes: 32 additions & 10 deletions src/NDbUnit.SqlLite/SqlLiteDbUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,58 @@
*/
using System;
using System.Data;
#if NETSTANDARD
using Microsoft.Data.Sqlite;
#else
using System.Data.SQLite;
#endif

namespace NDbUnit.Core.SqlLite
{
#if NETSTANDARD
public class SqlLiteDbUnitTest : NDbUnitTest<SqliteConnection>
#else
public class SqlLiteDbUnitTest : NDbUnitTest<SQLiteConnection>
#endif
{
public SqlLiteDbUnitTest(string connectionString)
: base(connectionString)
{
}

#if NETSTANDARD
public SqlLiteDbUnitTest(SqliteConnection connection)
: base(connection)
{
}

protected override IDbDataAdapter CreateDataAdapter(IDbCommand command)
{
return new SQLiteDataAdapter((SqliteCommand)command);
throw new NotImplementedException("Microsoft.Data.Sqlite does not implement IDbAdapter");
//return new SQLiteDataAdapter((SqliteCommand)command);
}

protected override IDbCommandBuilder CreateDbCommandBuilder(DbConnectionManager<SqliteConnection> connectionManager)
{
return new SqlLiteDbCommandBuilder(connectionManager);
}
//protected override IDbCommandBuilder CreateDbCommandBuilder(IDbConnection connection)
//{
// return new SqlLiteDbCommandBuilder(connection);
//}
#else
public SqlLiteDbUnitTest(SQLiteConnection connection)
: base(connection)
{
}

//protected override IDbCommandBuilder CreateDbCommandBuilder(string connectionString)
//{
// return new SqlLiteDbCommandBuilder(connectionString);
//}
protected override IDbDataAdapter CreateDataAdapter(IDbCommand command)
{
return new SQLiteDataAdapter((SQLiteCommand)command);
}

protected override IDbCommandBuilder CreateDbCommandBuilder(DbConnectionManager<SQLiteConnection> connectionManager)
{
return new SqlLiteDbCommandBuilder(connectionManager);
}
#endif

protected override IDbOperation CreateDbOperation()
{
return new SqlLiteDbOperation();
Expand All @@ -56,8 +72,14 @@ public SqlLiteUnitTest(string connectionString) : base(connectionString)
{
}

#if NETSTANDARD
public SqlLiteUnitTest(SqliteConnection connection) : base(connection)
{
}
#else
public SqlLiteUnitTest(SQLiteConnection connection) : base(connection)
{
}
#endif
}
}
Loading

0 comments on commit fe01950

Please sign in to comment.