From fe01950dccd112a2872eda55c46ba7799c5bb814 Mon Sep 17 00:00:00 2001 From: Simona Avornicesei Date: Thu, 1 Mar 2018 01:40:34 +0200 Subject: [PATCH] #23 Update project targeted frameworks, tools and libraries --- .gitignore | 4 +- NuGet.config | 7 +- src/NDbUnit.SqlLite/NDbUnit.SqlLite.csproj | 14 ++-- .../SqlLiteDbCommandBuilder.cs | 71 ++++++++++++++++++- src/NDbUnit.SqlLite/SqlLiteDbOperation.cs | 15 +++- src/NDbUnit.SqlLite/SqlLiteDbUnitTest.cs | 42 ++++++++--- test/NDbUnit.Test/NDbUnit.Test.csproj | 7 +- .../SQLliteInMemoryIntegrationTest.cs | 12 ++++ .../SqlLite/SqlLiteCommandBuilderTest.cs | 8 +++ .../SqlLite/SqlLiteDbOperationTest.cs | 13 ++++ .../SqlLite/SqlLiteUnitTestTest.cs | 11 +++ 11 files changed, 181 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 16d3f53..78477f4 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ *.sln.docstates .vs .sonar* +*.userprefs # Build results [Dd]ebug/ @@ -23,6 +24,7 @@ bld/ # Roslyn cache directories *.ide/ +*.idea/ # MSTest test Results [Tt]est[Rr]esult*/ @@ -188,4 +190,4 @@ FakesAssemblies/ #Jekyll _site .sass-cache -.jekyll-metadata \ No newline at end of file +.jekyll-metadata diff --git a/NuGet.config b/NuGet.config index 4e2d059..19eb349 100644 --- a/NuGet.config +++ b/NuGet.config @@ -2,8 +2,8 @@ - - + + @@ -14,5 +14,6 @@ - + + \ No newline at end of file diff --git a/src/NDbUnit.SqlLite/NDbUnit.SqlLite.csproj b/src/NDbUnit.SqlLite/NDbUnit.SqlLite.csproj index dc31c6e..10e4f8c 100644 --- a/src/NDbUnit.SqlLite/NDbUnit.SqlLite.csproj +++ b/src/NDbUnit.SqlLite/NDbUnit.SqlLite.csproj @@ -8,16 +8,15 @@ - - 2.0.0 - - - 1.0.107 - + + + + + @@ -30,6 +29,9 @@ + + + diff --git a/src/NDbUnit.SqlLite/SqlLiteDbCommandBuilder.cs b/src/NDbUnit.SqlLite/SqlLiteDbCommandBuilder.cs index e6a2d7d..cc3316c 100644 --- a/src/NDbUnit.SqlLite/SqlLiteDbCommandBuilder.cs +++ b/src/NDbUnit.SqlLite/SqlLiteDbCommandBuilder.cs @@ -16,12 +16,20 @@ namespace NDbUnit.Core.SqlLite { +#if NETSTANDARD public class SqlLiteDbCommandBuilder : DbCommandBuilder +#else + public class SqlLiteDbCommandBuilder : DbCommandBuilder +#endif { private new DataTable _dataTableSchema; - +#if NETSTANDARD public SqlLiteDbCommandBuilder(DbConnectionManager connectionManager ) : base(connectionManager) +#else + public SqlLiteDbCommandBuilder(DbConnectionManager connectionManager ) + : base(connectionManager) +#endif { } @@ -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; @@ -47,8 +59,13 @@ 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) @@ -56,7 +73,11 @@ protected override IDbCommand CreateDeleteCommand(IDbCommand selectCommand, stri 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; @@ -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; @@ -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. @@ -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; @@ -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)) @@ -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; @@ -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 "); @@ -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; @@ -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; @@ -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; @@ -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 } /// diff --git a/src/NDbUnit.SqlLite/SqlLiteDbOperation.cs b/src/NDbUnit.SqlLite/SqlLiteDbOperation.cs index 73d949c..47ea815 100644 --- a/src/NDbUnit.SqlLite/SqlLiteDbOperation.cs +++ b/src/NDbUnit.SqlLite/SqlLiteDbOperation.cs @@ -4,8 +4,13 @@ * 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 { @@ -13,12 +18,20 @@ 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 } /// diff --git a/src/NDbUnit.SqlLite/SqlLiteDbUnitTest.cs b/src/NDbUnit.SqlLite/SqlLiteDbUnitTest.cs index bc8130e..7ff6e9a 100644 --- a/src/NDbUnit.SqlLite/SqlLiteDbUnitTest.cs +++ b/src/NDbUnit.SqlLite/SqlLiteDbUnitTest.cs @@ -6,17 +6,26 @@ */ 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 +#else + public class SqlLiteDbUnitTest : NDbUnitTest +#endif { public SqlLiteDbUnitTest(string connectionString) : base(connectionString) { } +#if NETSTANDARD public SqlLiteDbUnitTest(SqliteConnection connection) : base(connection) { @@ -24,24 +33,31 @@ public SqlLiteDbUnitTest(SqliteConnection 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 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 connectionManager) + { + return new SqlLiteDbCommandBuilder(connectionManager); + } +#endif + protected override IDbOperation CreateDbOperation() { return new SqlLiteDbOperation(); @@ -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 } } diff --git a/test/NDbUnit.Test/NDbUnit.Test.csproj b/test/NDbUnit.Test/NDbUnit.Test.csproj index 15c9dd3..40ed436 100644 --- a/test/NDbUnit.Test/NDbUnit.Test.csproj +++ b/test/NDbUnit.Test/NDbUnit.Test.csproj @@ -27,7 +27,6 @@ - @@ -40,6 +39,11 @@ + + + + + @@ -60,6 +64,7 @@ compile;native;NativeBinaries + diff --git a/test/NDbUnit.Test/SqlLite-InMemory/SQLliteInMemoryIntegrationTest.cs b/test/NDbUnit.Test/SqlLite-InMemory/SQLliteInMemoryIntegrationTest.cs index 9d1b40e..6f71d4b 100644 --- a/test/NDbUnit.Test/SqlLite-InMemory/SQLliteInMemoryIntegrationTest.cs +++ b/test/NDbUnit.Test/SqlLite-InMemory/SQLliteInMemoryIntegrationTest.cs @@ -8,7 +8,11 @@ using NDbUnit.Core.SqlLite; using NUnit.Framework; using System.Data; +#if NETSTANDARD +using Microsoft.Data.Sqlite; +#else using System.Data.SQLite; +#endif using System.Diagnostics; using System.IO; @@ -18,12 +22,20 @@ namespace NDbUnit.Test.SqlLite_InMemory [TestFixture] public class SQLliteInMemoryIntegrationTest { +#if NETSTANDARD + private SqliteConnection _connection; +#else private SQLiteConnection _connection; +#endif [OneTimeSetUp] public void _OneTimeSetUp() { +#if NETSTANDARD + _connection = new SqliteConnection(DbConnection.SqlLiteInMemConnectionString); +#else _connection = new SQLiteConnection(DbConnection.SqlLiteInMemConnectionString); +#endif ExecuteSchemaCreationScript(); } diff --git a/test/NDbUnit.Test/SqlLite/SqlLiteCommandBuilderTest.cs b/test/NDbUnit.Test/SqlLite/SqlLiteCommandBuilderTest.cs index 404e203..6801672 100644 --- a/test/NDbUnit.Test/SqlLite/SqlLiteCommandBuilderTest.cs +++ b/test/NDbUnit.Test/SqlLite/SqlLiteCommandBuilderTest.cs @@ -8,7 +8,11 @@ using NDbUnit.Core.SqlLite; using NUnit.Framework; using System.Collections.Generic; +#if NETSTANDARD +using Microsoft.Data.Sqlite; +#else using System.Data.SQLite; +#endif namespace NDbUnit.Test.SqlClient { @@ -108,7 +112,11 @@ public override IList ExpectedUpdateCommands protected override IDbCommandBuilder GetDbCommandBuilder() { +#if NETSTANDARD + return new SqlLiteDbCommandBuilder(new DbConnectionManager(DbConnection.SqlLiteConnectionString)); +#else return new SqlLiteDbCommandBuilder(new DbConnectionManager(DbConnection.SqlLiteConnectionString)); +#endif } protected override string GetXmlSchemaFilename() diff --git a/test/NDbUnit.Test/SqlLite/SqlLiteDbOperationTest.cs b/test/NDbUnit.Test/SqlLite/SqlLiteDbOperationTest.cs index 37b1b18..4c73028 100644 --- a/test/NDbUnit.Test/SqlLite/SqlLiteDbOperationTest.cs +++ b/test/NDbUnit.Test/SqlLite/SqlLiteDbOperationTest.cs @@ -9,7 +9,11 @@ using NUnit.Framework; using System; using System.Data; +#if NETSTANDARD +using Microsoft.Data.Sqlite; +#else using System.Data.SQLite; +#endif namespace NDbUnit.Test.SqlLite { @@ -19,7 +23,11 @@ public class SqlLiteDbOperationTest : NDbUnit.Test.Common.DbOperationTestBase { protected override NDbUnit.Core.IDbCommandBuilder GetCommandBuilder() { +#if NETSTANDARD + return new SqlLiteDbCommandBuilder(new DbConnectionManager(DbConnection.SqlLiteConnectionString)); +#else return new SqlLiteDbCommandBuilder(new DbConnectionManager(DbConnection.SqlLiteConnectionString)); +#endif } protected override NDbUnit.Core.IDbOperation GetDbOperation() @@ -30,7 +38,12 @@ protected override NDbUnit.Core.IDbOperation GetDbOperation() protected override IDbCommand GetResetIdentityColumnsDbCommand(DataTable table, DataColumn column) { String sql = String.Format("delete from sqlite_sequence where name = '{0}'", table.TableName); + +#if NETSTANDARD + return new SqliteCommand(sql, (SqliteConnection)_commandBuilder.Connection); +#else return new SQLiteCommand(sql, (SQLiteConnection)_commandBuilder.Connection); +#endif } protected override string GetXmlFilename() diff --git a/test/NDbUnit.Test/SqlLite/SqlLiteUnitTestTest.cs b/test/NDbUnit.Test/SqlLite/SqlLiteUnitTestTest.cs index dc518c9..d75aebf 100644 --- a/test/NDbUnit.Test/SqlLite/SqlLiteUnitTestTest.cs +++ b/test/NDbUnit.Test/SqlLite/SqlLiteUnitTestTest.cs @@ -9,7 +9,11 @@ using NUnit.Framework; using System.Collections.Generic; using System.Data; +#if NETSTANDARD +using Microsoft.Data.Sqlite; +#else using System.Data.SQLite; +#endif using System.IO; namespace NDbUnit.Test.SqlLite @@ -51,10 +55,17 @@ public SqliteDbUnitTestStub(string connectionString) { } +#if NETSTANDARD + protected override IDbCommandBuilder CreateDbCommandBuilder(DbConnectionManager connectionManager ) + { + return _mockDbCommandBuilder; + } +#else protected override IDbCommandBuilder CreateDbCommandBuilder(DbConnectionManager connectionManager ) { return _mockDbCommandBuilder; } +#endif protected override IDbOperation CreateDbOperation() {