From adf0ead44aee5e231c83986747a15031c8c3d2cc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Nov 2023 14:18:02 -0600 Subject: [PATCH] Bump NUnit from 3.14.0 to 4.0.0 (#228) * Bump NUnit from 3.14.0 to 4.0.0 --- FAnsiSql/Connections/ManagedConnection.cs | 1 + FAnsiSql/DatabaseOperationArgs.cs | 3 +- FAnsiSql/Discovery/BulkCopy.cs | 1 + .../ConnectionStringKeywordAccumulator.cs | 22 +- .../Constraints/DiscoveredRelationship.cs | 5 +- FAnsiSql/Discovery/DiscoveredDataType.cs | 2 +- .../Discovery/DiscoveredDatabaseHelper.cs | 4 +- FAnsiSql/Discovery/DiscoveredServerHelper.cs | 2 +- FAnsiSql/Discovery/QuerySyntaxHelper.cs | 4 +- FAnsiSql/FAnsi.csproj | 4 + .../Implementation/ImplementationManager.cs | 2 +- .../MicrosoftSQL/MicrosoftSQLTableHelper.cs | 2 +- .../Oracle/OracleQuerySyntaxHelper.cs | 2 +- .../PostgreSql/PostgreSqlSyntaxHelper.cs | 2 +- Packages.md | 1 + .../Aggregation/AggregationTests.cs | 8 +- .../Aggregation/BasicAggregationTests.cs | 16 +- .../Aggregation/CalendarAggregationTests.cs | 149 +++---- .../CalendarWithPivotAggregationTests.cs | 72 ++-- .../Aggregation/PivotAggregationTests.cs | 9 +- Tests/FAnsiTests/CrossPlatformTests.cs | 281 +++++++++----- .../FAnsiTests/Database/DatabaseLevelTests.cs | 8 +- .../Database/DiscoverTablesTests.cs | 46 ++- Tests/FAnsiTests/DatabaseTests.cs | 13 +- .../EqualityTests_ServerAndDatabase.cs | 27 +- .../Equality/EqualityTests_TableAndColumn.cs | 13 +- Tests/FAnsiTests/Examples.cs | 19 +- Tests/FAnsiTests/ExtensionsTests.cs | 6 +- Tests/FAnsiTests/FAnsiTests.csproj | 6 +- .../ImplementationManagerLoadTests.cs | 2 +- Tests/FAnsiTests/ManagedConnectionTests.cs | 71 ++-- Tests/FAnsiTests/PackageListIsCorrectTests.cs | 23 +- Tests/FAnsiTests/Parameters/ParameterTests.cs | 7 +- .../Query/ParameterNameExtractionTests.cs | 6 +- .../Query/QuerySyntaxHelperDatabaseTests.cs | 3 +- .../Query/QuerySyntaxHelperTests.cs | 91 +++-- ...ConnectionStringKeywordAccumulatorTests.cs | 3 +- .../FAnsiTests/Server/ServerLevelUnitTests.cs | 2 +- Tests/FAnsiTests/Server/ServerTests.cs | 118 ++++-- Tests/FAnsiTests/Table/BadNamesTests.cs | 65 ++-- Tests/FAnsiTests/Table/BasicInsertTests.cs | 12 +- Tests/FAnsiTests/Table/BigIntTests.cs | 18 +- Tests/FAnsiTests/Table/BulkInsertTest.cs | 186 +++++---- .../FAnsiTests/Table/CreatePrimaryKeyTest.cs | 45 ++- Tests/FAnsiTests/Table/CreateTableTests.cs | 214 +++++----- .../FAnsiTests/Table/DataTypeAdjusterTests.cs | 2 +- Tests/FAnsiTests/Table/ForeignKeyTests.cs | 99 +++-- Tests/FAnsiTests/Table/LongNamesTests.cs | 7 +- Tests/FAnsiTests/Table/TableTypeTests.cs | 19 +- .../Table/TableValuedFunctionTests.cs | 14 +- Tests/FAnsiTests/Table/TestRename.cs | 15 +- Tests/FAnsiTests/Table/TopXTests.cs | 10 +- Tests/FAnsiTests/Table/UpdateTests.cs | 6 +- .../DatabaseTypeRequestTests.cs | 7 +- .../TypeTranslation/DatatypeComputerTests.cs | 367 +++++++++++------- .../TypeTranslation/TypeTranslaterTests.cs | 49 ++- .../TypeTranslaterUnitTests.cs | 2 +- 57 files changed, 1312 insertions(+), 881 deletions(-) diff --git a/FAnsiSql/Connections/ManagedConnection.cs b/FAnsiSql/Connections/ManagedConnection.cs index ac4cd620..f071dc6a 100644 --- a/FAnsiSql/Connections/ManagedConnection.cs +++ b/FAnsiSql/Connections/ManagedConnection.cs @@ -48,6 +48,7 @@ public ManagedConnection Clone() /// public void Dispose() { + System.GC.SuppressFinalize(this); if (CloseOnDispose) Connection.Dispose(); } diff --git a/FAnsiSql/DatabaseOperationArgs.cs b/FAnsiSql/DatabaseOperationArgs.cs index 95c72a22..e31d9190 100644 --- a/FAnsiSql/DatabaseOperationArgs.cs +++ b/FAnsiSql/DatabaseOperationArgs.cs @@ -32,7 +32,8 @@ public DatabaseOperationArgs() { } - public DatabaseOperationArgs(IManagedTransaction transactionIfAny, CancellationToken cancellationToken, int timeoutInSeconds) + public DatabaseOperationArgs(IManagedTransaction transactionIfAny, int timeoutInSeconds, + CancellationToken cancellationToken) { TransactionIfAny = transactionIfAny; CancellationToken = cancellationToken; diff --git a/FAnsiSql/Discovery/BulkCopy.cs b/FAnsiSql/Discovery/BulkCopy.cs index 1d2a018b..b74bf345 100644 --- a/FAnsiSql/Discovery/BulkCopy.cs +++ b/FAnsiSql/Discovery/BulkCopy.cs @@ -77,6 +77,7 @@ public void InvalidateTableSchema() /// public virtual void Dispose() { + GC.SuppressFinalize(this); Connection.Dispose(); } diff --git a/FAnsiSql/Discovery/ConnectionStringDefaults/ConnectionStringKeywordAccumulator.cs b/FAnsiSql/Discovery/ConnectionStringDefaults/ConnectionStringKeywordAccumulator.cs index 70312e15..ab78160c 100644 --- a/FAnsiSql/Discovery/ConnectionStringDefaults/ConnectionStringKeywordAccumulator.cs +++ b/FAnsiSql/Discovery/ConnectionStringDefaults/ConnectionStringKeywordAccumulator.cs @@ -12,25 +12,19 @@ namespace FAnsi.Discovery.ConnectionStringDefaults; /// /// Also handles connection string keyword aliases (where two words mean the same thing) /// -public class ConnectionStringKeywordAccumulator +/// +/// Initialises a new blank instance that does nothing. Call to adjust the template connection string options. +/// +/// +public sealed class ConnectionStringKeywordAccumulator(DatabaseType databaseType) { /// - /// describing what implmentation of DbConnectionStringBuilder is being manipulated + /// describing what implementation of DbConnectionStringBuilder is being manipulated /// - public DatabaseType DatabaseType { get; private set; } + public DatabaseType DatabaseType { get; private set; } = databaseType; private readonly Dictionary> _keywords = new(StringComparer.CurrentCultureIgnoreCase); - private readonly DbConnectionStringBuilder _builder; - - /// - /// Initialises a new blank instance that does nothing. Call to adjust the template connection string options. - /// - /// - public ConnectionStringKeywordAccumulator(DatabaseType databaseType) - { - DatabaseType = databaseType; - _builder = ImplementationManager.GetImplementation(databaseType).GetBuilder(); - } + private readonly DbConnectionStringBuilder _builder = ImplementationManager.GetImplementation(databaseType).GetBuilder(); /// /// Adds a new connection string option (which must be compatible with ) diff --git a/FAnsiSql/Discovery/Constraints/DiscoveredRelationship.cs b/FAnsiSql/Discovery/Constraints/DiscoveredRelationship.cs index 8cc24cbe..2020042d 100644 --- a/FAnsiSql/Discovery/Constraints/DiscoveredRelationship.cs +++ b/FAnsiSql/Discovery/Constraints/DiscoveredRelationship.cs @@ -29,7 +29,7 @@ public class DiscoveredRelationship /// Mapping of primary key column(s) in to foreign key column(s) in . If there are more than one entry /// then the foreign key is a composite key. /// - public Dictionary Keys { get; private set; } + public Dictionary Keys { get; } /// /// Describes what happens to records in the when thier parent records (in the ) are deleted. @@ -51,9 +51,8 @@ public DiscoveredRelationship(string fkName, DiscoveredTable pkTable, Discovered Name = fkName; PrimaryKeyTable = pkTable; ForeignKeyTable = fkTable; + Keys = []; CascadeDelete = deleteRule; - - Keys = new Dictionary(); } /// diff --git a/FAnsiSql/Discovery/DiscoveredDataType.cs b/FAnsiSql/Discovery/DiscoveredDataType.cs index c5102a1e..c9536760 100644 --- a/FAnsiSql/Discovery/DiscoveredDataType.cs +++ b/FAnsiSql/Discovery/DiscoveredDataType.cs @@ -23,7 +23,7 @@ public class DiscoveredDataType /// /// All values read from the database record retrieved when assembling the data type (E.g. the cells of the sys.columns record) /// - public Dictionary ProprietaryDatatype = new(); + public Dictionary ProprietaryDatatype = []; /// /// API constructor, instead use instead. diff --git a/FAnsiSql/Discovery/DiscoveredDatabaseHelper.cs b/FAnsiSql/Discovery/DiscoveredDatabaseHelper.cs index d272cc13..867f7dd4 100644 --- a/FAnsiSql/Discovery/DiscoveredDatabaseHelper.cs +++ b/FAnsiSql/Discovery/DiscoveredDatabaseHelper.cs @@ -39,7 +39,7 @@ public DiscoveredTable CreateTable(CreateTableArgs args) var columns = new List(); var customRequests = args.ExplicitColumnDefinitions != null ? args.ExplicitColumnDefinitions.ToList() - : new List(); + : []; if(args.DataTable != null) { @@ -294,7 +294,7 @@ public void ExecuteBatchNonQuery(string sql, DbConnection conn, DbTransaction tr /// Timeout in seconds to run each batch in the public void ExecuteBatchNonQuery(string sql, DbConnection conn, DbTransaction transaction, out Dictionary performanceFigures, int timeout = 30) { - performanceFigures = new Dictionary(); + performanceFigures = []; var sqlBatch = new StringBuilder(); diff --git a/FAnsiSql/Discovery/DiscoveredServerHelper.cs b/FAnsiSql/Discovery/DiscoveredServerHelper.cs index fbfedabb..e4ec8506 100644 --- a/FAnsiSql/Discovery/DiscoveredServerHelper.cs +++ b/FAnsiSql/Discovery/DiscoveredServerHelper.cs @@ -15,7 +15,7 @@ namespace FAnsi.Discovery; /// public abstract class DiscoveredServerHelper:IDiscoveredServerHelper { - private static readonly Dictionary ConnectionStringKeywordAccumulators = new(); + private static readonly Dictionary ConnectionStringKeywordAccumulators = []; /// /// Register a system wide rule that all connection strings of should include the given . diff --git a/FAnsiSql/Discovery/QuerySyntaxHelper.cs b/FAnsiSql/Discovery/QuerySyntaxHelper.cs index 77bae142..3df9b575 100644 --- a/FAnsiSql/Discovery/QuerySyntaxHelper.cs +++ b/FAnsiSql/Discovery/QuerySyntaxHelper.cs @@ -50,7 +50,7 @@ public abstract class QuerySyntaxHelper : IQuerySyntaxHelper public ITypeTranslater TypeTranslater { get; private set; } - private readonly Dictionary factories = new(); + private readonly Dictionary factories = []; public IAggregateHelper AggregateHelper { get; private set; } public IUpdateHelper UpdateHelper { get; set; } @@ -95,7 +95,7 @@ protected string GetAliasConst() public static HashSet GetAllParameterNamesFromQuery(string query) { if (string.IsNullOrWhiteSpace(query)) - return new HashSet(); + return []; var toReturn = new HashSet(ParameterNameRegex.Matches(query).Cast().Select(match => match.Groups[1].Value.Trim()), StringComparer.InvariantCultureIgnoreCase); return toReturn; diff --git a/FAnsiSql/FAnsi.csproj b/FAnsiSql/FAnsi.csproj index 7483ee49..b4b52b75 100644 --- a/FAnsiSql/FAnsi.csproj +++ b/FAnsiSql/FAnsi.csproj @@ -40,6 +40,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/FAnsiSql/Implementation/ImplementationManager.cs b/FAnsiSql/Implementation/ImplementationManager.cs index 1ec88d11..7688083d 100644 --- a/FAnsiSql/Implementation/ImplementationManager.cs +++ b/FAnsiSql/Implementation/ImplementationManager.cs @@ -27,7 +27,7 @@ public class ImplementationManager private ImplementationManager() { - _implementations = new List(); + _implementations = []; } /// diff --git a/FAnsiSql/Implementations/MicrosoftSQL/MicrosoftSQLTableHelper.cs b/FAnsiSql/Implementations/MicrosoftSQL/MicrosoftSQLTableHelper.cs index 34879e0b..1005c9e5 100644 --- a/FAnsiSql/Implementations/MicrosoftSQL/MicrosoftSQLTableHelper.cs +++ b/FAnsiSql/Implementations/MicrosoftSQL/MicrosoftSQLTableHelper.cs @@ -108,7 +108,7 @@ public override void DropTable(DbConnection connection, DiscoveredTable tableToD DropFunction(connection,(DiscoveredTableValuedFunction) tableToDrop); return; default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(tableToDrop),$"Unknown table type {tableToDrop.TableType}"); } using(cmd) diff --git a/FAnsiSql/Implementations/Oracle/OracleQuerySyntaxHelper.cs b/FAnsiSql/Implementations/Oracle/OracleQuerySyntaxHelper.cs index 3ad73725..9f36ad8a 100644 --- a/FAnsiSql/Implementations/Oracle/OracleQuerySyntaxHelper.cs +++ b/FAnsiSql/Implementations/Oracle/OracleQuerySyntaxHelper.cs @@ -92,7 +92,7 @@ public override string GetAutoIncrementKeywordIfAny() public override Dictionary GetSQLFunctionsDictionary() { - return new Dictionary(); + return []; } public override string HowDoWeAchieveMd5(string selectSql) diff --git a/FAnsiSql/Implementations/PostgreSql/PostgreSqlSyntaxHelper.cs b/FAnsiSql/Implementations/PostgreSql/PostgreSqlSyntaxHelper.cs index 97ea9fc4..9cbba35d 100644 --- a/FAnsiSql/Implementations/PostgreSql/PostgreSqlSyntaxHelper.cs +++ b/FAnsiSql/Implementations/PostgreSql/PostgreSqlSyntaxHelper.cs @@ -104,7 +104,7 @@ public override string GetAutoIncrementKeywordIfAny() public override Dictionary GetSQLFunctionsDictionary() { - return new Dictionary(); + return []; } public override string HowDoWeAchieveMd5(string selectSql) diff --git a/Packages.md b/Packages.md index 460c6b57..2b4044a7 100644 --- a/Packages.md +++ b/Packages.md @@ -15,3 +15,4 @@ | Oracle.ManagedDataAccess.Core | Closed Source | [OTNLA](https://www.oracle.com/downloads/licenses/distribution-license.html) | Enables interaction with Oracle databases | | HIC.TypeGuesser | [GitHub](https://github.com/HicServices/TypeGuesser) | [MIT](https://opensource.org/licenses/MIT)| Allows picking system Types for untyped strings e.g. `"12.3"`| | | Npgsql | [GitHub](https://github.com/npgsql/npgsql) | [PostgreSQL](https://github.com/npgsql/npgsql/blob/dev/LICENSE)| Enables interaction with Postgres databases | | +| [NUnit.Analyzers](https://nunit.org/) |[GitHub](https://github.com/nunit/nunit.analyzers) | [MIT](https://opensource.org/licenses/MIT) | Unit testing support code | diff --git a/Tests/FAnsiTests/Aggregation/AggregationTests.cs b/Tests/FAnsiTests/Aggregation/AggregationTests.cs index 79fcafb2..1f0c2fc9 100644 --- a/Tests/FAnsiTests/Aggregation/AggregationTests.cs +++ b/Tests/FAnsiTests/Aggregation/AggregationTests.cs @@ -10,8 +10,8 @@ namespace FAnsiTests.Aggregation; internal class AggregationTests:DatabaseTests { - private readonly Dictionary _easyTables = new(); - private readonly Dictionary _hardTables = new(); + private readonly Dictionary _easyTables = []; + private readonly Dictionary _hardTables = []; [OneTimeSetUp] public void Setup() @@ -88,7 +88,7 @@ private void SetupDatabaseTable(bool easy, string name) protected void AssertHasRow(DataTable dt, params object[] cells) { - Assert.IsTrue(dt.Rows.Cast().Any(r=>IsMatch(r,cells)),"Did not find expected row:{0}", string.Join("|",cells)); + Assert.That(dt.Rows.Cast().Any(r=>IsMatch(r,cells)),"Did not find expected row:{0}", string.Join("|",cells)); } /// @@ -173,7 +173,7 @@ protected DiscoveredTable GetTestTable(DatabaseType type, bool easy = false) var dic = easy ? _easyTables : _hardTables; if (!dic.ContainsKey(type)) - Assert.Inconclusive("No connection string found for Test database type {0}", type); + Assert.Inconclusive($"No connection string found for Test database type {type}"); return dic[type]; } diff --git a/Tests/FAnsiTests/Aggregation/BasicAggregationTests.cs b/Tests/FAnsiTests/Aggregation/BasicAggregationTests.cs index ab769422..8fcba434 100644 --- a/Tests/FAnsiTests/Aggregation/BasicAggregationTests.cs +++ b/Tests/FAnsiTests/Aggregation/BasicAggregationTests.cs @@ -28,7 +28,7 @@ public void Test_BasicCount(DatabaseType type) con.Open(); var cmd = svr.GetCommand(sql, con); - Assert.AreEqual(14, Convert.ToInt32(cmd.ExecuteScalar())); + Assert.That(Convert.ToInt32(cmd.ExecuteScalar()), Is.EqualTo(14)); } @@ -61,11 +61,15 @@ public void Test_GroupByCount(DatabaseType type) using var dt = new DataTable(); da.Fill(dt); - Assert.AreEqual(4, dt.Rows.Count); - Assert.AreEqual("E&, %a' mp;E", dt.Rows[0][1]); - Assert.AreEqual(3, dt.Rows[0][0]); + Assert.Multiple(() => + { + Assert.That(dt.Rows, Has.Count.EqualTo(4)); + + Assert.That(dt.Rows[0][1], Is.EqualTo("E&, %a' mp;E")); + Assert.That(dt.Rows[0][0], Is.EqualTo(3)); - Assert.AreEqual("F", dt.Rows[1][1]); - Assert.AreEqual(2, dt.Rows[1][0]); + Assert.That(dt.Rows[1][1], Is.EqualTo("F")); + Assert.That(dt.Rows[1][0], Is.EqualTo(2)); + }); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/Aggregation/CalendarAggregationTests.cs b/Tests/FAnsiTests/Aggregation/CalendarAggregationTests.cs index d74d1af8..ce8f0876 100644 --- a/Tests/FAnsiTests/Aggregation/CalendarAggregationTests.cs +++ b/Tests/FAnsiTests/Aggregation/CalendarAggregationTests.cs @@ -49,27 +49,30 @@ public void Test_Calendar_Year(DatabaseType type) using var dt = new DataTable(); da.Fill(dt); - Assert.AreEqual(10, dt.Rows.Count); //there are 10 years between 2001 and 2010 even though not all years are represented in the data - Assert.AreEqual(2001, dt.Rows[0][0]); - Assert.AreEqual(5, dt.Rows[0][1]); - Assert.AreEqual(2002, dt.Rows[1][0]); - Assert.AreEqual(5, dt.Rows[1][1]); - Assert.AreEqual(2003, dt.Rows[2][0]); - Assert.AreEqual(2, dt.Rows[2][1]); - Assert.AreEqual(2004, dt.Rows[3][0]); - Assert.AreEqual(DBNull.Value, dt.Rows[3][1]); - Assert.AreEqual(2005, dt.Rows[4][0]); - Assert.AreEqual(1, dt.Rows[4][1]); - Assert.AreEqual(2006, dt.Rows[5][0]); - Assert.AreEqual(DBNull.Value, dt.Rows[5][1]); - Assert.AreEqual(2007, dt.Rows[6][0]); - Assert.AreEqual(DBNull.Value, dt.Rows[6][1]); - Assert.AreEqual(2008, dt.Rows[7][0]); - Assert.AreEqual(DBNull.Value, dt.Rows[7][1]); - Assert.AreEqual(2009, dt.Rows[8][0]); - Assert.AreEqual(DBNull.Value, dt.Rows[8][1]); - Assert.AreEqual(2010, dt.Rows[9][0]); - Assert.AreEqual(DBNull.Value, dt.Rows[9][1]); + Assert.That(dt.Rows, Has.Count.EqualTo(10)); //there are 10 years between 2001 and 2010 even though not all years are represented in the data + Assert.Multiple(() => + { + Assert.That(dt.Rows[0][0], Is.EqualTo(2001)); + Assert.That(dt.Rows[0][1], Is.EqualTo(5)); + Assert.That(dt.Rows[1][0], Is.EqualTo(2002)); + Assert.That(dt.Rows[1][1], Is.EqualTo(5)); + Assert.That(dt.Rows[2][0], Is.EqualTo(2003)); + Assert.That(dt.Rows[2][1], Is.EqualTo(2)); + Assert.That(dt.Rows[3][0], Is.EqualTo(2004)); + Assert.That(dt.Rows[3][1], Is.EqualTo(DBNull.Value)); + Assert.That(dt.Rows[4][0], Is.EqualTo(2005)); + Assert.That(dt.Rows[4][1], Is.EqualTo(1)); + Assert.That(dt.Rows[5][0], Is.EqualTo(2006)); + Assert.That(dt.Rows[5][1], Is.EqualTo(DBNull.Value)); + Assert.That(dt.Rows[6][0], Is.EqualTo(2007)); + Assert.That(dt.Rows[6][1], Is.EqualTo(DBNull.Value)); + Assert.That(dt.Rows[7][0], Is.EqualTo(2008)); + Assert.That(dt.Rows[7][1], Is.EqualTo(DBNull.Value)); + Assert.That(dt.Rows[8][0], Is.EqualTo(2009)); + Assert.That(dt.Rows[8][1], Is.EqualTo(DBNull.Value)); + Assert.That(dt.Rows[9][0], Is.EqualTo(2010)); + Assert.That(dt.Rows[9][1], Is.EqualTo(DBNull.Value)); + }); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -109,7 +112,7 @@ public void Test_Calendar_Quarter(DatabaseType type) ConsoleWriteTable(dt); - Assert.AreEqual(37, dt.Rows.Count); // 4 quarters per year between 2001 and 2009 + 2010Q1 + Assert.That(dt.Rows, Has.Count.EqualTo(37)); // 4 quarters per year between 2001 and 2009 + 2010Q1 AssertHasRow(dt, "2001Q1", 5); AssertHasRow(dt, "2001Q2", null); @@ -154,7 +157,7 @@ public void Test_Calendar_Month(DatabaseType type) ConsoleWriteTable(dt); - Assert.AreEqual(109, dt.Rows.Count); // 109 months between 2001 and 2010 (inclusive) + Assert.That(dt.Rows, Has.Count.EqualTo(109)); // 109 months between 2001 and 2010 (inclusive) AssertHasRow(dt,"2001-01",5); AssertHasRow(dt, "2001-02", null); @@ -196,7 +199,7 @@ public void Test_Calendar_Day(DatabaseType type) using var dt = new DataTable(); da.Fill(dt); - Assert.AreEqual(3288, dt.Rows.Count); // 109 months between 2001 and 2010 (inclusive) + Assert.That(dt.Rows, Has.Count.EqualTo(3288)); // 109 months between 2001 and 2010 (inclusive) AssertHasRow(dt, new DateTime(2001,1,1), 4); AssertHasRow(dt, new DateTime(2001, 1, 2), 1); @@ -242,31 +245,34 @@ public void Test_Calendar_ToToday(DatabaseType type) using var dt = new DataTable(); da.Fill(dt); - Assert.GreaterOrEqual(dt.Rows.Count, 19); //there are 19 years between 2001 and 2019 (use greater than because we don't want test to fail in 2020) - Assert.AreEqual(2001, dt.Rows[0][0]); - Assert.AreEqual(5, dt.Rows[0][1]); - Assert.AreEqual(2002, dt.Rows[1][0]); - Assert.AreEqual(5, dt.Rows[1][1]); - Assert.AreEqual(2003, dt.Rows[2][0]); - Assert.AreEqual(2, dt.Rows[2][1]); - Assert.AreEqual(2004, dt.Rows[3][0]); - Assert.AreEqual(DBNull.Value, dt.Rows[3][1]); - Assert.AreEqual(2005, dt.Rows[4][0]); - Assert.AreEqual(1, dt.Rows[4][1]); - Assert.AreEqual(2006, dt.Rows[5][0]); - Assert.AreEqual(DBNull.Value, dt.Rows[5][1]); - Assert.AreEqual(2007, dt.Rows[6][0]); - Assert.AreEqual(DBNull.Value, dt.Rows[6][1]); - Assert.AreEqual(2008, dt.Rows[7][0]); - Assert.AreEqual(DBNull.Value, dt.Rows[7][1]); - Assert.AreEqual(2009, dt.Rows[8][0]); - Assert.AreEqual(DBNull.Value, dt.Rows[8][1]); - Assert.AreEqual(2010, dt.Rows[9][0]); - Assert.AreEqual(DBNull.Value, dt.Rows[9][1]); - - //should go up to this year - Assert.AreEqual(DateTime.Now.Year, dt.Rows[^1][0]); - Assert.AreEqual(DBNull.Value, dt.Rows[9][1]); + Assert.That(dt.Rows, Has.Count.GreaterThanOrEqualTo(19)); //there are 19 years between 2001 and 2019 (use greater than because we don't want test to fail in 2020) + Assert.Multiple(() => + { + Assert.That(dt.Rows[0][0], Is.EqualTo(2001)); + Assert.That(dt.Rows[0][1], Is.EqualTo(5)); + Assert.That(dt.Rows[1][0], Is.EqualTo(2002)); + Assert.That(dt.Rows[1][1], Is.EqualTo(5)); + Assert.That(dt.Rows[2][0], Is.EqualTo(2003)); + Assert.That(dt.Rows[2][1], Is.EqualTo(2)); + Assert.That(dt.Rows[3][0], Is.EqualTo(2004)); + Assert.That(dt.Rows[3][1], Is.EqualTo(DBNull.Value)); + Assert.That(dt.Rows[4][0], Is.EqualTo(2005)); + Assert.That(dt.Rows[4][1], Is.EqualTo(1)); + Assert.That(dt.Rows[5][0], Is.EqualTo(2006)); + Assert.That(dt.Rows[5][1], Is.EqualTo(DBNull.Value)); + Assert.That(dt.Rows[6][0], Is.EqualTo(2007)); + Assert.That(dt.Rows[6][1], Is.EqualTo(DBNull.Value)); + Assert.That(dt.Rows[7][0], Is.EqualTo(2008)); + Assert.That(dt.Rows[7][1], Is.EqualTo(DBNull.Value)); + Assert.That(dt.Rows[8][0], Is.EqualTo(2009)); + Assert.That(dt.Rows[8][1], Is.EqualTo(DBNull.Value)); + Assert.That(dt.Rows[9][0], Is.EqualTo(2010)); + Assert.That(dt.Rows[9][1], Is.EqualTo(DBNull.Value)); + + //should go up to this year + Assert.That(dt.Rows[^1][0], Is.EqualTo(DateTime.Now.Year)); + }); + Assert.That(dt.Rows[9][1], Is.EqualTo(DBNull.Value)); } /// @@ -311,26 +317,29 @@ public void Test_Calendar_SELECTColumnOrder_CountAfterAxisColumn(DatabaseType ty using var dt = new DataTable(); da.Fill(dt); - Assert.AreEqual(10, dt.Rows.Count); //there are 10 years between 2001 and 2010 even though not all years are represented in the data - Assert.AreEqual(2001, dt.Rows[0][0]); - Assert.AreEqual(5, dt.Rows[0][1]); - Assert.AreEqual(2002, dt.Rows[1][0]); - Assert.AreEqual(5, dt.Rows[1][1]); - Assert.AreEqual(2003, dt.Rows[2][0]); - Assert.AreEqual(2, dt.Rows[2][1]); - Assert.AreEqual(2004, dt.Rows[3][0]); - Assert.AreEqual(DBNull.Value, dt.Rows[3][1]); - Assert.AreEqual(2005, dt.Rows[4][0]); - Assert.AreEqual(1, dt.Rows[4][1]); - Assert.AreEqual(2006, dt.Rows[5][0]); - Assert.AreEqual(DBNull.Value, dt.Rows[5][1]); - Assert.AreEqual(2007, dt.Rows[6][0]); - Assert.AreEqual(DBNull.Value, dt.Rows[6][1]); - Assert.AreEqual(2008, dt.Rows[7][0]); - Assert.AreEqual(DBNull.Value, dt.Rows[7][1]); - Assert.AreEqual(2009, dt.Rows[8][0]); - Assert.AreEqual(DBNull.Value, dt.Rows[8][1]); - Assert.AreEqual(2010, dt.Rows[9][0]); - Assert.AreEqual(DBNull.Value, dt.Rows[9][1]); + Assert.That(dt.Rows, Has.Count.EqualTo(10)); //there are 10 years between 2001 and 2010 even though not all years are represented in the data + Assert.Multiple(() => + { + Assert.That(dt.Rows[0][0], Is.EqualTo(2001)); + Assert.That(dt.Rows[0][1], Is.EqualTo(5)); + Assert.That(dt.Rows[1][0], Is.EqualTo(2002)); + Assert.That(dt.Rows[1][1], Is.EqualTo(5)); + Assert.That(dt.Rows[2][0], Is.EqualTo(2003)); + Assert.That(dt.Rows[2][1], Is.EqualTo(2)); + Assert.That(dt.Rows[3][0], Is.EqualTo(2004)); + Assert.That(dt.Rows[3][1], Is.EqualTo(DBNull.Value)); + Assert.That(dt.Rows[4][0], Is.EqualTo(2005)); + Assert.That(dt.Rows[4][1], Is.EqualTo(1)); + Assert.That(dt.Rows[5][0], Is.EqualTo(2006)); + Assert.That(dt.Rows[5][1], Is.EqualTo(DBNull.Value)); + Assert.That(dt.Rows[6][0], Is.EqualTo(2007)); + Assert.That(dt.Rows[6][1], Is.EqualTo(DBNull.Value)); + Assert.That(dt.Rows[7][0], Is.EqualTo(2008)); + Assert.That(dt.Rows[7][1], Is.EqualTo(DBNull.Value)); + Assert.That(dt.Rows[8][0], Is.EqualTo(2009)); + Assert.That(dt.Rows[8][1], Is.EqualTo(DBNull.Value)); + Assert.That(dt.Rows[9][0], Is.EqualTo(2010)); + Assert.That(dt.Rows[9][1], Is.EqualTo(DBNull.Value)); + }); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/Aggregation/CalendarWithPivotAggregationTests.cs b/Tests/FAnsiTests/Aggregation/CalendarWithPivotAggregationTests.cs index b2b3cded..c1e3dfdb 100644 --- a/Tests/FAnsiTests/Aggregation/CalendarWithPivotAggregationTests.cs +++ b/Tests/FAnsiTests/Aggregation/CalendarWithPivotAggregationTests.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Data; +using NUnit.Framework.Legacy; namespace FAnsiTests.Aggregation; @@ -71,8 +72,7 @@ 2009 0 0 0 0 2010 0 0 0 0 */ - Assert.AreEqual(10, - dt.Rows.Count); //there are 10 years between 2001 and 2010 even though not all years are represented in the data + Assert.That(dt.Rows, Has.Count.EqualTo(10)); //there are 10 years between 2001 and 2010 even though not all years are represented in the data // only validate hard output, we got rows on easy thats enough for now if (easy) @@ -84,39 +84,41 @@ 2010 0 0 0 0 StringAssert.AreEqualIgnoringCase("F", dt.Columns[3].ColumnName); StringAssert.AreEqualIgnoringCase("G", dt.Columns[4].ColumnName); - Assert.AreEqual(2001, dt.Rows[0][0]); - Assert.AreEqual(3, dt.Rows[0][1]); - Assert.AreEqual(1, dt.Rows[0][2]); - Assert.AreEqual(0, dt.Rows[0][3]); - Assert.AreEqual(1, dt.Rows[0][4]); - - Assert.AreEqual(2002, dt.Rows[1][0]); - Assert.AreEqual(2, dt.Rows[1][1]); - Assert.AreEqual(1, dt.Rows[1][2]); - Assert.AreEqual(2, dt.Rows[1][3]); - Assert.AreEqual(0, dt.Rows[1][4]); - - Assert.AreEqual(2003, dt.Rows[2][0]); - Assert.AreEqual(2, dt.Rows[2][1]); - Assert.AreEqual(0, dt.Rows[2][2]); - Assert.AreEqual(0, dt.Rows[2][3]); - Assert.AreEqual(0, dt.Rows[2][4]); - - Assert.AreEqual(2004, dt.Rows[3][0]); - Assert.AreEqual(0, dt.Rows[3][1] == DBNull.Value ? 0 : dt.Rows[3][1]); - Assert.AreEqual(0, - dt.Rows[3][2] == DBNull.Value - ? 0 - : dt.Rows[3][ - 1]); //null is permitted because this row doesn't have any matching records... peculiarity of MySql implementation but null=0 is ok for aggregates - Assert.AreEqual(0, dt.Rows[3][3] == DBNull.Value ? 0 : dt.Rows[3][1]); - Assert.AreEqual(0, dt.Rows[3][4] == DBNull.Value ? 0 : dt.Rows[3][1]); - - Assert.AreEqual(2005, dt.Rows[4][0]); - Assert.AreEqual(0, dt.Rows[4][1]); - Assert.AreEqual(1, dt.Rows[4][2]); - Assert.AreEqual(0, dt.Rows[4][3]); - Assert.AreEqual(0, dt.Rows[4][4]); + Assert.Multiple(() => + { + Assert.That(dt.Rows[0][0], Is.EqualTo(2001)); + Assert.That(dt.Rows[0][1], Is.EqualTo(3)); + Assert.That(dt.Rows[0][2], Is.EqualTo(1)); + Assert.That(dt.Rows[0][3], Is.EqualTo(0)); + Assert.That(dt.Rows[0][4], Is.EqualTo(1)); + + Assert.That(dt.Rows[1][0], Is.EqualTo(2002)); + Assert.That(dt.Rows[1][1], Is.EqualTo(2)); + Assert.That(dt.Rows[1][2], Is.EqualTo(1)); + Assert.That(dt.Rows[1][3], Is.EqualTo(2)); + Assert.That(dt.Rows[1][4], Is.EqualTo(0)); + + Assert.That(dt.Rows[2][0], Is.EqualTo(2003)); + Assert.That(dt.Rows[2][1], Is.EqualTo(2)); + Assert.That(dt.Rows[2][2], Is.EqualTo(0)); + Assert.That(dt.Rows[2][3], Is.EqualTo(0)); + Assert.That(dt.Rows[2][4], Is.EqualTo(0)); + + Assert.That(dt.Rows[3][0], Is.EqualTo(2004)); + Assert.That(dt.Rows[3][1] == DBNull.Value ? 0 : dt.Rows[3][1], Is.EqualTo(0)); + Assert.That(dt.Rows[3][2] == DBNull.Value + ? 0 + : dt.Rows[3][ + 1], Is.EqualTo(0)); //null is permitted because this row doesn't have any matching records... peculiarity of MySql implementation but null=0 is ok for aggregates + Assert.That(dt.Rows[3][3] == DBNull.Value ? 0 : dt.Rows[3][1], Is.EqualTo(0)); + Assert.That(dt.Rows[3][4] == DBNull.Value ? 0 : dt.Rows[3][1], Is.EqualTo(0)); + + Assert.That(dt.Rows[4][0], Is.EqualTo(2005)); + Assert.That(dt.Rows[4][1], Is.EqualTo(0)); + Assert.That(dt.Rows[4][2], Is.EqualTo(1)); + Assert.That(dt.Rows[4][3], Is.EqualTo(0)); + Assert.That(dt.Rows[4][4], Is.EqualTo(0)); + }); } catch (Exception) { diff --git a/Tests/FAnsiTests/Aggregation/PivotAggregationTests.cs b/Tests/FAnsiTests/Aggregation/PivotAggregationTests.cs index 9af95048..c05833af 100644 --- a/Tests/FAnsiTests/Aggregation/PivotAggregationTests.cs +++ b/Tests/FAnsiTests/Aggregation/PivotAggregationTests.cs @@ -46,8 +46,11 @@ T 2 0 1 1 1 1 0 1 using var dt = new DataTable(); da.Fill(dt); - Assert.AreEqual(9, dt.Columns.Count); - Assert.AreEqual(4, dt.Rows.Count); - Assert.AreEqual("Cat", dt.Columns[0].ColumnName); + Assert.Multiple(() => + { + Assert.That(dt.Columns, Has.Count.EqualTo(9)); + Assert.That(dt.Rows, Has.Count.EqualTo(4)); + Assert.That(dt.Columns[0].ColumnName, Is.EqualTo("Cat")); + }); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/CrossPlatformTests.cs b/Tests/FAnsiTests/CrossPlatformTests.cs index 29f7f7ef..72c6af74 100644 --- a/Tests/FAnsiTests/CrossPlatformTests.cs +++ b/Tests/FAnsiTests/CrossPlatformTests.cs @@ -10,6 +10,7 @@ using FAnsi.Discovery.QuerySyntax; using FAnsiTests.TypeTranslation; using NUnit.Framework; +using NUnit.Framework.Legacy; using TypeGuesser; using TypeGuesser.Deciders; @@ -40,7 +41,7 @@ public void DateColumnTests_NoTime(DatabaseType type, object input) var tbl = db.CreateTable("MyTable",new []{new DatabaseColumnRequest("MyDate",new DatabaseTypeRequest(typeof(DateTime)))}); tbl.Insert(new Dictionary { { "MyDate", input } }); - + using (var blk = tbl.BeginBulkInsert()) { using var dt = new DataTable(); @@ -52,8 +53,11 @@ public void DateColumnTests_NoTime(DatabaseType type, object input) var result = tbl.GetDataTable(); var expectedDate = new DateTime(2007, 1, 1); - Assert.AreEqual(expectedDate, result.Rows[0][0]); - Assert.AreEqual(expectedDate, result.Rows[1][0]); + Assert.Multiple(() => + { + Assert.That(result.Rows[0][0], Is.EqualTo(expectedDate)); + Assert.That(result.Rows[1][0], Is.EqualTo(expectedDate)); + }); } [TestCase(DatabaseType.MicrosoftSQLServer, "2/28/1993 5:36:27 AM","en-US")] @@ -73,7 +77,7 @@ public void DateColumnTests_UkUsFormat_Explicit(DatabaseType type, object input, //basic insert tbl.Insert(new Dictionary { { "MyDate", input } },cultureInfo); - + //then bulk insert, both need to work using (var blk = tbl.BeginBulkInsert(cultureInfo)) { @@ -86,8 +90,11 @@ public void DateColumnTests_UkUsFormat_Explicit(DatabaseType type, object input, var result = tbl.GetDataTable(); var expectedDate = new DateTime(1993, 2,28,5,36,27); - Assert.AreEqual(expectedDate, result.Rows[0][0]); - Assert.AreEqual(expectedDate, result.Rows[1][0]); + Assert.Multiple(() => + { + Assert.That(result.Rows[0][0], Is.EqualTo(expectedDate)); + Assert.That(result.Rows[1][0], Is.EqualTo(expectedDate)); + }); } @@ -121,13 +128,13 @@ public void DateColumnTests_PrimaryKeyColumn(DatabaseType type, object input, st dt.PrimaryKey = new[]{ dt.Columns[0]}; blk.Upload(dt); - Assert.AreEqual(1,dt.PrimaryKey.Length); - Assert.AreEqual("MyDate",dt.PrimaryKey[0].ColumnName); + Assert.That(dt.PrimaryKey, Has.Length.EqualTo(1)); + Assert.That(dt.PrimaryKey[0].ColumnName, Is.EqualTo("MyDate")); } var result = tbl.GetDataTable(); var expectedDate = new DateTime(1993, 2,28,5,36,27); - Assert.AreEqual(expectedDate, result.Rows[0][0]); + Assert.That(result.Rows[0][0], Is.EqualTo(expectedDate)); } @@ -165,9 +172,11 @@ public void DateColumnTests_TimeOnly_Midnight(DatabaseType type, object input) .Cast().ToArray() : new[] { result.Rows[0][0], result.Rows[1][0] }; - - Assert.AreEqual(expectedTime, resultTimeSpans[0]); - Assert.AreEqual(expectedTime, resultTimeSpans[1]); + Assert.Multiple(() => + { + Assert.That(resultTimeSpans[0], Is.EqualTo(expectedTime)); + Assert.That(resultTimeSpans[1], Is.EqualTo(expectedTime)); + }); } /* @@ -234,17 +243,17 @@ public void DateColumnTests_TimeOnly_Afternoon(DatabaseType type, object input) var resultTimeSpans = //Oracle is a bit special it only stores whole dates then has server side settings about how much to return (like a format string) type == DatabaseType.Oracle - ? new[] { (DateTime)result.Rows[0][0], (DateTime)result.Rows[1][0] }.Select(dt => dt.TimeOfDay) + ? new[] { (DateTime)result.Rows[0][0], (DateTime)result.Rows[1][0] }.Select(static dt => dt.TimeOfDay) .Cast().ToArray() - : new[] { result.Rows[0][0], result.Rows[1][0] }; + : [result.Rows[0][0], result.Rows[1][0]]; - foreach (TimeSpan t in resultTimeSpans) + foreach (var t in resultTimeSpans.Cast()) { if(t.Seconds>0) - Assert.AreEqual(10,t.Seconds); + Assert.That(t.Seconds, Is.EqualTo(10)); var eval = t.Subtract(new TimeSpan(0, 0, 0, t.Seconds)); - Assert.AreEqual(expectedTime,eval); + Assert.That(eval, Is.EqualTo(expectedTime)); } } @@ -282,7 +291,7 @@ public void TypeConsensusBetweenGuesserAndDiscoveredTableTest(DatabaseType dbTyp database.CreateTable(tbl.GetRuntimeName(),dt); - Assert.AreEqual(datatType, c.GetSqlDBType(tt)); + Assert.That(c.GetSqlDBType(tt), Is.EqualTo(datatType)); var expectedDataType = datatType; @@ -295,8 +304,11 @@ public void TypeConsensusBetweenGuesserAndDiscoveredTableTest(DatabaseType dbTyp _ => expectedDataType }; - Assert.AreEqual(expectedDataType,tbl.DiscoverColumn("mycol").DataType.SQLType); - Assert.AreEqual(1,tbl.GetRowCount()); + Assert.Multiple(() => + { + Assert.That(tbl.DiscoverColumn("mycol").DataType.SQLType, Is.EqualTo(expectedDataType)); + Assert.That(tbl.GetRowCount(), Is.EqualTo(1)); + }); tbl.Drop(); } @@ -354,8 +366,11 @@ public void ForeignKeyCreationTest(DatabaseType type) $"INSERT INTO {tblChild.GetFullyQualifiedName()} VALUES (1,'chucky2')", con).ExecuteNonQuery(); } - Assert.AreEqual(2,tblParent.GetRowCount()); - Assert.AreEqual(2, tblChild.GetRowCount()); + Assert.Multiple(() => + { + Assert.That(tblParent.GetRowCount(), Is.EqualTo(2)); + Assert.That(tblChild.GetRowCount(), Is.EqualTo(2)); + }); using (var con = tblParent.Database.Server.GetConnection()) { @@ -365,8 +380,11 @@ public void ForeignKeyCreationTest(DatabaseType type) cmd.ExecuteNonQuery(); } - Assert.AreEqual(0,tblParent.GetRowCount()); - Assert.AreEqual(0, tblChild.GetRowCount()); + Assert.Multiple(() => + { + Assert.That(tblParent.GetRowCount(), Is.EqualTo(0)); + Assert.That(tblChild.GetRowCount(), Is.EqualTo(0)); + }); } finally { @@ -432,8 +450,11 @@ public void ForeignKeyCreationTest_TwoColumns(DatabaseType type, bool cascadeDel $"INSERT INTO {tblChild.GetFullyQualifiedName()} VALUES (1,2,'chucky2')", con).ExecuteNonQuery(); } - Assert.AreEqual(1, tblParent.GetRowCount()); - Assert.AreEqual(2, tblChild.GetRowCount()); + Assert.Multiple(() => + { + Assert.That(tblParent.GetRowCount(), Is.EqualTo(1)); + Assert.That(tblChild.GetRowCount(), Is.EqualTo(2)); + }); using (var con = tblParent.Database.Server.GetConnection()) { @@ -443,8 +464,11 @@ public void ForeignKeyCreationTest_TwoColumns(DatabaseType type, bool cascadeDel if (cascadeDelete) { cmd.ExecuteNonQuery(); - Assert.AreEqual(0, tblParent.GetRowCount()); - Assert.AreEqual(0, tblChild.GetRowCount()); + Assert.Multiple(() => + { + Assert.That(tblParent.GetRowCount(), Is.EqualTo(0)); + Assert.That(tblChild.GetRowCount(), Is.EqualTo(0)); + }); } else { @@ -469,11 +493,14 @@ public void CreateMaxVarcharColumns(DatabaseType type) new DatabaseColumnRequest("Field6",new DatabaseTypeRequest(typeof(string),10)) //varchar(10) }); - Assert.IsTrue(tbl.Exists()); + Assert.Multiple(() => + { + Assert.That(tbl.Exists()); - Assert.GreaterOrEqual(tbl.DiscoverColumn("Field1").DataType.GetLengthIfString(),4000); - Assert.GreaterOrEqual(tbl.DiscoverColumn("Field2").DataType.GetLengthIfString(), 1000); // unknown size should be at least 1k? that seems sensible - Assert.AreEqual(10,tbl.DiscoverColumn("Field6").DataType.GetLengthIfString()); + Assert.That(tbl.DiscoverColumn("Field1").DataType.GetLengthIfString(), Is.GreaterThanOrEqualTo(4000)); + Assert.That(tbl.DiscoverColumn("Field2").DataType.GetLengthIfString(), Is.GreaterThanOrEqualTo(1000)); // unknown size should be at least 1k? that seems sensible + Assert.That(tbl.DiscoverColumn("Field6").DataType.GetLengthIfString(), Is.EqualTo(10)); + }); } @@ -494,11 +521,14 @@ public void CreateMaxVarcharColumnFromDataTable(DatabaseType type) var tbl= database.CreateTable("MassiveTable", dt); - Assert.IsTrue(tbl.Exists()); - Assert.GreaterOrEqual(tbl.DiscoverColumn("MassiveColumn").DataType.GetLengthIfString(),8000); + Assert.Multiple(() => + { + Assert.That(tbl.Exists()); + Assert.That(tbl.DiscoverColumn("MassiveColumn").DataType.GetLengthIfString(), Is.GreaterThanOrEqualTo(8000)); + }); dt = tbl.GetDataTable(); - Assert.AreEqual(sb.ToString(),dt.Rows[0][0]); + Assert.That(dt.Rows[0][0], Is.EqualTo(sb.ToString())); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -512,10 +542,10 @@ public void CreateDateColumnFromDataTable(DatabaseType type) var tbl = database.CreateTable("DateTable", dt); - Assert.IsTrue(tbl.Exists()); + Assert.That(tbl.Exists()); dt = tbl.GetDataTable(); - Assert.AreEqual(new DateTime(2001,01,22), dt.Rows[0][0]); + Assert.That(dt.Rows[0][0], Is.EqualTo(new DateTime(2001,01,22))); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypesWithBoolFlags))] @@ -531,15 +561,18 @@ public void AddColumnTest(DatabaseType type,bool useTransaction) new DatabaseColumnRequest("Field1",new DatabaseTypeRequest(typeof(string),100)){IsPrimaryKey = true} //varchar(max) }); + Assert.Multiple(() => + { - //table should exist - Assert.IsTrue(tbl.Exists()); + //table should exist + Assert.That(tbl.Exists()); - //column should be varchar(100) - Assert.AreEqual(100, tbl.DiscoverColumn("Field1").DataType.GetLengthIfString()); + //column should be varchar(100) + Assert.That(tbl.DiscoverColumn("Field1").DataType.GetLengthIfString(), Is.EqualTo(100)); - //and should be a primary key - Assert.IsTrue(tbl.DiscoverColumn("Field1").IsPrimaryKey); + //and should be a primary key + Assert.That(tbl.DiscoverColumn("Field1").IsPrimaryKey); + }); //ALTER TABLE to ADD COLUMN of date type if (useTransaction) @@ -560,7 +593,7 @@ public void AddColumnTest(DatabaseType type,bool useTransaction) //and should have a type of datetime as requested var typeCreated = newCol.DataType.SQLType; var tt = database.Server.GetQuerySyntaxHelper().TypeTranslater; - Assert.AreEqual(typeof(DateTime), tt.GetCSharpTypeForSQLDBType(typeCreated)); + Assert.That(tt.GetCSharpTypeForSQLDBType(typeCreated), Is.EqualTo(typeof(DateTime))); var fieldsToAlter = new List(new []{"Field1", newColumnName}); @@ -585,13 +618,16 @@ public void AddColumnTest(DatabaseType type,bool useTransaction) newCol = tbl.DiscoverColumn(fieldName); //make sure the type change happened - Assert.AreEqual(10, newCol.DataType.GetLengthIfString()); + Assert.That(newCol.DataType.GetLengthIfString(), Is.EqualTo(10)); } - //and should still be a primary key - Assert.IsTrue(tbl.DiscoverColumn("Field1").IsPrimaryKey); - //and should not be a primary key - Assert.IsFalse(tbl.DiscoverColumn(newColumnName).IsPrimaryKey); + Assert.Multiple(() => + { + //and should still be a primary key + Assert.That(tbl.DiscoverColumn("Field1").IsPrimaryKey); + //and should not be a primary key + Assert.That(tbl.DiscoverColumn(newColumnName).IsPrimaryKey, Is.False); + }); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -601,7 +637,7 @@ public void ChangeDatabaseShouldNotAffectOriginalConnectionString_Test(DatabaseT var stringBefore = database1.Server.Builder.ConnectionString; database1.Server.ExpectDatabase("SomeOtherDb"); - Assert.AreEqual(stringBefore, database1.Server.Builder.ConnectionString); + Assert.That(database1.Server.Builder.ConnectionString, Is.EqualTo(stringBefore)); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypesWithTwoBoolFlags))] @@ -630,13 +666,16 @@ public void TestDistincting(DatabaseType type,bool useTransaction, bool dodgyNam dt.Rows.Add("frank", "2001-01-01", "50"); dt.Rows.Add("frank", "2001-01-01", "51"); - Assert.AreEqual(1,tbl.Database.DiscoverTables(false).Length); - Assert.AreEqual(0,tbl.GetRowCount()); + Assert.Multiple(() => + { + Assert.That(tbl.Database.DiscoverTables(false), Has.Length.EqualTo(1)); + Assert.That(tbl.GetRowCount(), Is.EqualTo(0)); + }); using (var insert = tbl.BeginBulkInsert()) insert.Upload(dt); - Assert.AreEqual(7, tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(7)); if(useTransaction) { @@ -647,8 +686,11 @@ public void TestDistincting(DatabaseType type,bool useTransaction, bool dodgyNam else tbl.MakeDistinct(); - Assert.AreEqual(3, tbl.GetRowCount()); - Assert.AreEqual(1, tbl.Database.DiscoverTables(false).Length); + Assert.Multiple(() => + { + Assert.That(tbl.GetRowCount(), Is.EqualTo(3)); + Assert.That(tbl.Database.DiscoverTables(false), Has.Length.EqualTo(1)); + }); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -666,24 +708,33 @@ public void TestIntDataTypes(DatabaseType type) var tbl = database.CreateTable("IntTestTable", dt); dt = tbl.GetDataTable(); - Assert.AreEqual(1, dt.Rows.OfType().Count(r => Convert.ToInt32(r[0]) == 100)); - Assert.AreEqual(1, dt.Rows.OfType().Count(r => Convert.ToInt32(r[0]) == 105)); - Assert.AreEqual(1, dt.Rows.OfType().Count(r => Convert.ToInt32(r[0]) == 1)); + Assert.Multiple(() => + { + Assert.That(dt.Rows.OfType().Count(r => Convert.ToInt32(r[0]) == 100), Is.EqualTo(1)); + Assert.That(dt.Rows.OfType().Count(r => Convert.ToInt32(r[0]) == 105), Is.EqualTo(1)); + Assert.That(dt.Rows.OfType().Count(r => Convert.ToInt32(r[0]) == 1), Is.EqualTo(1)); + }); var col = tbl.DiscoverColumn("MyCol"); col.DataType.AlterTypeTo("decimal(5,2)"); var size = tbl.DiscoverColumn("MyCol").DataType.GetDecimalSize(); - Assert.AreEqual(new DecimalSize(3, 2), size); //3 before decimal place 2 after; - Assert.AreEqual(3, size.NumbersBeforeDecimalPlace); - Assert.AreEqual(2, size.NumbersAfterDecimalPlace); - Assert.AreEqual(5, size.Precision); - Assert.AreEqual(2, size.Scale); + Assert.That(size, Is.EqualTo(new DecimalSize(3, 2))); //3 before decimal place 2 after; + Assert.Multiple(() => + { + Assert.That(size.NumbersBeforeDecimalPlace, Is.EqualTo(3)); + Assert.That(size.NumbersAfterDecimalPlace, Is.EqualTo(2)); + Assert.That(size.Precision, Is.EqualTo(5)); + Assert.That(size.Scale, Is.EqualTo(2)); + }); dt = tbl.GetDataTable(); - Assert.AreEqual(1, dt.Rows.OfType().Count(r => Convert.ToDecimal(r[0]) == new decimal(100.0f))); - Assert.AreEqual(1, dt.Rows.OfType().Count(r => Convert.ToDecimal(r[0]) == new decimal(105.0f))); - Assert.AreEqual(1, dt.Rows.OfType().Count(r => Convert.ToDecimal(r[0]) == new decimal(1.0f))); + Assert.Multiple(() => + { + Assert.That(dt.Rows.OfType().Count(r => Convert.ToDecimal(r[0]) == new decimal(100.0f)), Is.EqualTo(1)); + Assert.That(dt.Rows.OfType().Count(r => Convert.ToDecimal(r[0]) == new decimal(105.0f)), Is.EqualTo(1)); + Assert.That(dt.Rows.OfType().Count(r => Convert.ToDecimal(r[0]) == new decimal(1.0f)), Is.EqualTo(1)); + }); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -701,27 +752,36 @@ public void TestFloatDataTypes(DatabaseType type) var tbl = database.CreateTable("DecimalTestTable", dt); dt =tbl.GetDataTable(); - Assert.AreEqual(1,dt.Rows.OfType().Count(r=>Convert.ToDecimal(r[0]) == new decimal(100.0f))); - Assert.AreEqual(1, dt.Rows.OfType().Count(r => Convert.ToDecimal(r[0]) == new decimal(105.0f))); - Assert.AreEqual(1, dt.Rows.OfType().Count(r => Convert.ToDecimal(r[0]) == new decimal(2.1f))); + Assert.Multiple(() => + { + Assert.That(dt.Rows.OfType().Count(r => Convert.ToDecimal(r[0]) == new decimal(100.0f)), Is.EqualTo(1)); + Assert.That(dt.Rows.OfType().Count(r => Convert.ToDecimal(r[0]) == new decimal(105.0f)), Is.EqualTo(1)); + Assert.That(dt.Rows.OfType().Count(r => Convert.ToDecimal(r[0]) == new decimal(2.1f)), Is.EqualTo(1)); + }); var col = tbl.DiscoverColumn("MyCol"); var size = col.DataType.GetDecimalSize(); - Assert.AreEqual(new DecimalSize(3, 1), size); //3 before decimal place 2 after; - Assert.AreEqual(3,size.NumbersBeforeDecimalPlace); - Assert.AreEqual(1,size.NumbersAfterDecimalPlace); - Assert.AreEqual(4, size.Precision); - Assert.AreEqual(1, size.Scale); + Assert.That(size, Is.EqualTo(new DecimalSize(3, 1))); //3 before decimal place 2 after; + Assert.Multiple(() => + { + Assert.That(size.NumbersBeforeDecimalPlace, Is.EqualTo(3)); + Assert.That(size.NumbersAfterDecimalPlace, Is.EqualTo(1)); + Assert.That(size.Precision, Is.EqualTo(4)); + Assert.That(size.Scale, Is.EqualTo(1)); + }); col.DataType.AlterTypeTo("decimal(5,2)"); size = tbl.DiscoverColumn("MyCol").DataType.GetDecimalSize(); - Assert.AreEqual(new DecimalSize(3,2),size); //3 before decimal place 2 after; - Assert.AreEqual(3, size.NumbersBeforeDecimalPlace); - Assert.AreEqual(2, size.NumbersAfterDecimalPlace); - Assert.AreEqual(5, size.Precision); - Assert.AreEqual(2, size.Scale); + Assert.That(size, Is.EqualTo(new DecimalSize(3,2))); //3 before decimal place 2 after; + Assert.Multiple(() => + { + Assert.That(size.NumbersBeforeDecimalPlace, Is.EqualTo(3)); + Assert.That(size.NumbersAfterDecimalPlace, Is.EqualTo(2)); + Assert.That(size.Precision, Is.EqualTo(5)); + Assert.That(size.Scale, Is.EqualTo(2)); + }); } [TestCase(DatabaseType.MySql, "_-o-_",":>0<:")] @@ -762,24 +822,30 @@ public void HorribleDatabaseAndTableNames(DatabaseType type,string horribleDatab dt.Rows.Add("frank", "2001-01-01", "50"); dt.Rows.Add("frank", "2001-01-01", "51"); - Assert.AreEqual(1, tbl.Database.DiscoverTables(false).Length); - Assert.AreEqual(0, tbl.GetRowCount()); + Assert.Multiple(() => + { + Assert.That(tbl.Database.DiscoverTables(false), Has.Length.EqualTo(1)); + Assert.That(tbl.GetRowCount(), Is.EqualTo(0)); + }); using (var insert = tbl.BeginBulkInsert()) insert.Upload(dt); - Assert.AreEqual(7, tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(7)); tbl.MakeDistinct(); - Assert.AreEqual(3, tbl.GetRowCount()); - Assert.AreEqual(1, tbl.Database.DiscoverTables(false).Length); + Assert.Multiple(() => + { + Assert.That(tbl.GetRowCount(), Is.EqualTo(3)); + Assert.That(tbl.Database.DiscoverTables(false), Has.Length.EqualTo(1)); + }); tbl.Truncate(); tbl.CreatePrimaryKey(tbl.DiscoverColumn("Field3")); - Assert.IsTrue(tbl.DiscoverColumn("Field3").IsPrimaryKey); + Assert.That(tbl.DiscoverColumn("Field3").IsPrimaryKey); } finally @@ -869,15 +935,18 @@ public void HorribleColumnNames(DatabaseType type, string horribleDatabaseName, var tbl = database.CreateTable(horribleTableName, dt); - Assert.AreEqual(1, tbl.GetRowCount()); + Assert.Multiple(() => + { + Assert.That(tbl.GetRowCount(), Is.EqualTo(1)); - Assert.IsTrue(tbl.DiscoverColumns().Single().IsPrimaryKey); + Assert.That(tbl.DiscoverColumns().Single().IsPrimaryKey); - Assert.AreEqual(1,tbl.GetDataTable().Rows.Count); + Assert.That(tbl.GetDataTable().Rows, Has.Count.EqualTo(1)); + }); tbl.Insert(new Dictionary { {columnName,"fff" } }); - Assert.AreEqual(2,tbl.GetDataTable().Rows.Count); + Assert.That(tbl.GetDataTable().Rows, Has.Count.EqualTo(2)); } finally { @@ -909,17 +978,20 @@ public void CreateTable_AutoIncrementColumnTest(DatabaseType type) using (var bulkInsert = tbl.BeginBulkInsert()) bulkInsert.Upload(dt); - Assert.AreEqual(1,tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(1)); var result = tbl.GetDataTable(); - Assert.AreEqual(1,result.Rows.Count); - Assert.AreEqual(1,result.Rows[0]["IdColumn"]); + Assert.That(result.Rows, Has.Count.EqualTo(1)); + Assert.Multiple(() => + { + Assert.That(result.Rows[0]["IdColumn"], Is.EqualTo(1)); - Assert.IsTrue(tbl.DiscoverColumn("IdColumn").IsAutoIncrement); - Assert.IsFalse(tbl.DiscoverColumn("Name").IsAutoIncrement); + Assert.That(tbl.DiscoverColumn("IdColumn").IsAutoIncrement); + Assert.That(tbl.DiscoverColumn("Name").IsAutoIncrement, Is.False); + }); var autoIncrement = tbl.Insert(new Dictionary {{"Name", "Tony"}}); - Assert.AreEqual(2,autoIncrement); + Assert.That(autoIncrement, Is.EqualTo(2)); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -952,10 +1024,13 @@ public void CreateTable_DefaultTest_Date(DatabaseType type) var databaseValue = (DateTime)dt2.Rows.Cast().Single()["myDt"]; - Assert.AreEqual(currentValue.Year,databaseValue.Year); - Assert.AreEqual(currentValue.Month, databaseValue.Month); - Assert.AreEqual(currentValue.Day, databaseValue.Day); - Assert.AreEqual(currentValue.Hour, databaseValue.Hour); + Assert.Multiple(() => + { + Assert.That(databaseValue.Year, Is.EqualTo(currentValue.Year)); + Assert.That(databaseValue.Month, Is.EqualTo(currentValue.Month)); + Assert.That(databaseValue.Day, Is.EqualTo(currentValue.Day)); + Assert.That(databaseValue.Hour, Is.EqualTo(currentValue.Hour)); + }); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -1003,7 +1078,7 @@ public void CreateTable_DefaultTest_Guid(DatabaseType type) var databaseValue = (string)dt2.Rows.Cast().Single()["MyGuid"]; - Assert.IsNotNull(databaseValue); + Assert.That(databaseValue, Is.Not.Null); TestContext.WriteLine(databaseValue); } @@ -1042,14 +1117,14 @@ public void Test_BulkInserting_LotsOfDates(DatabaseType type) foreach(var s in someDates) dt.Rows.Add(2,s,Guid.NewGuid().ToString()); - Assert.AreEqual(someDates.Length,tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(someDates.Length)); using(var bulkInsert = tbl.BeginBulkInsert(culture)) { bulkInsert.Upload(dt); } - Assert.AreEqual(someDates.Length*2,tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(someDates.Length*2)); } private readonly string [] someDates = { @@ -1306,6 +1381,6 @@ public void DateTimeTypeDeciderPerformance() foreach(var f in DateTimeTypeDecider.DateFormatsDM) d.Parse(dt.ToString(f)); foreach(var f in DateTimeTypeDecider.TimeFormats) d.Parse(dt.ToString(f)); - Assert.AreEqual(new DateTime(1993,2,28,5,36,27),d.Parse("28/2/1993 5:36:27 AM")); + Assert.That(d.Parse("28/2/1993 5:36:27 AM"), Is.EqualTo(new DateTime(1993,2,28,5,36,27))); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/Database/DatabaseLevelTests.cs b/Tests/FAnsiTests/Database/DatabaseLevelTests.cs index b31cebfc..b1f4a2f1 100644 --- a/Tests/FAnsiTests/Database/DatabaseLevelTests.cs +++ b/Tests/FAnsiTests/Database/DatabaseLevelTests.cs @@ -12,7 +12,7 @@ internal class DatabaseLevelTests : DatabaseTests public void Database_Exists(DatabaseType type) { var server = GetTestDatabase(type); - Assert.IsTrue(server.Exists(), "Server " + server + " did not exist"); + Assert.That(server.Exists(), "Server " + server + " did not exist"); } @@ -25,7 +25,7 @@ public void Test_ExpectDatabase(DatabaseType type, bool upperCase) var helper = ImplementationManager.GetImplementation(type).GetServerHelper(); var server = new DiscoveredServer(helper.GetConnectionStringBuilder("loco","db","frank","kangaro")); var db = server.ExpectDatabase("omg"); - Assert.AreEqual(upperCase?"OMG":"omg",db.GetRuntimeName()); + Assert.That(db.GetRuntimeName(), Is.EqualTo(upperCase ?"OMG":"omg")); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -43,10 +43,10 @@ public void Test_CreateSchema(DatabaseType type) var tbl = db.CreateTable("Heyyy", new[] {new DatabaseColumnRequest("fff", new DatabaseTypeRequest(typeof(string), 10))},"Fr ank"); - Assert.IsTrue(tbl.Exists()); + Assert.That(tbl.Exists()); if(type == DatabaseType.MicrosoftSQLServer) - Assert.AreEqual("Fr ank",tbl.Schema); + Assert.That(tbl.Schema, Is.EqualTo("Fr ank")); } } } \ No newline at end of file diff --git a/Tests/FAnsiTests/Database/DiscoverTablesTests.cs b/Tests/FAnsiTests/Database/DiscoverTablesTests.cs index 8daaba8d..bcb9d35c 100644 --- a/Tests/FAnsiTests/Database/DiscoverTablesTests.cs +++ b/Tests/FAnsiTests/Database/DiscoverTablesTests.cs @@ -29,9 +29,12 @@ public void Test_DiscoverTables_Normal(DatabaseType dbType) var tbls = db.DiscoverTables(false); - Assert.AreEqual(2,tbls.Length); - Assert.AreEqual(1, tbls.Count(t => t.GetRuntimeName().Equals("AA",StringComparison.CurrentCultureIgnoreCase))); - Assert.AreEqual(1,tbls.Count(t=>t.GetRuntimeName().Equals("BB",StringComparison.CurrentCultureIgnoreCase))); + Assert.That(tbls, Has.Length.EqualTo(2)); + Assert.Multiple(() => + { + Assert.That(tbls.Count(t => t.GetRuntimeName().Equals("AA", StringComparison.CurrentCultureIgnoreCase)), Is.EqualTo(1)); + Assert.That(tbls.Count(t => t.GetRuntimeName().Equals("BB", StringComparison.CurrentCultureIgnoreCase)), Is.EqualTo(1)); + }); } /// @@ -44,10 +47,10 @@ public void Test_DiscoverTables_Normal(DatabaseType dbType) public void Test_DiscoverTables_WithInvalidNames_Skipped(DatabaseType dbType) { var db = GetTestDatabase(dbType); - + //FAnsi doesn't let you create tables with brackets in the names so we have to do it manually CreateBadTable(db); - + //FAnsi shouldn't let us create a table with an invalid name Assert.Throws(() => db.CreateTable("FF (troll)", @@ -62,13 +65,13 @@ public void Test_DiscoverTables_WithInvalidNames_Skipped(DatabaseType dbType) { new("F",new DatabaseTypeRequest(typeof(int))) }); - + //even though there are 2 tables in the database [BB (ff)] and [FF] only [FF] should be returned var tbls = db.DiscoverTables(false); - Assert.AreEqual(1,tbls.Length); - Assert.AreEqual(1, tbls.Count(t => t.GetRuntimeName().Equals("FF",StringComparison.CurrentCultureIgnoreCase))); - + Assert.That(tbls, Has.Length.EqualTo(1)); + Assert.That(tbls.Count(t => t.GetRuntimeName().Equals("FF",StringComparison.CurrentCultureIgnoreCase)), Is.EqualTo(1)); + DropBadTable(db,false); } @@ -80,10 +83,10 @@ public void Test_DiscoverTables_WithInvalidNames_Skipped(DatabaseType dbType) public void Test_DiscoverViews_WithInvalidNames_Skipped(DatabaseType dbType) { var db = GetTestDatabase(dbType); - + //FAnsi doesn't let you create tables with brackets in the names so we have to do it manually CreateBadView(db); - + //FAnsi shouldn't let us create a table with an invalid name Assert.Throws(() => db.CreateTable("FF (troll)", @@ -98,17 +101,20 @@ public void Test_DiscoverViews_WithInvalidNames_Skipped(DatabaseType dbType) { new("F",new DatabaseTypeRequest(typeof(int))) }); - + //even though there are 2 tables in the database [BB (ff)] and [FF] only [FF] should be returned var tbls = db.DiscoverTables(true); //should be 2 tables (and 1 bad view that doesn't get returned) - Assert.AreEqual(2,tbls.Length); - - //view should not be returned because it is bad - Assert.AreEqual(0,tbls.Count(t=>t.TableType == TableType.View)); - Assert.AreEqual(1, tbls.Count(t => t.GetRuntimeName().Equals("FF",StringComparison.CurrentCultureIgnoreCase))); - + Assert.That(tbls, Has.Length.EqualTo(2)); + + Assert.Multiple(() => + { + //view should not be returned because it is bad + Assert.That(tbls.Count(t => t.TableType == TableType.View), Is.EqualTo(0)); + Assert.That(tbls.Count(t => t.GetRuntimeName().Equals("FF", StringComparison.CurrentCultureIgnoreCase)), Is.EqualTo(1)); + }); + DropBadView(db,false); } @@ -130,14 +136,14 @@ private void DropBadTable(DiscoveredDatabase db,bool ignoreFailure) } } - private string GetBadTableName(DiscoveredDatabase db) => + private static string GetBadTableName(DiscoveredDatabase db) => db.Server.DatabaseType switch { DatabaseType.MicrosoftSQLServer => "[BB (ff)]", DatabaseType.MySql => "`BB (ff)`", DatabaseType.Oracle => $"{db.GetRuntimeName()}.\"BB (ff)\"", DatabaseType.PostgreSql => $"\"{db.GetRuntimeName()}\".public.\"BB (ff)\"", - _ => throw new ArgumentOutOfRangeException(nameof(db.Server.DatabaseType), db.Server.DatabaseType, null) + _ => throw new ArgumentOutOfRangeException(nameof(db), db.Server.DatabaseType, $"Unknown database type {db.Server.DatabaseType}") }; private void CreateBadTable(DiscoveredDatabase db) diff --git a/Tests/FAnsiTests/DatabaseTests.cs b/Tests/FAnsiTests/DatabaseTests.cs index 6c3b6754..13aefb5b 100644 --- a/Tests/FAnsiTests/DatabaseTests.cs +++ b/Tests/FAnsiTests/DatabaseTests.cs @@ -20,7 +20,7 @@ namespace FAnsiTests; [NonParallelizable] public class DatabaseTests { - protected readonly Dictionary TestConnectionStrings = new(); + protected readonly Dictionary TestConnectionStrings = []; private bool _allowDatabaseCreation; private string _testScratchDatabase; @@ -39,7 +39,7 @@ public void CheckFiles() var file = Path.Combine(TestContext.CurrentContext.TestDirectory, TestFilename); - Assert.IsTrue(File.Exists(file),"Could not find " + TestFilename); + Assert.That(File.Exists(file),"Could not find " + TestFilename); var doc = XDocument.Load(file); @@ -158,13 +158,16 @@ private static bool AreBasicallyEquals(object o, object o2, bool handleSlashRSla protected static void AssertAreEqual(DataTable dt1, DataTable dt2) { - Assert.AreEqual(dt1.Columns.Count, dt2.Columns.Count, "DataTables had a column count mismatch"); - Assert.AreEqual(dt1.Rows.Count, dt2.Rows.Count, "DataTables had a row count mismatch"); + Assert.Multiple(() => + { + Assert.That(dt2.Columns, Has.Count.EqualTo(dt1.Columns.Count), "DataTables had a column count mismatch"); + Assert.That(dt2.Rows, Has.Count.EqualTo(dt1.Rows.Count), "DataTables had a row count mismatch"); + }); foreach (DataRow row1 in dt1.Rows) { var match = dt2.Rows.Cast().Any(row2=> dt1.Columns.Cast().All(c => AreBasicallyEquals(row1[c.ColumnName], row2[c.ColumnName]))); - Assert.IsTrue(match, "Couldn't find match for row:{0}", string.Join(",", row1.ItemArray)); + Assert.That(match, "Couldn't find match for row:{0}", string.Join(",", row1.ItemArray)); } } diff --git a/Tests/FAnsiTests/Equality/EqualityTests_ServerAndDatabase.cs b/Tests/FAnsiTests/Equality/EqualityTests_ServerAndDatabase.cs index 989345af..4f7090fb 100644 --- a/Tests/FAnsiTests/Equality/EqualityTests_ServerAndDatabase.cs +++ b/Tests/FAnsiTests/Equality/EqualityTests_ServerAndDatabase.cs @@ -19,22 +19,25 @@ public void EqualityTest_DiscoveredServer_AreEqual(string constr1, DatabaseType var s1 = new DiscoveredServer(constr1, type1); var s2 = new DiscoveredServer(constr2, type2); - Assert.AreEqual(s1,s2); - Assert.AreEqual(s1.GetHashCode(),s2.GetHashCode()); + Assert.Multiple(() => + { + Assert.That(s2, Is.EqualTo(s1)); + Assert.That(s2.GetHashCode(), Is.EqualTo(s1.GetHashCode())); - Assert.AreEqual(s1.ExpectDatabase("MyDb"), s2.ExpectDatabase("MyDb")); - Assert.AreEqual(s1.ExpectDatabase("MyDb").GetHashCode(), s2.ExpectDatabase("MyDb").GetHashCode()); + Assert.That(s2.ExpectDatabase("MyDb"), Is.EqualTo(s1.ExpectDatabase("MyDb"))); + Assert.That(s2.ExpectDatabase("MyDb").GetHashCode(), Is.EqualTo(s1.ExpectDatabase("MyDb").GetHashCode())); - Assert.AreEqual(s1.ExpectDatabase("Mydb"), s2.ExpectDatabase("MyDb")); - Assert.AreEqual(s1.ExpectDatabase("Mydb").GetHashCode(), s2.ExpectDatabase("MyDb").GetHashCode()); + Assert.That(s2.ExpectDatabase("MyDb"), Is.EqualTo(s1.ExpectDatabase("Mydb"))); + Assert.That(s2.ExpectDatabase("MyDb").GetHashCode(), Is.EqualTo(s1.ExpectDatabase("Mydb").GetHashCode())); - Assert.AreNotEqual(s1.ExpectDatabase("MyDb"), s2.ExpectDatabase("MyDb2")); + Assert.That(s2.ExpectDatabase("MyDb2"), Is.Not.EqualTo(s1.ExpectDatabase("MyDb"))); + }); //This does not affect things since we are expecting a specific database anyway s1.ChangeDatabase("Dave"); - Assert.AreNotEqual(s1,s2); - Assert.AreEqual(s1.ExpectDatabase("MyDb"), s2.ExpectDatabase("MyDb")); - Assert.AreEqual(s1.ExpectDatabase("MyDb").GetHashCode(), s2.ExpectDatabase("MyDb").GetHashCode()); + Assert.That(s2, Is.Not.EqualTo(s1)); + Assert.That(s2.ExpectDatabase("MyDb"), Is.EqualTo(s1.ExpectDatabase("MyDb"))); + Assert.That(s2.ExpectDatabase("MyDb").GetHashCode(), Is.EqualTo(s1.ExpectDatabase("MyDb").GetHashCode())); } @@ -46,7 +49,7 @@ public void EqualityTest_DiscoveredServer_AreNotEqual(string constr1, DatabaseTy var s1 = new DiscoveredServer(constr1, type1); var s2 = new DiscoveredServer(constr2, type2); - Assert.AreNotEqual(s1,s2); - Assert.AreNotEqual(s1.ExpectDatabase("MyDb"), s2.ExpectDatabase("MyDb")); + Assert.That(s2, Is.Not.EqualTo(s1)); + Assert.That(s2.ExpectDatabase("MyDb"), Is.Not.EqualTo(s1.ExpectDatabase("MyDb"))); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/Equality/EqualityTests_TableAndColumn.cs b/Tests/FAnsiTests/Equality/EqualityTests_TableAndColumn.cs index 60c8b8e0..39d09d41 100644 --- a/Tests/FAnsiTests/Equality/EqualityTests_TableAndColumn.cs +++ b/Tests/FAnsiTests/Equality/EqualityTests_TableAndColumn.cs @@ -28,14 +28,17 @@ public void EqualityTest_DiscoveredTable_AreEqual(string table1, string schema1, var db = s.ExpectDatabase("MyDb"); var db2 = s.ExpectDatabase("MyDb"); - Assert.IsFalse(ReferenceEquals(db,db2)); - Assert.IsTrue(db.Equals(db2)); + Assert.Multiple(() => + { + Assert.That(ReferenceEquals(db, db2), Is.False); + Assert.That(db, Is.EqualTo(db2)); + }); var t1 = db.ExpectTable(table1,schema1); var t2 = db2.ExpectTable(table2,schema2); - Assert.AreEqual(t1,t2); - Assert.AreEqual(t1.GetHashCode(), t2.GetHashCode()); + Assert.That(t2, Is.EqualTo(t1)); + Assert.That(t2.GetHashCode(), Is.EqualTo(t1.GetHashCode())); } @@ -54,6 +57,6 @@ public void EqualityTest_DiscoveredTable_AreNotEqual(DatabaseType type1, string var t1 = db1.ExpectTable(tablename1, schema1); var t2 = db2.ExpectTable(tablename2, schema2); - Assert.AreNotEqual(t1, t2); + Assert.That(t2, Is.Not.EqualTo(t1)); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/Examples.cs b/Tests/FAnsiTests/Examples.cs index 17127d10..b3c9a7ac 100644 --- a/Tests/FAnsiTests/Examples.cs +++ b/Tests/FAnsiTests/Examples.cs @@ -34,14 +34,17 @@ public void Simple_Example() //Create the table database.CreateTable("MyTable",dt); - //Database types are compatible with all the data - Assert.AreEqual("datetime2",table.DiscoverColumn("Date of Birth").DataType.SQLType); - Assert.AreEqual("varchar(25)",table.DiscoverColumn("Name").DataType.SQLType); - - //And the (string) data is now properly typed and sat in our DBMS - Assert.AreEqual(2,table.GetRowCount()); - Assert.AreEqual(new DateTime(1920,1,1),table.GetDataTable().Rows[0][1]); - Assert.AreEqual(new DateTime(1910,5,22),table.GetDataTable().Rows[1][1]); + Assert.Multiple(() => + { + //Database types are compatible with all the data + Assert.That(table.DiscoverColumn("Date of Birth").DataType.SQLType, Is.EqualTo("datetime2")); + Assert.That(table.DiscoverColumn("Name").DataType.SQLType, Is.EqualTo("varchar(25)")); + + //And the (string) data is now properly typed and sat in our DBMS + Assert.That(table.GetRowCount(), Is.EqualTo(2)); + Assert.That(table.GetDataTable().Rows[0][1], Is.EqualTo(new DateTime(1920, 1, 1))); + Assert.That(table.GetDataTable().Rows[1][1], Is.EqualTo(new DateTime(1910, 5, 22))); + }); } [Test] diff --git a/Tests/FAnsiTests/ExtensionsTests.cs b/Tests/FAnsiTests/ExtensionsTests.cs index 050fda64..527d4772 100644 --- a/Tests/FAnsiTests/ExtensionsTests.cs +++ b/Tests/FAnsiTests/ExtensionsTests.cs @@ -15,14 +15,14 @@ public void Test_SetDoNotReType_RepeatCalls() dt.Columns.Add("FFF"); - Assert.IsFalse(dt.Columns["FFF"].GetDoNotReType()); + Assert.That(dt.Columns["FFF"].GetDoNotReType(), Is.False); Assert.DoesNotThrow(()=>dt.SetDoNotReType(true)); - Assert.IsTrue(dt.Columns["FFF"].GetDoNotReType()); + Assert.That(dt.Columns["FFF"].GetDoNotReType()); Assert.DoesNotThrow(()=>dt.SetDoNotReType(false)); - Assert.IsFalse(dt.Columns["FFF"].GetDoNotReType()); + Assert.That(dt.Columns["FFF"].GetDoNotReType(), Is.False); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/FAnsiTests.csproj b/Tests/FAnsiTests/FAnsiTests.csproj index 374a4691..7d154800 100644 --- a/Tests/FAnsiTests/FAnsiTests.csproj +++ b/Tests/FAnsiTests/FAnsiTests.csproj @@ -11,7 +11,11 @@ - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Tests/FAnsiTests/ImplementationManagerLoadTests.cs b/Tests/FAnsiTests/ImplementationManagerLoadTests.cs index 12aec635..144a1bde 100644 --- a/Tests/FAnsiTests/ImplementationManagerLoadTests.cs +++ b/Tests/FAnsiTests/ImplementationManagerLoadTests.cs @@ -8,6 +8,6 @@ internal class ImplementationManagerLoadTests [Test] public void Test_LoadAssemblies_FromDirectory() { - Assert.GreaterOrEqual(ImplementationManager.GetImplementations().Count,3); + Assert.That(ImplementationManager.GetImplementations(), Has.Count.GreaterThanOrEqualTo(3)); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/ManagedConnectionTests.cs b/Tests/FAnsiTests/ManagedConnectionTests.cs index c4a3c0c9..57722ee7 100644 --- a/Tests/FAnsiTests/ManagedConnectionTests.cs +++ b/Tests/FAnsiTests/ManagedConnectionTests.cs @@ -15,7 +15,7 @@ public void Test_GetConnection_NotOpenAtStart(DatabaseType dbType) var con = db.Server.GetConnection(); //GetConnection should return an unopened connection - Assert.AreEqual(ConnectionState.Closed,con.State); + Assert.That(con.State, Is.EqualTo(ConnectionState.Closed)); } /// @@ -32,11 +32,11 @@ public void Test_GetManagedConnection_AutoOpenClose(DatabaseType dbType) using (con = db.Server.GetManagedConnection()) { //GetManagedConnection should open itself - Assert.AreEqual(ConnectionState.Open,con.Connection.State); + Assert.That(con.Connection.State, Is.EqualTo(ConnectionState.Open)); } //finally should close it - Assert.AreEqual(ConnectionState.Closed,con.Connection.State); + Assert.That(con.Connection.State, Is.EqualTo(ConnectionState.Closed)); } @@ -54,11 +54,11 @@ public void Test_BeginNewTransactedConnection_AutoOpenClose(DatabaseType dbType) using (con = db.Server.BeginNewTransactedConnection()) { //GetManagedConnection should open itself - Assert.AreEqual(ConnectionState.Open,con.Connection.State); + Assert.That(con.Connection.State, Is.EqualTo(ConnectionState.Open)); } //finally should close it - Assert.AreEqual(ConnectionState.Closed,con.Connection.State); + Assert.That(con.Connection.State, Is.EqualTo(ConnectionState.Closed)); } /// @@ -81,25 +81,31 @@ public void Test_GetManagedConnection_OngoingTransaction(DatabaseType dbType) { var ongoingTrans = ongoingCon.ManagedTransaction; - //BeginNewTransactedConnection should open itself - Assert.AreEqual(ConnectionState.Open,ongoingCon.Connection.State); - Assert.IsNotNull(ongoingTrans); + Assert.Multiple(() => + { + //BeginNewTransactedConnection should open itself + Assert.That(ongoingCon.Connection.State, Is.EqualTo(ConnectionState.Open)); + Assert.That(ongoingTrans, Is.Not.Null); + }); //a managed connection with an ongoing transaction IManagedConnection con; using (con = db.Server.GetManagedConnection(ongoingTrans)) { - //still open - Assert.AreEqual(ConnectionState.Open,con.Connection.State); - Assert.IsTrue(con.Connection == ongoingCon.Connection); //same underlying connection + Assert.Multiple(() => + { + //still open + Assert.That(con.Connection.State, Is.EqualTo(ConnectionState.Open)); + Assert.That(con.Connection, Is.EqualTo(ongoingCon.Connection)); //same underlying connection + }); } //it should still be open after this finally block - Assert.AreEqual(ConnectionState.Open,con.Connection.State); + Assert.That(con.Connection.State, Is.EqualTo(ConnectionState.Open)); } //this is the using on the transaction this one should now close itself - Assert.AreEqual(ConnectionState.Closed,ongoingCon.Connection.State); + Assert.That(ongoingCon.Connection.State, Is.EqualTo(ConnectionState.Closed)); } @@ -120,21 +126,27 @@ public void Test_GetManagedConnection_OngoingTransaction_WithCommitRollback(Data { var ongoingTrans = ongoingCon.ManagedTransaction; - //BeginNewTransactedConnection should open itself - Assert.AreEqual(ConnectionState.Open,ongoingCon.Connection.State); - Assert.IsNotNull(ongoingTrans); + Assert.Multiple(() => + { + //BeginNewTransactedConnection should open itself + Assert.That(ongoingCon.Connection.State, Is.EqualTo(ConnectionState.Open)); + Assert.That(ongoingTrans, Is.Not.Null); + }); //a managed connection with an ongoing transaction IManagedConnection con; using (con = db.Server.GetManagedConnection(ongoingTrans)) { - //still open - Assert.AreEqual(ConnectionState.Open,con.Connection.State); - Assert.IsTrue(con.Connection == ongoingCon.Connection); //same underlying connection + Assert.Multiple(() => + { + //still open + Assert.That(con.Connection.State, Is.EqualTo(ConnectionState.Open)); + Assert.That(con.Connection, Is.EqualTo(ongoingCon.Connection)); //same underlying connection + }); } //it should still be open after this finally block - Assert.AreEqual(ConnectionState.Open,con.Connection.State); + Assert.That(con.Connection.State, Is.EqualTo(ConnectionState.Open)); if(commit) ongoingCon.ManagedTransaction.CommitAndCloseConnection(); @@ -142,11 +154,11 @@ public void Test_GetManagedConnection_OngoingTransaction_WithCommitRollback(Data ongoingCon.ManagedTransaction.AbandonAndCloseConnection(); //that should really have closed it! - Assert.AreEqual(ConnectionState.Closed,ongoingCon.Connection.State); + Assert.That(ongoingCon.Connection.State, Is.EqualTo(ConnectionState.Closed)); } //this is the using on the transaction this one should now close itself - Assert.AreEqual(ConnectionState.Closed,ongoingCon.Connection.State); + Assert.That(ongoingCon.Connection.State, Is.EqualTo(ConnectionState.Closed)); } @@ -180,23 +192,26 @@ public void Test_Clone_AutoOpenClose(DatabaseType dbType) using (con = db.Server.BeginNewTransactedConnection()) { //GetManagedConnection should open itself - Assert.AreEqual(ConnectionState.Open,con.Connection.State); + Assert.That(con.Connection.State, Is.EqualTo(ConnectionState.Open)); using (var clone = con.Clone()) { clone.CloseOnDispose = false; - //GetManagedConnection should open itself - Assert.AreEqual(ConnectionState.Open,clone.Connection.State); + Assert.Multiple(() => + { + //GetManagedConnection should open itself + Assert.That(clone.Connection.State, Is.EqualTo(ConnectionState.Open)); - Assert.IsTrue(clone.Connection == con.Connection); + Assert.That(clone.Connection, Is.EqualTo(con.Connection)); + }); } //GetManagedConnection should not have closed because we told the clone not to - Assert.AreEqual(ConnectionState.Open,con.Connection.State); + Assert.That(con.Connection.State, Is.EqualTo(ConnectionState.Open)); } //now disposing the non clone //finally should close it - Assert.AreEqual(ConnectionState.Closed,con.Connection.State); + Assert.That(con.Connection.State, Is.EqualTo(ConnectionState.Closed)); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/PackageListIsCorrectTests.cs b/Tests/FAnsiTests/PackageListIsCorrectTests.cs index dafe6508..91e6a57f 100644 --- a/Tests/FAnsiTests/PackageListIsCorrectTests.cs +++ b/Tests/FAnsiTests/PackageListIsCorrectTests.cs @@ -12,16 +12,16 @@ namespace DicomTypeTranslation.Tests; /// Tests to confirm that the dependencies in csproj files (NuGet packages) match those in the .nuspec files and that packages.md /// lists the correct versions (in documentation) /// -public class PackageListIsCorrectTests +public partial class PackageListIsCorrectTests { private static readonly EnumerationOptions EnumerationOptions = new() { RecurseSubdirectories = true,MatchCasing = MatchCasing.CaseInsensitive,IgnoreInaccessible = true}; // - private static readonly Regex RPackageRef = new(@" @@ -51,9 +51,12 @@ public void TestPackagesDocumentCorrect(string rootPath=null) undocumented.AppendJoin(Environment.NewLine, undocumentedPackages); var unusedPackages = packagesMarkdown.Except(usedPackages).ToArray(); - Assert.IsEmpty(unusedPackages, - $"The following packages are listed in PACKAGES.md but are not used in any csproj file: {string.Join(", ", unusedPackages)}"); - Assert.IsEmpty(undocumented.ToString()); + Assert.Multiple(() => + { + Assert.That(unusedPackages, Is.Empty, + $"The following packages are listed in PACKAGES.md but are not used in any csproj file: {string.Join(", ", unusedPackages)}"); + Assert.That(undocumented.ToString(), Is.Empty); + }); } /// @@ -79,7 +82,7 @@ private static DirectoryInfo FindRoot(string path = null) var root = new DirectoryInfo(TestContext.CurrentContext.TestDirectory); while (!root.EnumerateFiles("*.sln", SearchOption.TopDirectoryOnly).Any() && root.Parent != null) root = root.Parent; - Assert.IsNotNull(root.Parent, "Could not find root of repository"); + Assert.That(root.Parent, Is.Not.Null, "Could not find root of repository"); return root; } @@ -101,8 +104,12 @@ private static IEnumerable GetCsprojFiles(DirectoryInfo root) private static string GetPackagesMarkdown(DirectoryInfo root) { var path = root.EnumerateFiles("packages.md", EnumerationOptions).Select(f => f.FullName).SingleOrDefault(); - Assert.IsNotNull(path, "Could not find packages.md"); + Assert.That(path, Is.Not.Null, "Could not find packages.md"); return path; } + [GeneratedRegex("(() =>syntax.GetParameterDeclaration("@bob", new DatabaseTypeRequest(typeof(string), 10))); } @@ -62,7 +63,7 @@ public void CreateParameter_AndUse(DatabaseType type) con.Open(); var r = db.Server.GetCommand(sb.ToString(),con).ExecuteReader(); - Assert.IsTrue(r.Read()); - Assert.IsFalse(r.Read()); + Assert.That(r.Read()); + Assert.That(r.Read(), Is.False); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/Query/ParameterNameExtractionTests.cs b/Tests/FAnsiTests/Query/ParameterNameExtractionTests.cs index 24e6bde6..4b141260 100644 --- a/Tests/FAnsiTests/Query/ParameterNameExtractionTests.cs +++ b/Tests/FAnsiTests/Query/ParameterNameExtractionTests.cs @@ -20,15 +20,15 @@ public class ParameterNameExtractionTests [TestCase("@bobby='active'")] public void TestExtractionOfParmaetersFromSQL_FindOne(string sql) { - Assert.AreEqual("@bobby",QuerySyntaxHelper.GetAllParameterNamesFromQuery(sql).SingleOrDefault()); + Assert.That(QuerySyntaxHelper.GetAllParameterNamesFromQuery(sql).SingleOrDefault(), Is.EqualTo("@bobby")); } [TestCase("[bob]='@bobby'")] [TestCase("[bob]='myfriend@bobby.ac.uk'")] [TestCase("[bob]='myfriend123@bobby.ac.uk'")] [TestCase("[bob]= ':bobby'")] - public void TestExtractionOfParmaetersFromSQL_NoneOne(string sql) + public void TestExtractionOfParametersFromSQL_NoneOne(string sql) { - Assert.AreEqual(0, QuerySyntaxHelper.GetAllParameterNamesFromQuery(sql).Count); + Assert.That(QuerySyntaxHelper.GetAllParameterNamesFromQuery(sql), Is.Empty); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/Query/QuerySyntaxHelperDatabaseTests.cs b/Tests/FAnsiTests/Query/QuerySyntaxHelperDatabaseTests.cs index 7e1cb73a..2f20f13a 100644 --- a/Tests/FAnsiTests/Query/QuerySyntaxHelperDatabaseTests.cs +++ b/Tests/FAnsiTests/Query/QuerySyntaxHelperDatabaseTests.cs @@ -2,6 +2,7 @@ using FAnsi; using FAnsi.Discovery.QuerySyntax; using NUnit.Framework; +using NUnit.Framework.Legacy; namespace FAnsiTests.Query; @@ -47,6 +48,6 @@ public void Test_LenFunc(DatabaseType dbType) var sql = $"SELECT MAX({len}(f)) from {tbl.GetFullyQualifiedName()}"; var cmd = tbl.Database.Server.GetCommand(sql, con); - Assert.AreEqual(10, cmd.ExecuteScalar()); + Assert.That(cmd.ExecuteScalar(), Is.EqualTo(10)); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/Query/QuerySyntaxHelperTests.cs b/Tests/FAnsiTests/Query/QuerySyntaxHelperTests.cs index 24f73a49..4a8d64ac 100644 --- a/Tests/FAnsiTests/Query/QuerySyntaxHelperTests.cs +++ b/Tests/FAnsiTests/Query/QuerySyntaxHelperTests.cs @@ -5,6 +5,7 @@ using FAnsi.Discovery.QuerySyntax; using FAnsi.Implementation; using NUnit.Framework; +using NUnit.Framework.Legacy; namespace FAnsiTests.Query; @@ -44,7 +45,7 @@ internal class QuerySyntaxHelperTests public void SyntaxHelperTest_GetRuntimeName(DatabaseType dbType, string expected, string forInput) { var syntaxHelper = ImplementationManager.GetImplementation(dbType).GetQuerySyntaxHelper(); - Assert.AreEqual(expected,syntaxHelper.GetRuntimeName(forInput)); + Assert.That(syntaxHelper.GetRuntimeName(forInput), Is.EqualTo(expected)); } /// @@ -72,14 +73,14 @@ public void SyntaxHelperTest_GetRuntimeName_MultipleCalls(DatabaseType dbType, { if(i%2 ==0 ) { - Assert.AreEqual(runtime,currentName); + Assert.That(currentName, Is.EqualTo(runtime)); currentName = syntaxHelper.EnsureWrapped(currentName); currentName = syntaxHelper.EnsureWrapped(currentName); currentName = syntaxHelper.EnsureWrapped(currentName); } else { - Assert.AreEqual(wrapped,currentName); + Assert.That(currentName, Is.EqualTo(wrapped)); currentName = syntaxHelper.GetRuntimeName(currentName); currentName = syntaxHelper.GetRuntimeName(currentName); currentName = syntaxHelper.GetRuntimeName(currentName); @@ -95,7 +96,7 @@ public void EnsureWrapped_MultipleCalls(DatabaseType dbType) var once = syntax.EnsureWrapped("ff"); var twice = syntax.EnsureWrapped(once); - Assert.AreEqual(once,twice); + Assert.That(twice, Is.EqualTo(once)); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -107,19 +108,25 @@ public void SyntaxHelperTest_GetRuntimeName_Impossible(DatabaseType t) Assert.Throws(()=>syntaxHelper.GetRuntimeName("dbo.GetMyCoolThing(\"Magic Fun Times\")")); - Assert.IsFalse(syntaxHelper.TryGetRuntimeName("count(*)",out _)); - Assert.IsFalse(syntaxHelper.TryGetRuntimeName("dbo.GetMyCoolThing(\"Magic Fun Times\")",out _)); + Assert.Multiple(() => + { + Assert.That(syntaxHelper.TryGetRuntimeName("count(*)", out _), Is.False); + Assert.That(syntaxHelper.TryGetRuntimeName("dbo.GetMyCoolThing(\"Magic Fun Times\")", out _), Is.False); + }); } [Test] public void SyntaxHelperTest_GetRuntimeName_Oracle() { var syntaxHelper = ImplementationManager.GetImplementation(DatabaseType.Oracle).GetQuerySyntaxHelper(); - Assert.AreEqual("FRANK",syntaxHelper.GetRuntimeName("count(*) as Frank")); - Assert.AreEqual("FRANK",syntaxHelper.GetRuntimeName("count(cast(1 as int)) as Frank")); - Assert.AreEqual("FRANK",syntaxHelper.GetRuntimeName("count(cast(1 as int)) as \"Frank\"")); - Assert.AreEqual("FRANK",syntaxHelper.GetRuntimeName("\"mydb\".\"mytbl\".\"mycol\" as Frank")); - Assert.AreEqual("MYCOL",syntaxHelper.GetRuntimeName("\"mydb\".\"mytbl\".\"mycol\"")); + Assert.Multiple(() => + { + Assert.That(syntaxHelper.GetRuntimeName("count(*) as Frank"), Is.EqualTo("FRANK")); + Assert.That(syntaxHelper.GetRuntimeName("count(cast(1 as int)) as Frank"), Is.EqualTo("FRANK")); + Assert.That(syntaxHelper.GetRuntimeName("count(cast(1 as int)) as \"Frank\""), Is.EqualTo("FRANK")); + Assert.That(syntaxHelper.GetRuntimeName("\"mydb\".\"mytbl\".\"mycol\" as Frank"), Is.EqualTo("FRANK")); + Assert.That(syntaxHelper.GetRuntimeName("\"mydb\".\"mytbl\".\"mycol\""), Is.EqualTo("MYCOL")); + }); } @@ -142,10 +149,13 @@ public void SyntaxHelperTest_SplitLineIntoSelectSQLAndAlias(string line, string { var syntaxHelper = ImplementationManager.GetImplementation(t).GetQuerySyntaxHelper(); - Assert.AreEqual(expectedAlias != null,syntaxHelper.SplitLineIntoSelectSQLAndAlias(line, out var selectSQL, out var alias)); - Assert.AreEqual(expectedSelectSql,selectSQL); - Assert.AreEqual(expectedAlias,alias); - } + Assert.Multiple(() => + { + Assert.That(syntaxHelper.SplitLineIntoSelectSQLAndAlias(line, out var selectSQL, out var alias), Is.EqualTo(expectedAlias != null)); + Assert.That(selectSQL, Is.EqualTo(expectedSelectSql)); + Assert.That(alias, Is.EqualTo(expectedAlias)); + }); + } } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -160,9 +170,12 @@ public void Test_GetAlias(DatabaseType t) var testString = $"col {syntaxHelper.AliasPrefix} bob"; syntaxHelper.SplitLineIntoSelectSQLAndAlias(testString, out var selectSQL, out var alias); - - Assert.AreEqual("col",selectSQL); - Assert.AreEqual("bob",alias); + + Assert.Multiple(() => + { + Assert.That(selectSQL, Is.EqualTo("col")); + Assert.That(alias, Is.EqualTo("bob")); + }); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -183,9 +196,12 @@ public void Test_NameValidation(DatabaseType dbType) [Test] public void Test_MakeHeaderNameSensible_Unicode() { - //normal unicode is fine - Assert.AreEqual("你好", QuerySyntaxHelper.MakeHeaderNameSensible("你好")); - Assert.AreEqual("你好DropDatabaseBob", QuerySyntaxHelper.MakeHeaderNameSensible("你好; drop database bob;")); + Assert.Multiple(() => + { + //normal unicode is fine + Assert.That(QuerySyntaxHelper.MakeHeaderNameSensible("你好"), Is.EqualTo("你好")); + Assert.That(QuerySyntaxHelper.MakeHeaderNameSensible("你好; drop database bob;"), Is.EqualTo("你好DropDatabaseBob")); + }); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -194,21 +210,21 @@ public void Test_GetFullyQualifiedName(DatabaseType dbType) var syntaxHelper = ImplementationManager.GetImplementation(dbType).GetQuerySyntaxHelper(); var name = syntaxHelper.EnsureFullyQualified("mydb", null, "Troll", ",,,"); - Assert.AreEqual(",,,",syntaxHelper.GetRuntimeName(name)); + Assert.That(syntaxHelper.GetRuntimeName(name), Is.EqualTo(",,,")); switch (dbType) { case DatabaseType.MicrosoftSQLServer: - Assert.AreEqual("[mydb]..[Troll].[,,,]",name); + Assert.That(name, Is.EqualTo("[mydb]..[Troll].[,,,]")); break; case DatabaseType.MySql: - Assert.AreEqual("`mydb`.`Troll`.`,,,`",name); + Assert.That(name, Is.EqualTo("`mydb`.`Troll`.`,,,`")); break; case DatabaseType.Oracle: - Assert.AreEqual("\"MYDB\".\"TROLL\".\",,,\"",name); + Assert.That(name, Is.EqualTo("\"MYDB\".\"TROLL\".\",,,\"")); break; case DatabaseType.PostgreSql: - Assert.AreEqual("\"mydb\".public.\"Troll\".\",,,\"",name); + Assert.That(name, Is.EqualTo("\"mydb\".public.\"Troll\".\",,,\"")); break; default: throw new ArgumentOutOfRangeException(nameof(dbType), dbType, null); @@ -223,21 +239,21 @@ public void Test_GetFullyQualifiedName_WhitespaceSchema(DatabaseType dbType) foreach(var emptySchemaExpression in new [] { null,"", " ", "\t"}) { var name = syntaxHelper.EnsureFullyQualified("mydb", emptySchemaExpression, "Troll", "MyCol"); - Assert.IsTrue(string.Equals("MyCol", syntaxHelper.GetRuntimeName(name),StringComparison.InvariantCultureIgnoreCase)); + Assert.That(string.Equals("MyCol", syntaxHelper.GetRuntimeName(name),StringComparison.InvariantCultureIgnoreCase)); switch (dbType) { case DatabaseType.MicrosoftSQLServer: - Assert.AreEqual("[mydb]..[Troll].[MyCol]",name); + Assert.That(name, Is.EqualTo("[mydb]..[Troll].[MyCol]")); break; case DatabaseType.MySql: - Assert.AreEqual("`mydb`.`Troll`.`MyCol`", name); + Assert.That(name, Is.EqualTo("`mydb`.`Troll`.`MyCol`")); break; case DatabaseType.Oracle: - Assert.AreEqual("\"MYDB\".\"TROLL\".\"MYCOL\"", name); + Assert.That(name, Is.EqualTo("\"MYDB\".\"TROLL\".\"MYCOL\"")); break; case DatabaseType.PostgreSql: - Assert.AreEqual("\"mydb\".public.\"Troll\".\"MyCol\"", name); + Assert.That(name, Is.EqualTo("\"mydb\".public.\"Troll\".\"MyCol\"")); break; default: throw new ArgumentOutOfRangeException(nameof(dbType), dbType, null); @@ -251,11 +267,14 @@ public void Test_GetFullyQualifiedName_BacktickMySql() { var syntaxHelper = ImplementationManager.GetImplementation(DatabaseType.MySql).GetQuerySyntaxHelper(); - //when names have backticks the correct response is to double back tick them - Assert.AreEqual("`ff``ff`",syntaxHelper.EnsureWrapped("ff`ff")); - Assert.AreEqual("`d``b`.`ta``ble`",syntaxHelper.EnsureFullyQualified("d`b",null,"ta`ble")); + Assert.Multiple(() => + { + //when names have backticks the correct response is to double back tick them + Assert.That(syntaxHelper.EnsureWrapped("ff`ff"), Is.EqualTo("`ff``ff`")); + Assert.That(syntaxHelper.EnsureFullyQualified("d`b", null, "ta`ble"), Is.EqualTo("`d``b`.`ta``ble`")); - //runtime name should still be the actual name of the column - Assert.AreEqual("ff`ff",syntaxHelper.GetRuntimeName("ff`ff")); + //runtime name should still be the actual name of the column + Assert.That(syntaxHelper.GetRuntimeName("ff`ff"), Is.EqualTo("ff`ff")); + }); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/Server/ConnectionStringKeywordAccumulatorTests.cs b/Tests/FAnsiTests/Server/ConnectionStringKeywordAccumulatorTests.cs index 33290b57..6339f9cc 100644 --- a/Tests/FAnsiTests/Server/ConnectionStringKeywordAccumulatorTests.cs +++ b/Tests/FAnsiTests/Server/ConnectionStringKeywordAccumulatorTests.cs @@ -8,6 +8,7 @@ using FAnsi.Implementations.Oracle; using FAnsi.Implementations.PostgreSql; using NUnit.Framework; +using NUnit.Framework.Legacy; namespace FAnsiTests.Server; @@ -33,7 +34,7 @@ public void TestKeywords() acc.EnforceOptions(connectionStringBuilder); - Assert.IsTrue(connectionStringBuilder.ConnectionString.IndexOf("Auto Enlist=false", StringComparison.InvariantCultureIgnoreCase) != -1); + Assert.That(connectionStringBuilder.ConnectionString.Contains("Auto Enlist=false", StringComparison.InvariantCultureIgnoreCase)); } diff --git a/Tests/FAnsiTests/Server/ServerLevelUnitTests.cs b/Tests/FAnsiTests/Server/ServerLevelUnitTests.cs index 580bb6f1..e01363fd 100644 --- a/Tests/FAnsiTests/Server/ServerLevelUnitTests.cs +++ b/Tests/FAnsiTests/Server/ServerLevelUnitTests.cs @@ -13,6 +13,6 @@ public void ConstructionStringBuilderTest() InitialCatalog = "master" }; - Assert.AreEqual("Data Source=localhost;Initial Catalog=master;User ID=SA;Password=blah;Encrypt=True;Trust Server Certificate=True", b.ConnectionString); + Assert.That(b.ConnectionString, Is.EqualTo("Data Source=localhost;Initial Catalog=master;User ID=SA;Password=blah;Encrypt=True;Trust Server Certificate=True")); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/Server/ServerTests.cs b/Tests/FAnsiTests/Server/ServerTests.cs index cfe1f596..0f09d9d2 100644 --- a/Tests/FAnsiTests/Server/ServerTests.cs +++ b/Tests/FAnsiTests/Server/ServerTests.cs @@ -13,7 +13,7 @@ internal class ServerLevelTests:DatabaseTests public void Server_Exists(DatabaseType type) { var server = GetTestServer(type); - Assert.IsTrue(server.Exists(), "Server " + server + " did not exist"); + Assert.That(server.Exists(), "Server " + server + " did not exist"); } @@ -23,7 +23,7 @@ public void Server_Constructors(DatabaseType dbType) var helper = ImplementationManager.GetImplementation(dbType).GetServerHelper(); var server = new DiscoveredServer(helper.GetConnectionStringBuilder("localhost", null,"franko","wacky").ConnectionString,dbType); - Assert.AreEqual("localhost",server.Name); + Assert.That(server.Name, Is.EqualTo("localhost")); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -31,7 +31,7 @@ public void Server_RespondsWithinTime(DatabaseType type) { var server = GetTestServer(type); - Assert.IsTrue(server.RespondsWithinTime(3,out _)); + Assert.That(server.RespondsWithinTime(3,out _)); } /// @@ -45,8 +45,11 @@ public void ServerHelper_GetCurrentDatabase_WhenNoneSpecified(DatabaseType type) var builder = helper.GetConnectionStringBuilder(""); var server = new DiscoveredServer(builder); - Assert.AreEqual(null,server.Name); - Assert.AreEqual(null,server.GetCurrentDatabase()); + Assert.Multiple(() => + { + Assert.That(server.Name, Is.EqualTo(null)); + Assert.That(server.GetCurrentDatabase(), Is.EqualTo(null)); + }); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -57,16 +60,19 @@ public void ServerHelper_GetConnectionStringBuilder(DatabaseType type) var server = new DiscoveredServer(builder); - Assert.AreEqual("loco",server.Name); + Assert.That(server.Name, Is.EqualTo("loco")); //Oracle does not persist database in connection string if(type == DatabaseType.Oracle) - Assert.IsNull(server.GetCurrentDatabase()); + Assert.That(server.GetCurrentDatabase(), Is.Null); else - Assert.AreEqual("bob",server.GetCurrentDatabase().GetRuntimeName()); + Assert.That(server.GetCurrentDatabase().GetRuntimeName(), Is.EqualTo("bob")); - Assert.AreEqual("franko",server.ExplicitUsernameIfAny); - Assert.AreEqual("wacky",server.ExplicitPasswordIfAny); + Assert.Multiple(() => + { + Assert.That(server.ExplicitUsernameIfAny, Is.EqualTo("franko")); + Assert.That(server.ExplicitPasswordIfAny, Is.EqualTo("wacky")); + }); } @@ -78,17 +84,26 @@ public void ServerHelper_GetConnectionStringBuilder_NoDatabase(DatabaseType type var server = new DiscoveredServer(builder); - Assert.AreEqual("loco",server.Name); + Assert.Multiple(() => + { + Assert.That(server.Name, Is.EqualTo("loco")); - Assert.IsNull(server.GetCurrentDatabase()); + Assert.That(server.GetCurrentDatabase(), Is.Null); + }); - Assert.AreEqual("franko",server.ExplicitUsernameIfAny); - Assert.AreEqual("wacky",server.ExplicitPasswordIfAny); + Assert.Multiple(() => + { + Assert.That(server.ExplicitUsernameIfAny, Is.EqualTo("franko")); + Assert.That(server.ExplicitPasswordIfAny, Is.EqualTo("wacky")); + }); server = new DiscoveredServer("loco",useWhitespace?" ":null,type,"frank","kangaro"); - Assert.AreEqual("loco",server.Name); + Assert.Multiple(() => + { + Assert.That(server.Name, Is.EqualTo("loco")); - Assert.IsNull(server.GetCurrentDatabase()); + Assert.That(server.GetCurrentDatabase(), Is.Null); + }); } @@ -101,21 +116,27 @@ public void ServerHelper_ChangeDatabase(DatabaseType type,bool expectCaps) { var server = new DiscoveredServer("loco","bob",type,"franko","wacky"); - Assert.AreEqual("loco",server.Name); + Assert.Multiple(() => + { + Assert.That(server.Name, Is.EqualTo("loco")); - //this failure is already exposed by Server_Helper_GetConnectionStringBuilder - Assert.AreEqual(expectCaps?"BOB":"bob",server.GetCurrentDatabase().GetRuntimeName()); + //this failure is already exposed by Server_Helper_GetConnectionStringBuilder + Assert.That(server.GetCurrentDatabase().GetRuntimeName(), Is.EqualTo(expectCaps ? "BOB" : "bob")); - Assert.AreEqual("franko",server.ExplicitUsernameIfAny); - Assert.AreEqual("wacky",server.ExplicitPasswordIfAny); + Assert.That(server.ExplicitUsernameIfAny, Is.EqualTo("franko")); + Assert.That(server.ExplicitPasswordIfAny, Is.EqualTo("wacky")); + }); server.ChangeDatabase("omgggg"); - Assert.AreEqual(server.Name,"loco"); + Assert.Multiple(() => + { + Assert.That(server.Name, Is.EqualTo("loco")); - Assert.AreEqual(expectCaps?"OMGGGG":"omgggg",server.GetCurrentDatabase().GetRuntimeName()); - Assert.AreEqual("franko",server.ExplicitUsernameIfAny); - Assert.AreEqual("wacky",server.ExplicitPasswordIfAny); + Assert.That(server.GetCurrentDatabase().GetRuntimeName(), Is.EqualTo(expectCaps ? "OMGGGG" : "omgggg")); + Assert.That(server.ExplicitUsernameIfAny, Is.EqualTo("franko")); + Assert.That(server.ExplicitPasswordIfAny, Is.EqualTo("wacky")); + }); } @@ -134,25 +155,37 @@ public void ServerHelper_ChangeDatabase_AdHoc(DatabaseType type, bool useApiFirs //create initial server reference var helper = ImplementationManager.GetImplementation(type).GetServerHelper(); var server = new DiscoveredServer(helper.GetConnectionStringBuilder("loco","bob","franko","wacky")); - Assert.AreEqual("loco",server.Name); - Assert.AreEqual("bob",server.GetCurrentDatabase().GetRuntimeName()); + Assert.Multiple(() => + { + Assert.That(server.Name, Is.EqualTo("loco")); + Assert.That(server.GetCurrentDatabase().GetRuntimeName(), Is.EqualTo("bob")); + }); //Use API to change databases - if(useApiFirst) + if (useApiFirst) { server.ChangeDatabase("omgggg"); - Assert.AreEqual("loco",server.Name); - Assert.AreEqual("omgggg",server.GetCurrentDatabase().GetRuntimeName()); + Assert.Multiple(() => + { + Assert.That(server.Name, Is.EqualTo("loco")); + Assert.That(server.GetCurrentDatabase().GetRuntimeName(), Is.EqualTo("omgggg")); + }); } //adhoc changes to builder server.Builder["Database"] = "Fisss"; - Assert.AreEqual("loco",server.Name); - Assert.AreEqual("Fisss",server.GetCurrentDatabase().GetRuntimeName()); + Assert.Multiple(() => + { + Assert.That(server.Name, Is.EqualTo("loco")); + Assert.That(server.GetCurrentDatabase().GetRuntimeName(), Is.EqualTo("Fisss")); + }); server.Builder["Server"] = "Amagad"; - Assert.AreEqual("Amagad",server.Name); - Assert.AreEqual("Fisss",server.GetCurrentDatabase().GetRuntimeName()); + Assert.Multiple(() => + { + Assert.That(server.Name, Is.EqualTo("Amagad")); + Assert.That(server.GetCurrentDatabase().GetRuntimeName(), Is.EqualTo("Fisss")); + }); } [TestCase(DatabaseType.MicrosoftSQLServer,DatabaseType.MySql)] @@ -177,12 +210,12 @@ public void MoveData_BetweenServerTypes(DatabaseType from, DatabaseType to) //Upload it to the first database var fromDb = GetTestDatabase(from); var tblFrom = fromDb.CreateTable("MyTable", dtToMove); - Assert.IsTrue(tblFrom.Exists()); + Assert.That(tblFrom.Exists()); //Get pointer to the second database table (which doesn't exist yet) var toDb = GetTestDatabase(to); var toTable = toDb.ExpectTable("MyNewTable"); - Assert.IsFalse(toTable.Exists()); + Assert.That(toTable.Exists(), Is.False); //Get the clone table sql adjusted to work on the other DBMS var sql = tblFrom.ScriptTableCreation(false, false, false, toTable); @@ -196,7 +229,7 @@ public void MoveData_BetweenServerTypes(DatabaseType from, DatabaseType to) } //new table should exist - Assert.IsTrue(tblFrom.Exists()); + Assert.That(tblFrom.Exists()); using (var insert = toTable.BeginBulkInsert()) { @@ -207,8 +240,11 @@ public void MoveData_BetweenServerTypes(DatabaseType from, DatabaseType to) insert.Upload(fromData); } - Assert.AreEqual(3, tblFrom.GetRowCount()); - Assert.AreEqual(3, toTable.GetRowCount()); + Assert.Multiple(() => + { + Assert.That(tblFrom.GetRowCount(), Is.EqualTo(3)); + Assert.That(toTable.GetRowCount(), Is.EqualTo(3)); + }); AssertAreEqual(toTable.GetDataTable(), tblFrom.GetDataTable()); } @@ -220,9 +256,9 @@ public void TestServer_GetVersion(DatabaseType dbType) var ver = db.Server.GetVersion(); TestContext.WriteLine($"Version:{ver}"); - Assert.IsNotNull(ver); + Assert.That(ver, Is.Not.Null); - Assert.Greater(ver.Major,0); + Assert.That(ver.Major, Is.GreaterThan(0)); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/Table/BadNamesTests.cs b/Tests/FAnsiTests/Table/BadNamesTests.cs index 6976e4ec..1773bde1 100644 --- a/Tests/FAnsiTests/Table/BadNamesTests.cs +++ b/Tests/FAnsiTests/Table/BadNamesTests.cs @@ -50,10 +50,13 @@ public void Test_EnsureWrapped_EmptyExpressions(DatabaseType dbType) var factory = new QuerySyntaxHelperFactory(); var syntax = factory.Create(dbType); - Assert.AreEqual("",syntax.EnsureWrapped("")); - Assert.AreEqual(" ", syntax.EnsureWrapped(" ")); - Assert.AreEqual("\t", syntax.EnsureWrapped("\t")); - Assert.IsNull(syntax.EnsureWrapped(null)); + Assert.Multiple(() => + { + Assert.That(syntax.EnsureWrapped(""), Is.EqualTo("")); + Assert.That(syntax.EnsureWrapped(" "), Is.EqualTo(" ")); + Assert.That(syntax.EnsureWrapped("\t"), Is.EqualTo("\t")); + }); + Assert.That(syntax.EnsureWrapped(null), Is.Null); } @@ -63,8 +66,11 @@ public void BadNames_EnsureWrapped() var db = GetTestDatabase(DatabaseType.MicrosoftSQLServer); var tbl = db.ExpectTable("][nquisitor"); - Assert.IsFalse(tbl.Exists()); - Assert.AreEqual("[]][nquisitor]",tbl.GetWrappedName()); + Assert.Multiple(() => + { + Assert.That(tbl.Exists(), Is.False); + Assert.That(tbl.GetWrappedName(), Is.EqualTo("[]][nquisitor]")); + }); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -72,7 +78,7 @@ public void BadNames_DiscoverColumns(DatabaseType dbType) { var tbl = SetupBadNamesTable(dbType); var cols = tbl.DiscoverColumns(); - Assert.AreEqual(2,cols.Length); + Assert.That(cols, Has.Length.EqualTo(2)); tbl.Drop(); } @@ -84,14 +90,14 @@ public void BadNames_AlterType(DatabaseType dbType) var (_, badColumnName, _) = GetBadNames(dbType); var col = tbl.DiscoverColumn(badColumnName); - Assert.AreEqual(100,col.DataType.GetLengthIfString()); + Assert.That(col.DataType.GetLengthIfString(), Is.EqualTo(100)); var varcharType = tbl.Database.Server.GetQuerySyntaxHelper().TypeTranslater.GetSQLDBTypeForCSharpType(new DatabaseTypeRequest(typeof(string),10)); // Can we ALTER its datatype - Assert.AreEqual(100,col.DataType.GetLengthIfString()); + Assert.That(col.DataType.GetLengthIfString(), Is.EqualTo(100)); col.DataType.AlterTypeTo(varcharType); - Assert.AreEqual(10,col.DataType.GetLengthIfString()); + Assert.That(col.DataType.GetLengthIfString(), Is.EqualTo(10)); tbl.Drop(); @@ -104,13 +110,13 @@ public void BadNames_TopXColumn(DatabaseType dbType,bool noNulls) var tbl = SetupBadNamesTable(dbType); var col = tbl.DiscoverColumn(badColumnName); - Assert.AreEqual(0,tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(0)); tbl.Insert(new Dictionary{{col,"ff" } }); tbl.Insert(new Dictionary{{col,"ff" } }); tbl.Insert(new Dictionary{{col,DBNull.Value } }); - Assert.AreEqual(3,tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(3)); var topx = col.GetTopXSql(5,noNulls); @@ -121,12 +127,12 @@ public void BadNames_TopXColumn(DatabaseType dbType,bool noNulls) var cmd = svr.GetCommand(topx,con); var r= cmd.ExecuteReader(); - Assert.IsTrue(r.Read()); - Assert.IsTrue(r.Read()); + Assert.That(r.Read()); + Assert.That(r.Read()); - Assert.AreEqual(!noNulls,r.Read()); + Assert.That(r.Read(), Is.EqualTo(!noNulls)); - Assert.IsFalse(r.Read()); + Assert.That(r.Read(), Is.False); } tbl.Drop(); @@ -139,13 +145,13 @@ public void BadNames_DropColumn(DatabaseType dbType) var (_, badColumnName, _) = GetBadNames(dbType); var tbl = SetupBadNamesTable(dbType); - Assert.AreEqual(2,tbl.DiscoverColumns().Length); + Assert.That(tbl.DiscoverColumns(), Has.Length.EqualTo(2)); var col = tbl.DiscoverColumn(badColumnName); tbl.DropColumn(col); - Assert.AreEqual(1,tbl.DiscoverColumns().Length); + Assert.That(tbl.DiscoverColumns(), Has.Length.EqualTo(1)); tbl.Drop(); } @@ -159,7 +165,7 @@ public void BadNames_TopXTable(DatabaseType dbType) var tbl = SetupBadNamesTable(dbType); var col = tbl.DiscoverColumn(badColumnName); - Assert.AreEqual(0,tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(0)); tbl.Insert(new Dictionary{{col,"ff" } }); tbl.Insert(new Dictionary{{col,"ff" } }); @@ -174,9 +180,9 @@ public void BadNames_TopXTable(DatabaseType dbType) var cmd = svr.GetCommand(topx,con); var r= cmd.ExecuteReader(); - Assert.IsTrue(r.Read()); - Assert.IsTrue(r.Read()); - Assert.IsFalse(r.Read()); + Assert.That(r.Read()); + Assert.That(r.Read()); + Assert.That(r.Read(), Is.False); } tbl.Drop(); @@ -206,11 +212,14 @@ public void BadNames_DiscoverRelationships(DatabaseType dbType) var r = tbl1.DiscoverRelationships().Single(); - Assert.AreEqual(tbl1,r.PrimaryKeyTable); - Assert.AreEqual(tbl2,r.ForeignKeyTable); + Assert.Multiple(() => + { + Assert.That(r.PrimaryKeyTable, Is.EqualTo(tbl1)); + Assert.That(r.ForeignKeyTable, Is.EqualTo(tbl2)); - Assert.AreEqual(pk, r.Keys.Single().Key); - Assert.AreEqual(tbl2.DiscoverColumn($"{badColumnName}2"), r.Keys.Single().Value); + Assert.That(r.Keys.Single().Key, Is.EqualTo(pk)); + Assert.That(r.Keys.Single().Value, Is.EqualTo(tbl2.DiscoverColumn($"{badColumnName}2"))); + }); tbl2.Drop(); tbl1.Drop(); @@ -233,7 +242,7 @@ public void BadNames_BulkInsert(DatabaseType dbType) insert.Upload(dt); } - Assert.AreEqual(1,dt.Rows.Count); + Assert.That(dt.Rows, Has.Count.EqualTo(1)); tbl.Drop(); } @@ -248,7 +257,7 @@ public void BadNames_Rename(DatabaseType dbType) tbl.Rename(badTableName.Replace('F','A')); - Assert.AreNotEqual(nameBefore,tbl.GetFullyQualifiedName()); + Assert.That(tbl.GetFullyQualifiedName(), Is.Not.EqualTo(nameBefore)); tbl.Drop(); } diff --git a/Tests/FAnsiTests/Table/BasicInsertTests.cs b/Tests/FAnsiTests/Table/BasicInsertTests.cs index ef26e311..42db21d1 100644 --- a/Tests/FAnsiTests/Table/BasicInsertTests.cs +++ b/Tests/FAnsiTests/Table/BasicInsertTests.cs @@ -44,8 +44,8 @@ public void CreateTableAndInsertAValue_ColumnOverload(DatabaseType type, object }); var result = tbl.GetDataTable(); - Assert.AreEqual(1,result.Rows.Count); - Assert.AreEqual(value,result.Rows[0][0]); + Assert.That(result.Rows, Has.Count.EqualTo(1)); + Assert.That(result.Rows[0][0], Is.EqualTo(value)); tbl.Drop(); } @@ -69,8 +69,8 @@ public void CreateTableAndInsertAValue_StringOverload(DatabaseType type, object }); var result = tbl.GetDataTable(); - Assert.AreEqual(1, result.Rows.Count); - Assert.AreEqual(value, result.Rows[0][0]); + Assert.That(result.Rows, Has.Count.EqualTo(1)); + Assert.That(result.Rows[0][0], Is.EqualTo(value)); tbl.Drop(); } @@ -93,7 +93,7 @@ public void CreateTableAndInsertAValue_ReturnsIdentity(DatabaseType type) {nameCol,"fish"} }); - Assert.AreEqual(1,result); + Assert.That(result, Is.EqualTo(1)); result = tbl.Insert(new Dictionary @@ -101,6 +101,6 @@ public void CreateTableAndInsertAValue_ReturnsIdentity(DatabaseType type) {nameCol,"fish"} }); - Assert.AreEqual(2, result); + Assert.That(result, Is.EqualTo(2)); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/Table/BigIntTests.cs b/Tests/FAnsiTests/Table/BigIntTests.cs index 65f1cb10..33dd675b 100644 --- a/Tests/FAnsiTests/Table/BigIntTests.cs +++ b/Tests/FAnsiTests/Table/BigIntTests.cs @@ -14,12 +14,15 @@ public void TestBigInt_Insert(DatabaseType dbType) var db = GetTestDatabase(dbType); var tbl = db.CreateTable("MyBigIntTable", new []{ new DatabaseColumnRequest("Col1","bigint",false)}); - Assert.AreEqual(0,tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(0)); tbl.Insert(new Dictionary{ {"Col1",9223372036854775807L} }); - Assert.AreEqual(1,tbl.GetRowCount()); - Assert.AreEqual(9223372036854775807L,tbl.GetDataTable().Rows[0][0]); + Assert.Multiple(() => + { + Assert.That(tbl.GetRowCount(), Is.EqualTo(1)); + Assert.That(tbl.GetDataTable().Rows[0][0], Is.EqualTo(9223372036854775807L)); + }); tbl.Drop(); } @@ -29,7 +32,7 @@ public void TestBigInt_InsertDataTable(DatabaseType dbType) var db = GetTestDatabase(dbType); var tbl = db.CreateTable("MyBigIntTable", new []{ new DatabaseColumnRequest("Col1","bigint",false)}); - Assert.AreEqual(0,tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(0)); using var dt = new DataTable(); dt.Columns.Add("Col1"); @@ -40,8 +43,11 @@ public void TestBigInt_InsertDataTable(DatabaseType dbType) insert.Upload(dt); } - Assert.AreEqual(1,tbl.GetRowCount()); - Assert.AreEqual(9223372036854775807L,tbl.GetDataTable().Rows[0][0]); + Assert.Multiple(() => + { + Assert.That(tbl.GetRowCount(), Is.EqualTo(1)); + Assert.That(tbl.GetDataTable().Rows[0][0], Is.EqualTo(9223372036854775807L)); + }); tbl.Drop(); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/Table/BulkInsertTest.cs b/Tests/FAnsiTests/Table/BulkInsertTest.cs index e65ecff8..c9f9b16c 100644 --- a/Tests/FAnsiTests/Table/BulkInsertTest.cs +++ b/Tests/FAnsiTests/Table/BulkInsertTest.cs @@ -9,6 +9,7 @@ using FAnsi.Discovery.QuerySyntax; using FAnsi.Exceptions; using NUnit.Framework; +using NUnit.Framework.Legacy; using TypeGuesser; namespace FAnsiTests.Table; @@ -28,7 +29,7 @@ public void TestBulkInsert_Basic(DatabaseType type) }); //There are no rows in the table yet - Assert.AreEqual(0, tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(0)); using var dt = new DataTable(); dt.Columns.Add("Name"); @@ -40,14 +41,14 @@ public void TestBulkInsert_Basic(DatabaseType type) bulk.Timeout = 30; bulk.Upload(dt); - Assert.AreEqual(2, tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(2)); dt.Rows.Clear(); dt.Rows.Add("Frank", 100); bulk.Upload(dt); - Assert.AreEqual(3, tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(3)); } [TestCaseSource(typeof(All), nameof(All.DatabaseTypes))] @@ -63,7 +64,7 @@ public void TestBulkInsert_SpacedOutNames(DatabaseType type) }); //There are no rows in the table yet - Assert.AreEqual(0, tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(0)); using (var dt = new DataTable()) { @@ -76,14 +77,14 @@ public void TestBulkInsert_SpacedOutNames(DatabaseType type) bulk.Timeout = 30; bulk.Upload(dt); - Assert.AreEqual(2, tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(2)); dt.Rows.Clear(); dt.Rows.Add("Frank", 100); bulk.Upload(dt); - Assert.AreEqual(3, tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(3)); } tbl.Insert(new Dictionary @@ -92,7 +93,7 @@ public void TestBulkInsert_SpacedOutNames(DatabaseType type) {"A ge", "300"} }); - Assert.AreEqual(4, tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(4)); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -108,7 +109,7 @@ public void TestBulkInsert_ColumnOrdinals(DatabaseType type) }); //There are no rows in the table yet - Assert.AreEqual(0, tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(0)); using var dt = new DataTable(); dt.Columns.Add("Age"); @@ -116,20 +117,26 @@ public void TestBulkInsert_ColumnOrdinals(DatabaseType type) dt.Rows.Add( "50","David"); dt.Rows.Add("60","Jamie"); - Assert.AreEqual("Age",dt.Columns[0].ColumnName); - Assert.AreEqual(typeof(string),dt.Columns[0].DataType); + Assert.Multiple(() => + { + Assert.That(dt.Columns[0].ColumnName, Is.EqualTo("Age")); + Assert.That(dt.Columns[0].DataType, Is.EqualTo(typeof(string))); + }); using (var bulk = tbl.BeginBulkInsert()) { bulk.Timeout = 30; bulk.Upload(dt); - Assert.AreEqual(2, tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(2)); } - //columns should not be reordered - Assert.AreEqual("Age",dt.Columns[0].ColumnName); - Assert.AreEqual(typeof(int),dt.Columns[0].DataType); //but the data type was changed by HardTyping it + Assert.Multiple(() => + { + //columns should not be reordered + Assert.That(dt.Columns[0].ColumnName, Is.EqualTo("Age")); + Assert.That(dt.Columns[0].DataType, Is.EqualTo(typeof(int))); //but the data type was changed by HardTyping it + }); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -145,7 +152,7 @@ public void TestBulkInsert_Transaction(DatabaseType type) }); - Assert.AreEqual(0, tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(0)); using (var dt = new DataTable()) { @@ -161,7 +168,7 @@ public void TestBulkInsert_Transaction(DatabaseType type) bulk.Upload(dt); //inside transaction the count is 2 - Assert.AreEqual(2, tbl.GetRowCount(transaction.ManagedTransaction)); + Assert.That(tbl.GetRowCount(transaction.ManagedTransaction), Is.EqualTo(2)); dt.Rows.Clear(); dt.Rows.Add("Frank", 100); @@ -169,14 +176,14 @@ public void TestBulkInsert_Transaction(DatabaseType type) bulk.Upload(dt); //inside transaction the count is 3 - Assert.AreEqual(3, tbl.GetRowCount(transaction.ManagedTransaction)); + Assert.That(tbl.GetRowCount(transaction.ManagedTransaction), Is.EqualTo(3)); } transaction.ManagedTransaction.CommitAndCloseConnection(); } //Transaction was committed final row count should be 3 - Assert.AreEqual(3, tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(3)); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -192,7 +199,7 @@ public void TestBulkInsert_AbandonTransaction(DatabaseType type) }); - Assert.AreEqual(0, tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(0)); using (var dt = new DataTable()) { @@ -208,7 +215,7 @@ public void TestBulkInsert_AbandonTransaction(DatabaseType type) bulk.Upload(dt); //inside transaction the count is 2 - Assert.AreEqual(2, tbl.GetRowCount(transaction.ManagedTransaction)); + Assert.That(tbl.GetRowCount(transaction.ManagedTransaction), Is.EqualTo(2)); dt.Rows.Clear(); dt.Rows.Add("Frank", 100); @@ -216,14 +223,14 @@ public void TestBulkInsert_AbandonTransaction(DatabaseType type) bulk.Upload(dt); //inside transaction the count is 3 - Assert.AreEqual(3, tbl.GetRowCount(transaction.ManagedTransaction)); + Assert.That(tbl.GetRowCount(transaction.ManagedTransaction), Is.EqualTo(3)); } transaction.ManagedTransaction.AbandonAndCloseConnection(); } //We abandoned transaction so final rowcount should be 0 - Assert.AreEqual(0, tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(0)); } @@ -239,7 +246,7 @@ public void TestBulkInsert_AlterColumn_MidTransaction(DatabaseType type) new DatabaseColumnRequest("Age", new DatabaseTypeRequest(typeof (int))) }); - Assert.AreEqual(0, tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(0)); using (var dt = new DataTable()) { @@ -255,7 +262,7 @@ public void TestBulkInsert_AlterColumn_MidTransaction(DatabaseType type) bulk.Upload(dt); //inside transaction the count is 2 - Assert.AreEqual(2, tbl.GetRowCount(transaction.ManagedTransaction)); + Assert.That(tbl.GetRowCount(transaction.ManagedTransaction), Is.EqualTo(2)); //New row is too long for the data type dt.Rows.Clear(); @@ -271,14 +278,14 @@ public void TestBulkInsert_AlterColumn_MidTransaction(DatabaseType type) bulk.Upload(dt); //inside transaction the count is 3 - Assert.AreEqual(3, tbl.GetRowCount(transaction.ManagedTransaction)); + Assert.That(tbl.GetRowCount(transaction.ManagedTransaction), Is.EqualTo(3)); } transaction.ManagedTransaction.CommitAndCloseConnection(); } //We abandoned transaction so final rowcount should be 0 - Assert.AreEqual(3, tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(3)); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -305,7 +312,7 @@ public void BulkInsert_MixedCase(DatabaseType type) } using var result = tbl.GetDataTable(); - Assert.AreEqual(2, result.Rows.Count); //2 rows inserted + Assert.That(result.Rows, Has.Count.EqualTo(2)); //2 rows inserted } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -340,11 +347,17 @@ public void UnmatchedColumnsBulkInsertTest_UsesDefaultValues_Passes(DatabaseType var result = tbl.GetDataTable(); - Assert.AreEqual(3, result.Columns.Count); - Assert.AreEqual("yes", result.Rows[0]["bob"]); - Assert.NotNull(result.Rows[0]["frank"]); - Assert.GreaterOrEqual(result.Rows[0]["frank"].ToString()?.Length, 5); //should be a date - Assert.AreEqual("no", result.Rows[0]["peter"]); + Assert.Multiple(() => + { + Assert.That(result.Columns, Has.Count.EqualTo(3)); + Assert.That(result.Rows[0]["bob"], Is.EqualTo("yes")); + Assert.That(result.Rows[0]["frank"], Is.Not.Null); + }); + Assert.Multiple(() => + { + Assert.That(result.Rows[0]["frank"].ToString()?.Length, Is.GreaterThanOrEqualTo(5)); //should be a date + Assert.That(result.Rows[0]["peter"], Is.EqualTo("no")); + }); tbl.Drop(); } @@ -431,7 +444,7 @@ public void UnmatchedColumnsBulkInsertTest_UsesDefaultValues_TwoLargeBatches_Pas using (var blk = tbl.BeginBulkInsert()) { - Assert.AreEqual(numberOfRowsPerBatch, blk.Upload(dt)); //affected rows should match batch size + Assert.That(blk.Upload(dt), Is.EqualTo(numberOfRowsPerBatch)); //affected rows should match batch size } sw.Stop(); TestContext.WriteLine($"Time taken:{sw.ElapsedMilliseconds}ms"); @@ -446,7 +459,7 @@ public void UnmatchedColumnsBulkInsertTest_UsesDefaultValues_TwoLargeBatches_Pas using (var blk = tbl.BeginBulkInsert()) { - Assert.AreEqual(numberOfRowsPerBatch, blk.Upload(dt)); + Assert.That(blk.Upload(dt), Is.EqualTo(numberOfRowsPerBatch)); } sw.Stop(); @@ -455,18 +468,27 @@ public void UnmatchedColumnsBulkInsertTest_UsesDefaultValues_TwoLargeBatches_Pas var result = tbl.GetDataTable(); - Assert.AreEqual(33, result.Columns.Count); - Assert.AreEqual(numberOfRowsPerBatch*2, result.Rows.Count); - Assert.NotNull(result.Rows[0]["bob"]); - Assert.NotNull(result.Rows[0]["frank"]); - Assert.GreaterOrEqual(result.Rows[0]["frank"].ToString()?.Length, 5); //should be a date - Assert.AreEqual("no", result.Rows[0]["peter"]); + Assert.Multiple(() => + { + Assert.That(result.Columns, Has.Count.EqualTo(33)); + Assert.That(result.Rows, Has.Count.EqualTo(numberOfRowsPerBatch * 2)); + }); + Assert.Multiple(() => + { + Assert.That(result.Rows[0]["bob"], Is.Not.Null); + Assert.That(result.Rows[0]["frank"], Is.Not.Null); + }); + Assert.Multiple(() => + { + Assert.That(result.Rows[0]["frank"].ToString()?.Length, Is.GreaterThanOrEqualTo(5)); //should be a date + Assert.That(result.Rows[0]["peter"], Is.EqualTo("no")); + }); //while we have a ton of data in there let's test some cancellation operations //no primary key var bobCol = tbl.DiscoverColumn("bob"); - Assert.IsFalse(tbl.DiscoverColumns().Any(c=>c.IsPrimaryKey)); + Assert.That(!tbl.DiscoverColumns().Any(static c=>c.IsPrimaryKey), Is.True); using (var con = tbl.Database.Server.BeginNewTransactedConnection()) @@ -490,20 +512,21 @@ public void UnmatchedColumnsBulkInsertTest_UsesDefaultValues_TwoLargeBatches_Pas //give it 300 ms delay (simulates user cancelling not DbCommand.Timeout expiring) using var cts = new CancellationTokenSource(300); //GetDataTable should have been cancelled at the database level - Assert.Throws(()=>tbl.GetDataTable(new DatabaseOperationArgs(con.ManagedTransaction,cts.Token,50000))); - tbl.GetDataTable(new DatabaseOperationArgs(con.ManagedTransaction,default,50000)); + Assert.Throws(()=>tbl.GetDataTable(new DatabaseOperationArgs(con.ManagedTransaction,50000, + cts.Token))); + tbl.GetDataTable(new DatabaseOperationArgs(con.ManagedTransaction,50000, default)); } //and there should not be any primary keys - Assert.IsFalse(tbl.DiscoverColumns().Any(c=>c.IsPrimaryKey)); + Assert.That(tbl.DiscoverColumns().Any(c=>c.IsPrimaryKey), Is.False); //now give it a bit longer to create it using(var cts = new CancellationTokenSource(50000000)) tbl.CreatePrimaryKey(null, cts.Token, 50000, bobCol); bobCol = tbl.DiscoverColumn("bob"); - Assert.IsTrue(bobCol.IsPrimaryKey); + Assert.That(bobCol.IsPrimaryKey); tbl.Drop(); } @@ -558,17 +581,23 @@ public void AutoIncrementPrimaryKey_Passes(DatabaseType type) dt.Rows.Add("tank"); using var blk = tbl.BeginBulkInsert(); - Assert.AreEqual(3, blk.Upload(dt)); + Assert.That(blk.Upload(dt), Is.EqualTo(3)); } var result = tbl.GetDataTable(); - Assert.AreEqual(2, result.Columns.Count); - Assert.AreEqual(3, result.Rows.Count); - Assert.AreEqual(1, result.Rows.Cast().Count(r => Convert.ToInt32(r["bob"]) == 1)); - Assert.AreEqual(1, result.Rows.Cast().Count(r => Convert.ToInt32(r["bob"]) == 2)); - Assert.AreEqual(1, result.Rows.Cast().Count(r => Convert.ToInt32(r["bob"]) == 3)); + Assert.Multiple(() => + { + Assert.That(result.Columns, Has.Count.EqualTo(2)); + Assert.That(result.Rows, Has.Count.EqualTo(3)); + }); + Assert.Multiple(() => + { + Assert.That(result.Rows.Cast().Count(r => Convert.ToInt32(r["bob"]) == 1), Is.EqualTo(1)); + Assert.That(result.Rows.Cast().Count(r => Convert.ToInt32(r["bob"]) == 2), Is.EqualTo(1)); + Assert.That(result.Rows.Cast().Count(r => Convert.ToInt32(r["bob"]) == 3), Is.EqualTo(1)); + }); } @@ -592,7 +621,7 @@ public void TestBulkInsert_ScientificNotation(DatabaseType type) dt.Rows.Add("-4.10235746055587E-05"); //-0.0000410235746055587 <- this is what the number is //-0.0000410235 <- this is what goes into db since we only asked for 10 digits after decimal place using var blk = tbl.BeginBulkInsert(); - Assert.AreEqual(1, blk.Upload(dt)); + Assert.That(blk.Upload(dt), Is.EqualTo(1)); } @@ -601,9 +630,12 @@ public void TestBulkInsert_ScientificNotation(DatabaseType type) //the numbers read from the database should be pretty much exactly -0.0000410235 but Decimals are always a pain so... var result = tbl.GetDataTable(); - //right number of rows/columns? - Assert.AreEqual(1, result.Columns.Count); - Assert.AreEqual(2, result.Rows.Count); + Assert.Multiple(() => + { + //right number of rows/columns? + Assert.That(result.Columns, Has.Count.EqualTo(1)); + Assert.That(result.Rows, Has.Count.EqualTo(2)); + }); //get cell values rounded to 9 decimal places var c1 = Math.Round((decimal) result.Rows[0][0], 9); @@ -646,12 +678,13 @@ public void TestBulkInsert_Unicode(DatabaseType dbType) //now check that it all worked! var dtResult = table.GetDataTable(); - Assert.AreEqual(3,dtResult.Rows.Count); + Assert.That(dtResult.Rows, Has.Count.EqualTo(3)); //value fetched from database should match the one inserted - Assert.Contains("乗 12345",dtResult.Rows.Cast().Select(r=>r[0]).ToArray()); - Assert.Contains("你好",dtResult.Rows.Cast().Select(r=>r[0]).ToArray()); - Assert.Contains("مرحبا",dtResult.Rows.Cast().Select(r=>r[0]).ToArray()); + var values = dtResult.Rows.Cast().Select(static r => (string)r[0]).ToArray(); + Assert.That(values, Does.Contain("乗 12345")); + Assert.That(values, Does.Contain("你好")); + Assert.That(values, Does.Contain("مرحبا")); table.Drop(); } @@ -669,7 +702,7 @@ public void TestBulkInsert_SchemaTooNarrow_StringError(DatabaseType type) }); //There are no rows in the table yet - Assert.AreEqual(0, tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(0)); using var dt = new DataTable(); dt.Columns.Add("age"); @@ -693,7 +726,7 @@ public void TestBulkInsert_SchemaTooNarrow_StringError(DatabaseType type) StringAssert.Contains("BulkInsert failed on data row 4 the complaint was about source column <> which had value <> destination data type was <>",ex.Message); break; case DatabaseType.MySql: - Assert.AreEqual("Data too long for column 'Name' at row 4",ex.Message); + Assert.That(ex.Message, Is.EqualTo("Data too long for column 'Name' at row 4")); break; case DatabaseType.Oracle: StringAssert.Contains("NAME",ex.Message); @@ -721,7 +754,7 @@ public void TestBulkInsert_ExplicitDateTimeFormats(DatabaseType type) }); //There are no rows in the table yet - Assert.AreEqual(0, tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(0)); using (var dt = new DataTable()) { @@ -735,7 +768,7 @@ public void TestBulkInsert_ExplicitDateTimeFormats(DatabaseType type) } var dtDown = tbl.GetDataTable(); - Assert.AreEqual(new DateTime(2001,12,30),dtDown.Rows[0]["MyDate"]); + Assert.That(dtDown.Rows[0]["MyDate"], Is.EqualTo(new DateTime(2001,12,30))); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -753,7 +786,7 @@ public void TestBulkInsert_SchemaTooNarrow_DecimalError(DatabaseType type) }); //There are no rows in the table yet - Assert.AreEqual(0, tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(0)); using var dt = new DataTable(); dt.Columns.Add("age"); @@ -769,17 +802,7 @@ public void TestBulkInsert_SchemaTooNarrow_DecimalError(DatabaseType type) using var bulk = tbl.BeginBulkInsert(); bulk.Timeout = 30; - Exception ex = null; - try - { - bulk.Upload(dt); - } - catch(Exception e) - { - ex = e; - } - - Assert.IsNotNull(ex,"Expected upload to fail because value on row 2 is too long"); + var ex = Assert.Catch(()=>bulk.Upload(dt),"Expected upload to fail because value on row 2 is too long"); switch (type) { @@ -788,7 +811,7 @@ public void TestBulkInsert_SchemaTooNarrow_DecimalError(DatabaseType type) StringAssert.Contains("Parameter value '111111111.1' is out of range",ex.Message); break; case DatabaseType.MySql: - Assert.AreEqual("Out of range value for column 'Score' at row 3",ex.Message); + Assert.That(ex?.Message, Is.EqualTo("Out of range value for column 'Score' at row 3")); break; case DatabaseType.Oracle: StringAssert.Contains("value larger than specified precision allowed for this column",ex.Message); @@ -818,7 +841,7 @@ public void TestBulkInsert_BadDecimalFormat_DecimalError(DatabaseType type) }); //There are no rows in the table yet - Assert.AreEqual(0, tbl.GetRowCount()); + Assert.That(tbl.GetRowCount(), Is.EqualTo(0)); using var dt = new DataTable(); dt.Columns.Add("age"); @@ -844,10 +867,13 @@ public void TestBulkInsert_BadDecimalFormat_DecimalError(DatabaseType type) ex = e; } - Assert.IsNotNull(ex,"Expected upload to fail because value on row 2 is bad"); + Assert.That(ex, Is.Not.Null, "Expected upload to fail because value on row 2 is bad"); - Assert.AreEqual("Failed to parse value '.' in column 'score'",ex.Message); - Assert.IsNotNull(ex.InnerException,"Expected parse error to be an inner exception"); + Assert.Multiple(() => + { + Assert.That(ex.Message, Is.EqualTo("Failed to parse value '.' in column 'score'")); + Assert.That(ex.InnerException, Is.Not.Null, "Expected parse error to be an inner exception"); + }); StringAssert.Contains("Could not parse string value '.' with Decider Type:DecimalTypeDecider",ex.InnerException.Message); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/Table/CreatePrimaryKeyTest.cs b/Tests/FAnsiTests/Table/CreatePrimaryKeyTest.cs index b64858c0..a132f3c5 100644 --- a/Tests/FAnsiTests/Table/CreatePrimaryKeyTest.cs +++ b/Tests/FAnsiTests/Table/CreatePrimaryKeyTest.cs @@ -37,15 +37,21 @@ public void TestBasicCase_KeysCreated(DatabaseType databaseType) var col = tbl.DiscoverColumn("A"); - Assert.IsTrue(col.AllowNulls); - Assert.IsFalse(col.IsPrimaryKey); + Assert.Multiple(() => + { + Assert.That(col.AllowNulls); + Assert.That(col.IsPrimaryKey, Is.False); + }); tbl.CreatePrimaryKey(col); col = tbl.DiscoverColumn("A"); - Assert.IsFalse(col.AllowNulls); - Assert.IsTrue(col.IsPrimaryKey); + Assert.Multiple(() => + { + Assert.That(col.AllowNulls, Is.False); + Assert.That(col.IsPrimaryKey); + }); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -73,22 +79,31 @@ public void TestBasicCase_FailHalfWay_SchemaUnchanged(DatabaseType databaseType) var colA = tbl.DiscoverColumn("A"); var colB = tbl.DiscoverColumn("B"); - //Pre state - Assert.IsTrue(colA.AllowNulls); - Assert.IsFalse(colA.IsPrimaryKey); - Assert.IsTrue(colB.AllowNulls); - Assert.IsFalse(colB.IsPrimaryKey); + Assert.Multiple(() => + { + //Pre state + Assert.That(colA.AllowNulls); + Assert.That(colA.IsPrimaryKey, Is.False); + Assert.That(colB.AllowNulls); + Assert.That(colB.IsPrimaryKey, Is.False); + }); var ex = Assert.Throws(()=>tbl.CreatePrimaryKey(colA, colB)); - Assert.IsTrue(ex?.Message.Contains("Failed to create primary key on table")); - Assert.IsNotInstanceOf(typeof(AggregateException), ex?.InnerException); - Assert.IsInstanceOf(ex?.InnerException); + Assert.Multiple(() => + { + Assert.That(ex?.Message.Contains("Failed to create primary key on table") ?? false); + Assert.That(ex?.InnerException, Is.Not.InstanceOf(typeof(AggregateException))); + Assert.That(ex?.InnerException, Is.InstanceOf()); + }); colA = tbl.DiscoverColumn("A"); colB = tbl.DiscoverColumn("B"); - //Post state should exactly match - Assert.IsFalse(colA.IsPrimaryKey); - Assert.IsFalse(colB.IsPrimaryKey); + Assert.Multiple(() => + { + //Post state should exactly match + Assert.That(colA.IsPrimaryKey, Is.False); + Assert.That(colB.IsPrimaryKey, Is.False); + }); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/Table/CreateTableTests.cs b/Tests/FAnsiTests/Table/CreateTableTests.cs index 66875099..c6e62841 100644 --- a/Tests/FAnsiTests/Table/CreateTableTests.cs +++ b/Tests/FAnsiTests/Table/CreateTableTests.cs @@ -8,6 +8,7 @@ using FAnsi.Discovery.TableCreation; using FAnsi.Extensions; using NUnit.Framework; +using NUnit.Framework.Legacy; using TypeGuesser; namespace FAnsiTests.Table; @@ -23,11 +24,11 @@ public void CreateSimpleTable_Exists(DatabaseType type) new DatabaseColumnRequest("Name", new DatabaseTypeRequest(typeof (string), 10)) }); - Assert.IsTrue(table.Exists()); + Assert.That(table.Exists()); table.Drop(); - Assert.IsFalse(table.Exists()); + Assert.That(table.Exists(), Is.False); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -53,41 +54,56 @@ public void TestTableCreation(DatabaseType type) }); - Assert.IsTrue(tbl.Exists()); + Assert.That(tbl.Exists()); var colsDictionary = tbl.DiscoverColumns().ToDictionary(k => k.GetRuntimeName(), v => v, StringComparer.InvariantCultureIgnoreCase); var name = colsDictionary["name"]; - Assert.AreEqual(10, name.DataType.GetLengthIfString()); - Assert.AreEqual(false, name.AllowNulls); - Assert.AreEqual(typeof(string), syntaxHelper.TypeTranslater.GetCSharpTypeForSQLDBType(name.DataType.SQLType)); - Assert.IsTrue(name.IsPrimaryKey); + Assert.Multiple(() => + { + Assert.That(name.DataType.GetLengthIfString(), Is.EqualTo(10)); + Assert.That(name.AllowNulls, Is.EqualTo(false)); + Assert.That(syntaxHelper.TypeTranslater.GetCSharpTypeForSQLDBType(name.DataType.SQLType), Is.EqualTo(typeof(string))); + Assert.That(name.IsPrimaryKey); + }); var normalisedName = syntaxHelper.GetRuntimeName("foreignName"); //some database engines don't like capital letters? var foreignName = colsDictionary[normalisedName]; - Assert.AreEqual(false, foreignName.AllowNulls);//because it is part of the primary key we ignored the users request about nullability - Assert.AreEqual(7, foreignName.DataType.GetLengthIfString()); - Assert.AreEqual(typeof(string), syntaxHelper.TypeTranslater.GetCSharpTypeForSQLDBType(foreignName.DataType.SQLType)); - Assert.IsTrue(foreignName.IsPrimaryKey); + Assert.Multiple(() => + { + Assert.That(foreignName.AllowNulls, Is.EqualTo(false));//because it is part of the primary key we ignored the users request about nullability + Assert.That(foreignName.DataType.GetLengthIfString(), Is.EqualTo(7)); + Assert.That(syntaxHelper.TypeTranslater.GetCSharpTypeForSQLDBType(foreignName.DataType.SQLType), Is.EqualTo(typeof(string))); + Assert.That(foreignName.IsPrimaryKey); + }); var address = colsDictionary["address"]; - Assert.AreEqual(500, address.DataType.GetLengthIfString()); - Assert.AreEqual(true, address.AllowNulls); - Assert.AreEqual(typeof(string), syntaxHelper.TypeTranslater.GetCSharpTypeForSQLDBType(address.DataType.SQLType)); - Assert.IsFalse(address.IsPrimaryKey); + Assert.Multiple(() => + { + Assert.That(address.DataType.GetLengthIfString(), Is.EqualTo(500)); + Assert.That(address.AllowNulls, Is.EqualTo(true)); + Assert.That(syntaxHelper.TypeTranslater.GetCSharpTypeForSQLDBType(address.DataType.SQLType), Is.EqualTo(typeof(string))); + Assert.That(address.IsPrimaryKey, Is.False); + }); var dob = colsDictionary["dob"]; - Assert.AreEqual(-1, dob.DataType.GetLengthIfString()); - Assert.AreEqual(false, dob.AllowNulls); - Assert.AreEqual(typeof(DateTime), syntaxHelper.TypeTranslater.GetCSharpTypeForSQLDBType(dob.DataType.SQLType)); - Assert.IsFalse(dob.IsPrimaryKey); + Assert.Multiple(() => + { + Assert.That(dob.DataType.GetLengthIfString(), Is.EqualTo(-1)); + Assert.That(dob.AllowNulls, Is.EqualTo(false)); + Assert.That(syntaxHelper.TypeTranslater.GetCSharpTypeForSQLDBType(dob.DataType.SQLType), Is.EqualTo(typeof(DateTime))); + Assert.That(dob.IsPrimaryKey, Is.False); + }); var score = colsDictionary["score"]; - Assert.AreEqual(true, score.AllowNulls); - Assert.AreEqual(5, score.DataType.GetDecimalSize().NumbersBeforeDecimalPlace); - Assert.AreEqual(3, score.DataType.GetDecimalSize().NumbersAfterDecimalPlace); + Assert.Multiple(() => + { + Assert.That(score.AllowNulls, Is.EqualTo(true)); + Assert.That(score.DataType.GetDecimalSize().NumbersBeforeDecimalPlace, Is.EqualTo(5)); + Assert.That(score.DataType.GetDecimalSize().NumbersAfterDecimalPlace, Is.EqualTo(3)); - Assert.AreEqual(typeof(decimal), syntaxHelper.TypeTranslater.GetCSharpTypeForSQLDBType(score.DataType.SQLType)); + Assert.That(syntaxHelper.TypeTranslater.GetCSharpTypeForSQLDBType(score.DataType.SQLType), Is.EqualTo(typeof(decimal))); + }); tbl.Drop(); } @@ -103,8 +119,8 @@ public void Test_CreateTable_ProprietaryType() new [] {new DatabaseColumnRequest("Name", "VARCHAR2(10)")} ); - Assert.AreEqual(10, table.DiscoverColumn("Name").DataType.GetLengthIfString()); - + Assert.That(table.DiscoverColumn("Name").DataType.GetLengthIfString(), Is.EqualTo(10)); + table.Drop(); } @@ -117,7 +133,7 @@ public void CreateSimpleTable_VarcharTypeCorrect(DatabaseType type) new DatabaseColumnRequest("Name", new DatabaseTypeRequest(typeof (string), 5)) }); - Assert.IsTrue(table.Exists()); + Assert.That(table.Exists()); var dbType = table.DiscoverColumn("Name").DataType.SQLType; @@ -125,16 +141,16 @@ public void CreateSimpleTable_VarcharTypeCorrect(DatabaseType type) switch (type) { case DatabaseType.MicrosoftSQLServer: - Assert.AreEqual("varchar(5)",dbType); + Assert.That(dbType, Is.EqualTo("varchar(5)")); break; case DatabaseType.MySql: - Assert.AreEqual("varchar(5)",dbType); + Assert.That(dbType, Is.EqualTo("varchar(5)")); break; case DatabaseType.Oracle: - Assert.AreEqual("varchar2(5)",dbType); + Assert.That(dbType, Is.EqualTo("varchar2(5)")); break; case DatabaseType.PostgreSql: - Assert.AreEqual("character varying(5)",dbType); + Assert.That(dbType, Is.EqualTo("character varying(5)")); break; default: throw new ArgumentOutOfRangeException(nameof(type)); @@ -143,7 +159,7 @@ public void CreateSimpleTable_VarcharTypeCorrect(DatabaseType type) table.Drop(); - Assert.IsFalse(table.Exists()); + Assert.That(table.Exists(), Is.False); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -158,7 +174,7 @@ public void CreateTable_PrimaryKey_FromDataTable(DatabaseType databaseType) var table = database.CreateTable("PkTable", dt); - Assert.IsTrue(table.DiscoverColumn("Name").IsPrimaryKey); + Assert.That(table.DiscoverColumn("Name").IsPrimaryKey); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -176,7 +192,7 @@ public void CreateTable_PrimaryKey_FromColumnRequest(DatabaseType databaseType) } }); - Assert.IsTrue(table.DiscoverColumn("Name").IsPrimaryKey); + Assert.That(table.DiscoverColumn("Name").IsPrimaryKey); table.Drop(); } @@ -198,7 +214,7 @@ public void CreateTable_CollationTest(DatabaseType type, string collation) } }); - Assert.AreEqual(collation, tbl.DiscoverColumn("Name").Collation); + Assert.That(tbl.DiscoverColumn("Name").Collation, Is.EqualTo(collation)); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -212,18 +228,21 @@ public void CreateTable_BoolStrings(DatabaseType type) var tbl = db.CreateTable("MyTable", dt); - Assert.AreEqual(1,tbl.GetRowCount()); - - /*if (type == DatabaseType.Oracle) + Assert.Multiple(() => { - //Oracle doesn't have a bit datatype - Assert.AreEqual(typeof(string), tbl.DiscoverColumn("MyBoolCol").GetGuesser().Guess.CSharpType); - Assert.AreEqual("true", tbl.GetDataTable().Rows[0][0]); - return; - }*/ - - Assert.AreEqual(typeof(bool),tbl.DiscoverColumn("MyBoolCol").GetGuesser().Guess.CSharpType); - Assert.AreEqual(true,tbl.GetDataTable().Rows[0][0]); + Assert.That(tbl.GetRowCount(), Is.EqualTo(1)); + + /*if (type == DatabaseType.Oracle) + { + //Oracle doesn't have a bit datatype + Assert.AreEqual(typeof(string), tbl.DiscoverColumn("MyBoolCol").GetGuesser().Guess.CSharpType); + Assert.AreEqual("true", tbl.GetDataTable().Rows[0][0]); + return; + }*/ + + Assert.That(tbl.DiscoverColumn("MyBoolCol").GetGuesser().Guess.CSharpType, Is.EqualTo(typeof(bool))); + Assert.That(tbl.GetDataTable().Rows[0][0], Is.EqualTo(true)); + }); } [Test] @@ -239,12 +258,12 @@ public void OracleRaceCondition() new DatabaseColumnRequest("D", "int"), new DatabaseColumnRequest("E", "int") }); - - Assert.AreEqual(5,tbl.GetDataTable().Columns.Count); + + Assert.That(tbl.GetDataTable().Columns, Has.Count.EqualTo(5)); tbl.DropColumn(tbl.DiscoverColumn("E")); - Assert.AreEqual(4, tbl.GetDataTable().Columns.Count); + Assert.That(tbl.GetDataTable().Columns, Has.Count.EqualTo(4)); tbl.Drop(); } @@ -261,11 +280,11 @@ public void Test_DropColumn(DatabaseType dbType) }); - Assert.AreEqual(2,tbl.GetDataTable().Columns.Count); + Assert.That(tbl.GetDataTable().Columns, Has.Count.EqualTo(2)); tbl.DropColumn(tbl.DiscoverColumn("B")); - Assert.AreEqual(1, tbl.GetDataTable().Columns.Count); + Assert.That(tbl.GetDataTable().Columns, Has.Count.EqualTo(1)); tbl.Drop(); } @@ -281,7 +300,7 @@ public void Test_OracleBit_IsNotStringAnyMore() }); var col = table.DiscoverColumn("MyCol"); - Assert.AreEqual("decimal(1,0)", col.DataType.SQLType); + Assert.That(col.DataType.SQLType, Is.EqualTo("decimal(1,0)")); } @@ -310,16 +329,16 @@ public void Test_CreateTable_UnicodeStrings(DatabaseType type,string testString) //value fetched from database should match the one inserted var dbValue = (string) table.GetDataTable().Rows[0][0]; - Assert.AreEqual(testString,dbValue); + Assert.That(dbValue, Is.EqualTo(testString)); table.Drop(); //column created should know it is unicode var typeRequest = col.Table.GetQuerySyntaxHelper().TypeTranslater.GetDataTypeRequestForSQLDBType(col.DataType.SQLType); - Assert.IsTrue(typeRequest.Unicode, "Expected column DatabaseTypeRequest generated from column SQLType to be Unicode"); + Assert.That(typeRequest.Unicode, "Expected column DatabaseTypeRequest generated from column SQLType to be Unicode"); //Column created should use unicode when creating a new datatype computer from the col var comp = col.GetGuesser(); - Assert.IsTrue(comp.Guess.Unicode); + Assert.That(comp.Guess.Unicode); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -333,21 +352,24 @@ public void Test_CreateTable_UnicodeNames(DatabaseType dbType) var table = db.CreateTable("你好", dt); - Assert.IsTrue(table.Exists()); - Assert.AreEqual("你好",table.GetRuntimeName()); + Assert.Multiple(() => + { + Assert.That(table.Exists()); + Assert.That(table.GetRuntimeName(), Is.EqualTo("你好")); - Assert.IsTrue(db.ExpectTable("你好").Exists()); + Assert.That(db.ExpectTable("你好").Exists()); + }); var col = table.DiscoverColumn("微笑"); - Assert.AreEqual("微笑", col.GetRuntimeName()); + Assert.That(col.GetRuntimeName(), Is.EqualTo("微笑")); table.Insert(new Dictionary {{ "微笑","10" } }); - Assert.AreEqual(2, table.GetRowCount()); + Assert.That(table.GetRowCount(), Is.EqualTo(2)); table.Insert(new Dictionary {{ col,"11" } }); - Assert.AreEqual(3,table.GetRowCount()); + Assert.That(table.GetRowCount(), Is.EqualTo(3)); using var dt2 = new DataTable(); dt2.Columns.Add("微笑"); @@ -356,7 +378,7 @@ public void Test_CreateTable_UnicodeNames(DatabaseType dbType) using(var bulk = table.BeginBulkInsert()) bulk.Upload(dt2); - Assert.AreEqual(4,table.GetRowCount()); + Assert.That(table.GetRowCount(), Is.EqualTo(4)); } [TestCase(DatabaseType.MicrosoftSQLServer)] @@ -374,11 +396,11 @@ public void Test_CreateTable_TF(DatabaseType dbType) var tbl = db.CreateTable("T1", dt); - Assert.AreEqual(typeof(bool), tbl.DiscoverColumn("Hb").DataType.GetCSharpDataType()); + Assert.That(tbl.DiscoverColumn("Hb").DataType.GetCSharpDataType(), Is.EqualTo(typeof(bool))); var dt2 = tbl.GetDataTable(); - Assert.Contains(true, dt2.Rows.Cast().Select(c => c[0]).ToArray()); - Assert.Contains(false, dt2.Rows.Cast().Select(c => c[0]).ToArray()); + Assert.That(dt2.Rows.Cast().Select(c => c[0]).ToArray(), Does.Contain(true)); + Assert.That(dt2.Rows.Cast().Select(c => c[0]).ToArray(), Does.Contain(false)); tbl.Drop(); } @@ -398,11 +420,12 @@ public void Test_CreateTable_DoNotRetype(DatabaseType dbType) var tbl = db.CreateTable("T1", dt); - Assert.AreEqual(typeof(string), tbl.DiscoverColumn("Hb").DataType.GetCSharpDataType()); + Assert.That(tbl.DiscoverColumn("Hb").DataType.GetCSharpDataType(), Is.EqualTo(typeof(string))); var dt2 = tbl.GetDataTable(); - Assert.Contains("T", dt2.Rows.Cast().Select(c => c[0]).ToArray()); - Assert.Contains("F", dt2.Rows.Cast().Select(c => c[0]).ToArray()); + var values = dt2.Rows.Cast().Select(static c => (string)c[0]).ToArray(); + Assert.That(values, Does.Contain("T")); + Assert.That(values, Does.Contain("F")); tbl.Drop(); } @@ -417,12 +440,12 @@ public void Test_DataTableClone_ExtendedProperties() dt.Columns.Add("C1"); //the default Type for a DataColumn is string - Assert.AreEqual(typeof(string),dt.Columns[0].DataType); + Assert.That(dt.Columns[0].DataType, Is.EqualTo(typeof(string))); dt.Columns["C1"]?.ExtendedProperties.Add("ff",true); var dt2 = dt.Clone(); - Assert.IsTrue(dt2.Columns["C1"]?.ExtendedProperties.ContainsKey("ff")); + Assert.That(dt2.Columns["C1"]?.ExtendedProperties.ContainsKey("ff")??false); } [Test] @@ -434,12 +457,12 @@ public void Test_GetDoNotRetype_OnlyStringColumns() dt.SetDoNotReType(true); //do not retype only applies when it is a string - Assert.IsFalse(dt.Columns[0].GetDoNotReType()); + Assert.That(dt.Columns[0].GetDoNotReType(), Is.False); dt.Columns[0].DataType = typeof(string); //change it to a string and it applies - Assert.IsTrue(dt.Columns[0].GetDoNotReType()); + Assert.That(dt.Columns[0].GetDoNotReType()); } /// @@ -486,8 +509,11 @@ public void CreateTable_GuessSettings_StaticDefaults_TF(DatabaseType dbType, boo var tbl = db.CreateTable("T1", dt); var col = tbl.DiscoverColumn("Hb"); - Assert.AreEqual(treatAsBoolean ? typeof(bool): typeof(string),col.DataType.GetCSharpDataType()); - Assert.AreEqual(treatAsBoolean ? -1: 1,col.DataType.GetLengthIfString(),"Expected string length to be 1 for 'T'"); + Assert.Multiple(() => + { + Assert.That(col.DataType.GetCSharpDataType(), Is.EqualTo(treatAsBoolean ? typeof(bool) : typeof(string))); + Assert.That(col.DataType.GetLengthIfString(), Is.EqualTo(treatAsBoolean ? -1 : 1), "Expected string length to be 1 for 'T'"); + }); } finally { @@ -517,12 +543,15 @@ public void TestSomething(DatabaseType dbType) }); - Assert.IsTrue(tbl.Exists()); + Assert.Multiple(() => + { + Assert.That(tbl.Exists()); - Assert.AreEqual(typeof(int),tbl.DiscoverColumn("cint").DataType.GetCSharpDataType()); - Assert.AreEqual(typeof(long),tbl.DiscoverColumn("clong").DataType.GetCSharpDataType()); - Assert.AreEqual(typeof(short),tbl.DiscoverColumn("cshort").DataType.GetCSharpDataType()); - Assert.AreEqual(typeof(string),tbl.DiscoverColumn("script_name").DataType.GetCSharpDataType()); + Assert.That(tbl.DiscoverColumn("cint").DataType.GetCSharpDataType(), Is.EqualTo(typeof(int))); + Assert.That(tbl.DiscoverColumn("clong").DataType.GetCSharpDataType(), Is.EqualTo(typeof(long))); + Assert.That(tbl.DiscoverColumn("cshort").DataType.GetCSharpDataType(), Is.EqualTo(typeof(short))); + Assert.That(tbl.DiscoverColumn("script_name").DataType.GetCSharpDataType(), Is.EqualTo(typeof(string))); + }); tbl.Drop(); } @@ -542,8 +571,11 @@ public void CreateTable_GuessSettings_InArgs_TF(DatabaseType dbType, bool treatA dt.Rows.Add("F"); var args = new CreateTableArgs(db,"Hb",null,dt,false); - Assert.AreEqual(args.GuessSettings.CharCanBeBoolean, GuessSettingsFactory.Defaults.CharCanBeBoolean,"Default should match the static default"); - Assert.IsFalse(args.GuessSettings == GuessSettingsFactory.Defaults,"Args should not be the same instance! otherwise we would unintentionally edit the defaults!"); + Assert.Multiple(() => + { + Assert.That(GuessSettingsFactory.Defaults.CharCanBeBoolean, Is.EqualTo(args.GuessSettings.CharCanBeBoolean), "Default should match the static default"); + Assert.That(!ReferenceEquals(args.GuessSettings, GuessSettingsFactory.Defaults), "Args should not be the same instance! otherwise we would unintentionally edit the defaults!"); + }); //change the args settings args.GuessSettings.CharCanBeBoolean = treatAsBoolean; @@ -551,8 +583,11 @@ public void CreateTable_GuessSettings_InArgs_TF(DatabaseType dbType, bool treatA var tbl = db.CreateTable(args); var col = tbl.DiscoverColumn("Hb"); - Assert.AreEqual(treatAsBoolean ? typeof(bool): typeof(string),col.DataType.GetCSharpDataType()); - Assert.AreEqual(treatAsBoolean ? -1: 1,col.DataType.GetLengthIfString(),"Expected string length to be 1 for 'T'"); + Assert.Multiple(() => + { + Assert.That(col.DataType.GetCSharpDataType(), Is.EqualTo(treatAsBoolean ? typeof(bool) : typeof(string))); + Assert.That(col.DataType.GetLengthIfString(), Is.EqualTo(treatAsBoolean ? -1 : 1), "Expected string length to be 1 for 'T'"); + }); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypesWithBoolFlags))] @@ -565,24 +600,27 @@ public void CreateTable_GuessSettings_ExplicitDateTimeFormat(DatabaseType dbType dt.Rows.Add("013020"); var args = new CreateTableArgs(db,"Hb",null,dt,false); - Assert.AreEqual(args.GuessSettings.ExplicitDateFormats, GuessSettingsFactory.Defaults.ExplicitDateFormats,"Default should match the static default"); - Assert.IsFalse(args.GuessSettings == GuessSettingsFactory.Defaults,"Args should not be the same instance! otherwise we would unintentionally edit the defaults!"); + Assert.Multiple(() => + { + Assert.That(GuessSettingsFactory.Defaults.ExplicitDateFormats, Is.EqualTo(args.GuessSettings.ExplicitDateFormats), "Default should match the static default"); + Assert.That(!ReferenceEquals(args.GuessSettings, GuessSettingsFactory.Defaults), "Args should not be the same instance! otherwise we would unintentionally edit the defaults!"); + }); //change the args settings to treat this date format - args.GuessSettings.ExplicitDateFormats = useCustomDate ? new[]{"MMddyy" } :null; + args.GuessSettings.ExplicitDateFormats = useCustomDate ? ["MMddyy"] :null; var tbl = db.CreateTable(args); var col = tbl.DiscoverColumn("DateCol"); - Assert.AreEqual(useCustomDate ? typeof(DateTime): typeof(string),col.DataType.GetCSharpDataType()); + Assert.That(col.DataType.GetCSharpDataType(), Is.EqualTo(useCustomDate ? typeof(DateTime): typeof(string))); var dtDown = tbl.GetDataTable(); - Assert.AreEqual(useCustomDate? new DateTime(2020,01,30): "013020" ,dtDown.Rows[0][0]); + Assert.That(dtDown.Rows[0][0], Is.EqualTo(useCustomDate ? new DateTime(2020,01,30): "013020")); } [Test] public void GuessSettings_CopyProperties() { var props = typeof(GuessSettings).GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty).Select(p => p.Name).ToArray(); - Assert.AreEqual(2,props.Length,"There are new settable Properties in GuessSettings, we should copy them across in DiscoveredDatabaseHelper.CreateTable"); + Assert.That(props, Has.Length.EqualTo(2), "There are new settable Properties in GuessSettings, we should copy them across in DiscoveredDatabaseHelper.CreateTable"); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/Table/DataTypeAdjusterTests.cs b/Tests/FAnsiTests/Table/DataTypeAdjusterTests.cs index 3d22c63a..550ce76d 100644 --- a/Tests/FAnsiTests/Table/DataTypeAdjusterTests.cs +++ b/Tests/FAnsiTests/Table/DataTypeAdjusterTests.cs @@ -17,7 +17,7 @@ public void CreateTable_WithAdjuster(DatabaseType type) new DatabaseColumnRequest("Name", new DatabaseTypeRequest(typeof (string), 10)) }, null, new DataTypeAdjusterTestsPadder()); - Assert.AreEqual(12,tbl.DiscoverColumn("Name").DataType.GetLengthIfString()); + Assert.That(tbl.DiscoverColumn("Name").DataType.GetLengthIfString(), Is.EqualTo(12)); tbl.Drop(); } diff --git a/Tests/FAnsiTests/Table/ForeignKeyTests.cs b/Tests/FAnsiTests/Table/ForeignKeyTests.cs index e83d846d..73555243 100644 --- a/Tests/FAnsiTests/Table/ForeignKeyTests.cs +++ b/Tests/FAnsiTests/Table/ForeignKeyTests.cs @@ -4,6 +4,7 @@ using FAnsi.Discovery; using FAnsi.Discovery.Constraints; using NUnit.Framework; +using NUnit.Framework.Legacy; using TypeGuesser; namespace FAnsiTests.Table; @@ -43,28 +44,40 @@ public void TestForeignKey_OneColumnKey(DatabaseType dbType, bool cascade) var relationships = parentTable.DiscoverRelationships(); - Assert.AreEqual(1,relationships.Length); + Assert.That(relationships, Has.Length.EqualTo(1)); - Assert.AreEqual(parentTable,relationships[0].PrimaryKeyTable); - Assert.AreEqual(childTable,relationships[0].ForeignKeyTable); - Assert.AreEqual(1,relationships[0].Keys.Count); + Assert.Multiple(() => + { + Assert.That(relationships[0].PrimaryKeyTable, Is.EqualTo(parentTable)); + Assert.That(relationships[0].ForeignKeyTable, Is.EqualTo(childTable)); + Assert.That(relationships[0].Keys, Has.Count.EqualTo(1)); + }); - Assert.AreEqual(parentTable.DiscoverColumns().Single(),relationships[0].Keys.Keys.Single()); - Assert.AreEqual(discovered_fkCol, relationships[0].Keys.Values.Single()); + Assert.Multiple(() => + { + Assert.That(relationships[0].Keys.Keys.Single(), Is.EqualTo(parentTable.DiscoverColumns().Single())); + Assert.That(relationships[0].Keys.Values.Single(), Is.EqualTo(discovered_fkCol)); - Assert.AreEqual(parentTable.DiscoverColumns().Single(), discovered_pkCol); + Assert.That(discovered_pkCol, Is.EqualTo(parentTable.DiscoverColumns().Single())); - Assert.AreEqual(relationships[0].Keys[discovered_pkCol],discovered_fkCol); + Assert.That(discovered_fkCol, Is.EqualTo(relationships[0].Keys[discovered_pkCol])); - Assert.AreEqual(cascade ? CascadeRule.Delete:CascadeRule.NoAction,relationships[0].CascadeDelete); + Assert.That(relationships[0].CascadeDelete, Is.EqualTo(cascade ? CascadeRule.Delete : CascadeRule.NoAction)); + }); var sort1 = new RelationshipTopologicalSort(new[] {childTable, parentTable}); - Assert.AreEqual(sort1.Order[0],parentTable); - Assert.AreEqual(sort1.Order[1],childTable); + Assert.Multiple(() => + { + Assert.That(parentTable, Is.EqualTo(sort1.Order[0])); + Assert.That(childTable, Is.EqualTo(sort1.Order[1])); + }); var sort2 = new RelationshipTopologicalSort(new[] { parentTable,childTable}); - Assert.AreEqual(sort2.Order[0], parentTable); - Assert.AreEqual(sort2.Order[1], childTable); + Assert.Multiple(() => + { + Assert.That(parentTable, Is.EqualTo(sort2.Order[0])); + Assert.That(childTable, Is.EqualTo(sort2.Order[1])); + }); childTable.Drop(); parentTable.Drop(); @@ -111,16 +124,22 @@ public void TestForeignKey_TwoColumnKey(DatabaseType dbType) var relationships = parentTable.DiscoverRelationships(); - Assert.AreEqual(1, relationships.Length); + Assert.That(relationships, Has.Length.EqualTo(1)); - Assert.AreEqual(parentTable, relationships[0].PrimaryKeyTable); - Assert.AreEqual(childTable, relationships[0].ForeignKeyTable); + Assert.Multiple(() => + { + Assert.That(relationships[0].PrimaryKeyTable, Is.EqualTo(parentTable)); + Assert.That(relationships[0].ForeignKeyTable, Is.EqualTo(childTable)); - //should be a composite key of Id1 => Parent_Id1 && Id2 => Parent_Id2 - Assert.AreEqual(2, relationships[0].Keys.Count); + //should be a composite key of Id1 => Parent_Id1 && Id2 => Parent_Id2 + Assert.That(relationships[0].Keys, Has.Count.EqualTo(2)); + }); - Assert.AreEqual(discovered_fkCol1, relationships[0].Keys[discovered_pkCol1]); - Assert.AreEqual(discovered_fkCol2, relationships[0].Keys[discovered_pkCol2]); + Assert.Multiple(() => + { + Assert.That(relationships[0].Keys[discovered_pkCol1], Is.EqualTo(discovered_fkCol1)); + Assert.That(relationships[0].Keys[discovered_pkCol2], Is.EqualTo(discovered_fkCol2)); + }); childTable.Drop(); parentTable.Drop(); @@ -173,11 +192,11 @@ public void Test_ThreeTables_OnePrimary(DatabaseType dbType, bool useTransaction constraint2 = t1.AddForeignKey(c3,c1,true,"FK_Lol"); } - - - - Assert.IsNotNull(constraint1); - Assert.IsNotNull(constraint2); + Assert.Multiple(() => + { + Assert.That(constraint1, Is.Not.Null); + Assert.That(constraint2, Is.Not.Null); + }); StringAssert.AreEqualIgnoringCase("FK_T2_T1",constraint1.Name); StringAssert.AreEqualIgnoringCase("FK_Lol",constraint2.Name); @@ -185,9 +204,9 @@ public void Test_ThreeTables_OnePrimary(DatabaseType dbType, bool useTransaction var sort2 = new RelationshipTopologicalSort(new[] { t1,t2,t3 }); - Assert.Contains(t1, sort2.Order.ToList()); - Assert.Contains(t2, sort2.Order.ToList()); - Assert.Contains(t3, sort2.Order.ToList()); + Assert.That(sort2.Order.ToList(), Does.Contain(t1)); + Assert.That(sort2.Order.ToList(), Does.Contain(t2)); + Assert.That(sort2.Order.ToList(), Does.Contain(t3)); } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] @@ -224,14 +243,17 @@ public void Test_ThreeTables_TwoPrimary(DatabaseType dbType) var constraint1 = t1.AddForeignKey(c3,c1,true); var constraint2 = t1.AddForeignKey(c3,c2,true); - Assert.IsNotNull(constraint1); - Assert.IsNotNull(constraint2); + Assert.Multiple(() => + { + Assert.That(constraint1, Is.Not.Null); + Assert.That(constraint2, Is.Not.Null); + }); var sort2 = new RelationshipTopologicalSort(new[] { t1,t2,t3 }); - Assert.Contains(t1, sort2.Order.ToList()); - Assert.Contains(t2, sort2.Order.ToList()); - Assert.Contains(t3, sort2.Order.ToList()); + Assert.That(sort2.Order.ToList(), Does.Contain(t1)); + Assert.That(sort2.Order.ToList(), Does.Contain(t2)); + Assert.That(sort2.Order.ToList(), Does.Contain(t3)); } [Test] @@ -244,12 +266,15 @@ public void Test_RelationshipTopologicalSort_UnrelatedTables() var lawyers = db.CreateTable("Lawyers", new[] { new DatabaseColumnRequest("Name", new DatabaseTypeRequest(typeof(string), 100)) }); var sort = new RelationshipTopologicalSort(new[] {cops}); - Assert.AreEqual(cops,sort.Order.Single()); + Assert.That(sort.Order.Single(), Is.EqualTo(cops)); var sort2 = new RelationshipTopologicalSort(new[] { cops,robbers,lawyers }); - Assert.AreEqual(cops, sort2.Order[0]); - Assert.AreEqual(robbers, sort2.Order[1]); - Assert.AreEqual(lawyers, sort2.Order[2]); + Assert.Multiple(() => + { + Assert.That(sort2.Order[0], Is.EqualTo(cops)); + Assert.That(sort2.Order[1], Is.EqualTo(robbers)); + Assert.That(sort2.Order[2], Is.EqualTo(lawyers)); + }); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/Table/LongNamesTests.cs b/Tests/FAnsiTests/Table/LongNamesTests.cs index 841d5115..7f4acd39 100644 --- a/Tests/FAnsiTests/Table/LongNamesTests.cs +++ b/Tests/FAnsiTests/Table/LongNamesTests.cs @@ -2,6 +2,7 @@ using FAnsi; using FAnsi.Discovery; using NUnit.Framework; +using NUnit.Framework.Legacy; using TypeGuesser; namespace FAnsiTests.Table; @@ -18,11 +19,11 @@ public void Test_LongTableName_CreateAndReadBack(DatabaseType dbType) var tbl = db.CreateTable(tableName,new DatabaseColumnRequest[]{new(columnName,new DatabaseTypeRequest(typeof(string),100))}); - Assert.IsTrue(tbl.Exists()); + Assert.That(tbl.Exists()); StringAssert.AreEqualIgnoringCase(tableName,tbl.GetRuntimeName()); var col = tbl.DiscoverColumn(columnName); - Assert.IsNotNull(col); + Assert.That(col, Is.Not.Null); StringAssert.AreEqualIgnoringCase(columnName,col.GetRuntimeName()); } @@ -41,7 +42,7 @@ public void Test_LongDatabaseNames_CreateAndReadBack(DatabaseType dbType) var db2 = db.Server.ExpectDatabase(sb.ToString()); db2.Create(true); - Assert.IsTrue(db2.Exists()); + Assert.That(db2.Exists()); StringAssert.AreEqualIgnoringCase(sb.ToString(),db2.GetRuntimeName()); db2.Drop(); diff --git a/Tests/FAnsiTests/Table/TableTypeTests.cs b/Tests/FAnsiTests/Table/TableTypeTests.cs index c5d8409f..1d626e28 100644 --- a/Tests/FAnsiTests/Table/TableTypeTests.cs +++ b/Tests/FAnsiTests/Table/TableTypeTests.cs @@ -20,7 +20,7 @@ public void CreateView(DatabaseType dbType) tbl = db.CreateTable("MyTable",dt); } - Assert.AreEqual(TableType.Table, tbl.TableType); + Assert.That(tbl.TableType, Is.EqualTo(TableType.Table)); var viewName = "MyView"; @@ -50,22 +50,25 @@ public void CreateView(DatabaseType dbType) //if we expect it to be a table var view = tbl.Database.ExpectTable("MyView"); - Assert.IsFalse(view.Exists()); //we should be wrong + Assert.That(view.Exists(), Is.False); //we should be wrong //if we expect it to be a view view = tbl.Database.ExpectTable("MyView",null,TableType.View); - Assert.AreEqual(1,view.DiscoverColumns().Length); + Assert.Multiple(() => + { + Assert.That(view.DiscoverColumns(), Has.Length.EqualTo(1)); - //we would be right! - Assert.IsTrue(view.Exists()); - Assert.AreEqual(TableType.View,view.TableType); + //we would be right! + Assert.That(view.Exists()); + Assert.That(view.TableType, Is.EqualTo(TableType.View)); + }); view.Drop(); - Assert.IsFalse(view.Exists()); + Assert.That(view.Exists(), Is.False); var ex = Assert.Throws(()=>view.Rename("Lolz")); - Assert.AreEqual("Rename is not supported for TableType View", ex?.Message); + Assert.That(ex?.Message, Is.EqualTo("Rename is not supported for TableType View")); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/Table/TableValuedFunctionTests.cs b/Tests/FAnsiTests/Table/TableValuedFunctionTests.cs index dea244e7..bf26a26c 100644 --- a/Tests/FAnsiTests/Table/TableValuedFunctionTests.cs +++ b/Tests/FAnsiTests/Table/TableValuedFunctionTests.cs @@ -1,6 +1,7 @@ using System.Linq; using FAnsi; using NUnit.Framework; +using NUnit.Framework.Legacy; namespace FAnsiTests.Table; @@ -58,17 +59,20 @@ Name varchar(50) var tvf = db.DiscoverTableValuedFunctions().Single(); var p = tvf.DiscoverParameters().First(); - Assert.AreEqual("@startNumber",p.ParameterName); - Assert.AreEqual("int",p.DataType.SQLType); - Assert.AreEqual(schema,tvf.Schema??"dbo"); + Assert.Multiple(() => + { + Assert.That(p.ParameterName, Is.EqualTo("@startNumber")); + Assert.That(p.DataType.SQLType, Is.EqualTo("int")); + Assert.That(tvf.Schema ?? "dbo", Is.EqualTo(schema)); + }); StringAssert.EndsWith(".MyAwesomeFunction(@startNumber,@stopNumber,@name)",tvf.GetFullyQualifiedName()); - Assert.IsTrue(tvf.Exists()); + Assert.That(tvf.Exists()); tvf.Drop(); - Assert.IsFalse(tvf.Exists()); + Assert.That(tvf.Exists(), Is.False); } diff --git a/Tests/FAnsiTests/Table/TestRename.cs b/Tests/FAnsiTests/Table/TestRename.cs index 1d16b91f..032553c0 100644 --- a/Tests/FAnsiTests/Table/TestRename.cs +++ b/Tests/FAnsiTests/Table/TestRename.cs @@ -14,18 +14,21 @@ public void TestRenamingTable(DatabaseType type) var tbl = db.CreateTable("MyTable",new []{new DatabaseColumnRequest("Age",new DatabaseTypeRequest(typeof(int)) )}); - Assert.IsTrue(tbl.Exists()); + Assert.That(tbl.Exists()); var tbl2 = db.ExpectTable("MYTABLE2"); - Assert.IsFalse(tbl2.Exists()); + Assert.That(tbl2.Exists(), Is.False); tbl.Rename("MYTABLE2"); - Assert.IsTrue(tbl.Exists()); - Assert.IsTrue(tbl2.Exists()); + Assert.Multiple(() => + { + Assert.That(tbl.Exists()); + Assert.That(tbl2.Exists()); - Assert.AreEqual("MYTABLE2",tbl.GetRuntimeName()); - Assert.AreEqual("MYTABLE2",tbl2.GetRuntimeName()); + Assert.That(tbl.GetRuntimeName(), Is.EqualTo("MYTABLE2")); + Assert.That(tbl2.GetRuntimeName(), Is.EqualTo("MYTABLE2")); + }); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/Table/TopXTests.cs b/Tests/FAnsiTests/Table/TopXTests.cs index 0566ff30..6f7bb921 100644 --- a/Tests/FAnsiTests/Table/TopXTests.cs +++ b/Tests/FAnsiTests/Table/TopXTests.cs @@ -44,12 +44,12 @@ public void Test_TopX_OrderBy(DatabaseType type,bool asc) using(var con = db.Server.GetConnection()) { con.Open(); - Assert.AreEqual(asc?1:4,db.Server.GetCommand(sql,con).ExecuteScalar()); + Assert.That(db.Server.GetCommand(sql,con).ExecuteScalar(), Is.EqualTo(asc ?1:4)); } var dtTopX = tbl.GetDataTable(1); - Assert.AreEqual(1,dtTopX.Rows.Count); - Assert.AreEqual(1,dtTopX.Rows[0]["F"]); + Assert.That(dtTopX.Rows, Has.Count.EqualTo(1)); + Assert.That(dtTopX.Rows[0]["F"], Is.EqualTo(1)); using(var con = db.Server.GetConnection()) @@ -57,11 +57,11 @@ public void Test_TopX_OrderBy(DatabaseType type,bool asc) con.Open(); var sqlcol = tbl.DiscoverColumn("X").GetTopXSql(1,false); - Assert.AreEqual(DBNull.Value,db.Server.GetCommand(sqlcol,con).ExecuteScalar()); + Assert.That(db.Server.GetCommand(sqlcol,con).ExecuteScalar(), Is.EqualTo(DBNull.Value)); sqlcol = tbl.DiscoverColumn("X").GetTopXSql(1,true); - Assert.AreEqual("fish",db.Server.GetCommand(sqlcol,con).ExecuteScalar()); + Assert.That(db.Server.GetCommand(sqlcol,con).ExecuteScalar(), Is.EqualTo("fish")); } } } \ No newline at end of file diff --git a/Tests/FAnsiTests/Table/UpdateTests.cs b/Tests/FAnsiTests/Table/UpdateTests.cs index 658d44a7..d394c3cb 100644 --- a/Tests/FAnsiTests/Table/UpdateTests.cs +++ b/Tests/FAnsiTests/Table/UpdateTests.cs @@ -64,15 +64,15 @@ public void Test_UpdateTableFromJoin(DatabaseType dbType) var cmd = db.Server.GetCommand(sql, con); var affectedRows = cmd.ExecuteNonQuery(); - Assert.AreEqual(1,affectedRows); + Assert.That(affectedRows, Is.EqualTo(1)); //Frank should have got a new high score of 900 cmd = db.Server.GetCommand($"SELECT {highScore} from {tbl1.GetFullyQualifiedName()} WHERE {name} = 'Frank'", con); - Assert.AreEqual(900,cmd.ExecuteScalar()); + Assert.That(cmd.ExecuteScalar(), Is.EqualTo(900)); //Dave should have his old score of 100 cmd = db.Server.GetCommand($"SELECT {highScore} from {tbl1.GetFullyQualifiedName()} WHERE {name} = 'Dave'", con); - Assert.AreEqual(100, cmd.ExecuteScalar()); + Assert.That(cmd.ExecuteScalar(), Is.EqualTo(100)); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/TypeTranslation/DatabaseTypeRequestTests.cs b/Tests/FAnsiTests/TypeTranslation/DatabaseTypeRequestTests.cs index 7ab381cf..425d0f41 100644 --- a/Tests/FAnsiTests/TypeTranslation/DatabaseTypeRequestTests.cs +++ b/Tests/FAnsiTests/TypeTranslation/DatabaseTypeRequestTests.cs @@ -14,7 +14,10 @@ public void Test_Max_WithUnicode() new DatabaseTypeRequest(typeof(string), 2) ); - Assert.AreEqual(2,max.Width); - Assert.IsTrue(max.Unicode,"If either arg in a Max call is Unicode then the resulting maximum should be Unicode=true"); + Assert.Multiple(() => + { + Assert.That(max.Width, Is.EqualTo(2)); + Assert.That(max.Unicode, "If either arg in a Max call is Unicode then the resulting maximum should be Unicode=true"); + }); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/TypeTranslation/DatatypeComputerTests.cs b/Tests/FAnsiTests/TypeTranslation/DatatypeComputerTests.cs index 1866ba55..5c0c7b74 100644 --- a/Tests/FAnsiTests/TypeTranslation/DatatypeComputerTests.cs +++ b/Tests/FAnsiTests/TypeTranslation/DatatypeComputerTests.cs @@ -3,6 +3,7 @@ using FAnsi.Discovery.TypeTranslation; using FAnsi.Implementations.MicrosoftSQL; using NUnit.Framework; +using NUnit.Framework.Legacy; using TypeGuesser; namespace FAnsiTests.TypeTranslation; @@ -23,16 +24,22 @@ public void TestGuesser_IntToFloat() { var t = new Guesser(); t.AdjustToCompensateForValue("12"); - - Assert.AreEqual(typeof(int),t.Guess.CSharpType); - Assert.AreEqual(0, t.Guess.Size.NumbersAfterDecimalPlace); - Assert.AreEqual(2, t.Guess.Size.NumbersBeforeDecimalPlace); + + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(int))); + Assert.That(t.Guess.Size.NumbersAfterDecimalPlace, Is.EqualTo(0)); + Assert.That(t.Guess.Size.NumbersBeforeDecimalPlace, Is.EqualTo(2)); + }); t.AdjustToCompensateForValue("0.1"); - Assert.AreEqual(typeof(decimal), t.Guess.CSharpType); - Assert.AreEqual(1, t.Guess.Size.NumbersAfterDecimalPlace); - Assert.AreEqual(2, t.Guess.Size.NumbersBeforeDecimalPlace); + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(decimal))); + Assert.That(t.Guess.Size.NumbersAfterDecimalPlace, Is.EqualTo(1)); + Assert.That(t.Guess.Size.NumbersBeforeDecimalPlace, Is.EqualTo(2)); + }); } @@ -42,16 +49,22 @@ public void TestGuesser_IntToDate() var t = new Guesser(); t.AdjustToCompensateForValue("12"); - Assert.AreEqual(typeof(int), t.Guess.CSharpType); - Assert.AreEqual(0, t.Guess.Size.NumbersAfterDecimalPlace); - Assert.AreEqual(2, t.Guess.Size.NumbersBeforeDecimalPlace); - Assert.AreEqual(2, t.Guess.Width); + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(int))); + Assert.That(t.Guess.Size.NumbersAfterDecimalPlace, Is.EqualTo(0)); + Assert.That(t.Guess.Size.NumbersBeforeDecimalPlace, Is.EqualTo(2)); + Assert.That(t.Guess.Width, Is.EqualTo(2)); + }); t.AdjustToCompensateForValue("2001-01-01"); - Assert.AreEqual(typeof(string), t.Guess.CSharpType); - Assert.AreEqual(0, t.Guess.Size.NumbersAfterDecimalPlace); - Assert.AreEqual(10, t.Guess.Width); + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(string))); + Assert.That(t.Guess.Size.NumbersAfterDecimalPlace, Is.EqualTo(0)); + Assert.That(t.Guess.Width, Is.EqualTo(10)); + }); } [Test] @@ -63,29 +76,35 @@ public void TestGuesser_decimal() t.AdjustToCompensateForValue(null); t.AdjustToCompensateForValue(DBNull.Value); - Assert.AreEqual(typeof(decimal),t.Guess.CSharpType); + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(decimal))); } [Test] public void TestGuesser_Int() { var t = new Guesser(); - + t.AdjustToCompensateForValue("0"); - Assert.AreEqual(typeof(bool), t.Guess.CSharpType); - Assert.AreEqual(1, t.Guess.Width); + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(bool))); + Assert.That(t.Guess.Width, Is.EqualTo(1)); + }); t.AdjustToCompensateForValue("-0"); - Assert.AreEqual(typeof(int), t.Guess.CSharpType); - Assert.AreEqual(2, t.Guess.Width); - - + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(int))); + Assert.That(t.Guess.Width, Is.EqualTo(2)); + }); + + t.AdjustToCompensateForValue("15"); t.AdjustToCompensateForValue("299"); t.AdjustToCompensateForValue(null); t.AdjustToCompensateForValue(DBNull.Value); - Assert.AreEqual(typeof(int),t.Guess.CSharpType); + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(int))); } @@ -99,16 +118,16 @@ public void TestGuesser_IntAnddecimal_MustUsedecimal() t.AdjustToCompensateForValue(null); t.AdjustToCompensateForValue(DBNull.Value); - Assert.AreEqual(t.Guess.CSharpType, typeof(decimal)); + Assert.That(typeof(decimal), Is.EqualTo(t.Guess.CSharpType)); var sqlType = t.GetSqlDBType(_translater); - Assert.AreEqual("decimal(4,1)",sqlType) ; + Assert.That(sqlType, Is.EqualTo("decimal(4,1)")) ; var orig = t.Guess; var reverseEngineered = _translater.GetDataTypeRequestForSQLDBType(sqlType); - Assert.AreEqual(orig,reverseEngineered ,"The computed DataTypeRequest was not the same after going via sql datatype and reverse engineering"); + Assert.That(reverseEngineered, Is.EqualTo(orig), "The computed DataTypeRequest was not the same after going via sql datatype and reverse engineering"); } [Test] - public void TestGuesser_IntAnddecimal_MustUsedecimalThenString() + public void TestGuesser_IntAndDecimal_MustUseDecimalThenString() { var t = new Guesser(); t.AdjustToCompensateForValue("15"); @@ -116,20 +135,10 @@ public void TestGuesser_IntAnddecimal_MustUsedecimalThenString() t.AdjustToCompensateForValue("200"); t.AdjustToCompensateForValue(null); t.AdjustToCompensateForValue(DBNull.Value); - - Assert.AreEqual("decimal(4,1)", t.GetSqlDBType(_translater)); - t.AdjustToCompensateForValue("D"); - Assert.AreEqual("varchar(5)", t.GetSqlDBType(_translater)); - } - - public void TestGuesser_DateTimeFromInt() - { - var t = new Guesser(); - t.AdjustToCompensateForValue("01/01/2001"); - Assert.AreEqual(typeof(DateTime), t.Guess.CSharpType); - t.AdjustToCompensateForValue("2013"); - Assert.AreEqual(typeof(string), t.Guess.CSharpType); + Assert.That(t.GetSqlDBType(_translater), Is.EqualTo("decimal(4,1)")); + t.AdjustToCompensateForValue("D"); + Assert.That(t.GetSqlDBType(_translater), Is.EqualTo("varchar(5)")); } //Tests system being happy to sign off in the orders bool=>int=>decimal but nothing else @@ -140,11 +149,11 @@ public void TestGuesser_FallbackCompatible(string input1, Type expectedTypeAfter { var t = new Guesser(); t.AdjustToCompensateForValue(input1); - - Assert.AreEqual(expectedTypeAfterFirstInput,t.Guess.CSharpType); - + + Assert.That(t.Guess.CSharpType, Is.EqualTo(expectedTypeAfterFirstInput)); + t.AdjustToCompensateForValue(input2); - Assert.AreEqual(expectedTypeAfterSecondInput, t.Guess.CSharpType); + Assert.That(t.Guess.CSharpType, Is.EqualTo(expectedTypeAfterSecondInput)); } //Tests system being angry at having signed off on a bool=>int=>decimal then seeing a valid non string type (e.g. DateTime) @@ -159,16 +168,16 @@ public void TestGuesser_FallbackIncompatible(string input1, Type expectedTypeAft var t = new Guesser(); t.AdjustToCompensateForValue(input1); - Assert.AreEqual(expectedTypeAfterFirstInput, t.Guess.CSharpType); + Assert.That(t.Guess.CSharpType, Is.EqualTo(expectedTypeAfterFirstInput)); t.AdjustToCompensateForValue(input2); - Assert.AreEqual(typeof(string), t.Guess.CSharpType); + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(string))); //now check it in reverse just to be sure t = new Guesser(); t.AdjustToCompensateForValue(input2); t.AdjustToCompensateForValue(input1); - Assert.AreEqual(typeof(string),t.Guess.CSharpType); + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(string))); } [Test] @@ -177,7 +186,7 @@ public void TestGuesser_IntToDateTime() var t = new Guesser(); t.AdjustToCompensateForValue("2013"); t.AdjustToCompensateForValue("01/01/2001"); - Assert.AreEqual(typeof(string), t.Guess.CSharpType); + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(string))); } [TestCase("fish",32)] @@ -192,9 +201,9 @@ public void TestGuesser_MixingTypes_ThrowsException(object o1, object o2) //...then we don't accept strings anymore var t = new Guesser(); - t.AdjustToCompensateForValue(o1); + t.AdjustToCompensateForValue(o1); - var ex = Assert.Throws(() => t.AdjustToCompensateForValue(o2)); + var ex = Assert.Throws(() => t.AdjustToCompensateForValue(o2)); StringAssert.Contains("mixed with untyped objects",ex?.Message); } @@ -205,8 +214,11 @@ public void TestGuesser_DateTime() t.AdjustToCompensateForValue("01/01/2001"); t.AdjustToCompensateForValue(null); - Assert.AreEqual(t.Guess.CSharpType, typeof(DateTime)); - Assert.AreEqual("datetime2", t.GetSqlDBType(_translater)); + Assert.Multiple(() => + { + Assert.That(typeof(DateTime), Is.EqualTo(t.Guess.CSharpType)); + Assert.That(t.GetSqlDBType(_translater), Is.EqualTo("datetime2")); + }); } [TestCase("1. 01 ", typeof(DateTime))] @@ -215,7 +227,7 @@ public void TestGuesser_DateTime_DodgyFormats(string input, Type expectedOutput) { var t = new Guesser(); t.AdjustToCompensateForValue(input); - Assert.AreEqual(expectedOutput, t.Guess.CSharpType); + Assert.That(t.Guess.CSharpType, Is.EqualTo(expectedOutput)); } [Test] @@ -225,23 +237,29 @@ public void TestGuesser_DateTime_English() t.AdjustToCompensateForValue(GetCultureSpecificDate()); t.AdjustToCompensateForValue(null); - Assert.AreEqual(t.Guess.CSharpType, typeof(DateTime)); - Assert.AreEqual("datetime2", t.GetSqlDBType(_translater)); + Assert.Multiple(() => + { + Assert.That(typeof(DateTime), Is.EqualTo(t.Guess.CSharpType)); + Assert.That(t.GetSqlDBType(_translater), Is.EqualTo("datetime2")); + }); } [Test] public void TestGuesser_DateTime_EnglishWithTime() { var t = new Guesser(); - + Console.WriteLine(CultureInfo.CurrentCulture.EnglishName); TestContext.WriteLine(CultureInfo.CurrentCulture.DateTimeFormat.MonthDayPattern); t.AdjustToCompensateForValue($"{GetCultureSpecificDate()} 11:10"); t.AdjustToCompensateForValue(null); - Assert.AreEqual(t.Guess.CSharpType, typeof(DateTime)); - Assert.AreEqual("datetime2", t.GetSqlDBType(_translater)); + Assert.Multiple(() => + { + Assert.That(typeof(DateTime), Is.EqualTo(t.Guess.CSharpType)); + Assert.That(t.GetSqlDBType(_translater), Is.EqualTo("datetime2")); + }); } private string GetCultureSpecificDate() @@ -264,8 +282,11 @@ public void TestGuesser_DateTime_EnglishWithTimeAndAM() t.AdjustToCompensateForValue($"{GetCultureSpecificDate()} 11:10AM"); t.AdjustToCompensateForValue(null); - Assert.AreEqual(t.Guess.CSharpType, typeof(DateTime)); - Assert.AreEqual("datetime2", t.GetSqlDBType(_translater)); + Assert.Multiple(() => + { + Assert.That(typeof(DateTime), Is.EqualTo(t.Guess.CSharpType)); + Assert.That(t.GetSqlDBType(_translater), Is.EqualTo("datetime2")); + }); } [TestCase("01",2)] @@ -284,8 +305,11 @@ public void TestGuesser_PreeceedingZeroes(string input, int expectedLength) { var t = new Guesser(); t.AdjustToCompensateForValue(input); - Assert.AreEqual(typeof(string), t.Guess.CSharpType); - Assert.AreEqual(expectedLength, t.Guess.Width); + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(string))); + Assert.That(t.Guess.Width, Is.EqualTo(expectedLength)); + }); } [Test] @@ -297,7 +321,7 @@ public void TestGuesser_PreeceedingZeroesAfterFloat() t.AdjustToCompensateForValue(null); t.AdjustToCompensateForValue(DBNull.Value); - Assert.AreEqual(typeof(string), t.Guess.CSharpType); + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(string))); } [Test] public void TestGuesser_Negatives() @@ -306,8 +330,11 @@ public void TestGuesser_Negatives() t.AdjustToCompensateForValue("-1"); t.AdjustToCompensateForValue("-99.99"); - Assert.AreEqual(t.Guess.CSharpType, typeof(decimal)); - Assert.AreEqual("decimal(4,2)", t.GetSqlDBType(_translater)); + Assert.Multiple(() => + { + Assert.That(typeof(decimal), Is.EqualTo(t.Guess.CSharpType)); + Assert.That(t.GetSqlDBType(_translater), Is.EqualTo("decimal(4,2)")); + }); } @@ -316,11 +343,14 @@ public void TestGuesser_Doubles() { var t = new Guesser(); t.AdjustToCompensateForValue(299.99); - - Assert.AreEqual(typeof(double), t.Guess.CSharpType); - Assert.AreEqual(2, t.Guess.Size.NumbersAfterDecimalPlace); - Assert.AreEqual(3, t.Guess.Size.NumbersBeforeDecimalPlace); + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(double))); + + Assert.That(t.Guess.Size.NumbersAfterDecimalPlace, Is.EqualTo(2)); + Assert.That(t.Guess.Size.NumbersBeforeDecimalPlace, Is.EqualTo(3)); + }); } [TestCase(" 1.01", typeof(decimal))] @@ -332,8 +362,11 @@ public void TestGuesser_Whitespace(string input, Type expectedType) var t = new Guesser(); t.AdjustToCompensateForValue(input); - Assert.AreEqual(expectedType, t.Guess.CSharpType); - Assert.AreEqual(input.Length,t.Guess.Width); + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(expectedType)); + Assert.That(t.Guess.Width, Is.EqualTo(input.Length)); + }); } [Test] @@ -347,20 +380,23 @@ public void TestGuesser_Bool(bool sendStringEquiv) t.AdjustToCompensateForValue("True"); else t.AdjustToCompensateForValue(true); - + if (sendStringEquiv) t.AdjustToCompensateForValue("False"); else t.AdjustToCompensateForValue(false); - - Assert.AreEqual(typeof(bool), t.Guess.CSharpType); + + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(bool))); t.AdjustToCompensateForValue(null); - Assert.AreEqual(typeof(bool), t.Guess.CSharpType); + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(bool))); - Assert.AreEqual(0, t.Guess.Size.NumbersAfterDecimalPlace); - Assert.AreEqual(0, t.Guess.Size.NumbersBeforeDecimalPlace); + Assert.That(t.Guess.Size.NumbersAfterDecimalPlace, Is.EqualTo(0)); + Assert.That(t.Guess.Size.NumbersBeforeDecimalPlace, Is.EqualTo(0)); + }); } [Test] @@ -382,11 +418,14 @@ public void TestGuesser_Int16s() t.AdjustToCompensateForValue((short)30); t.AdjustToCompensateForValue((short)200); - Assert.AreEqual(typeof(short), t.Guess.CSharpType); + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(short))); + + Assert.That(t.Guess.Size.NumbersBeforeDecimalPlace, Is.EqualTo(3)); + Assert.That(t.Guess.Size.NumbersAfterDecimalPlace, Is.EqualTo(0)); + }); - Assert.AreEqual(3, t.Guess.Size.NumbersBeforeDecimalPlace); - Assert.AreEqual(0, t.Guess.Size.NumbersAfterDecimalPlace); - } [Test] @@ -395,11 +434,14 @@ public void TestGuesser_Byte() var t = new Guesser(); t.AdjustToCompensateForValue(new byte[5]); - Assert.AreEqual(typeof(byte[]), t.Guess.CSharpType); + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(byte[]))); - Assert.AreEqual(0, t.Guess.Size.NumbersAfterDecimalPlace); - Assert.AreEqual(0, t.Guess.Size.NumbersBeforeDecimalPlace); - Assert.IsTrue(t.Guess.Size.IsEmpty); + Assert.That(t.Guess.Size.NumbersAfterDecimalPlace, Is.EqualTo(0)); + Assert.That(t.Guess.Size.NumbersBeforeDecimalPlace, Is.EqualTo(0)); + Assert.That(t.Guess.Size.IsEmpty); + }); } @@ -409,9 +451,12 @@ public void TestGuesser_NumberOfDecimalPlaces() var t = new Guesser(); t.AdjustToCompensateForValue("111111111.11111111111115"); - Assert.AreEqual(typeof(decimal), t.Guess.CSharpType); - Assert.AreEqual(9, t.Guess.Size.NumbersBeforeDecimalPlace); - Assert.AreEqual(14, t.Guess.Size.NumbersAfterDecimalPlace); + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(decimal))); + Assert.That(t.Guess.Size.NumbersBeforeDecimalPlace, Is.EqualTo(9)); + Assert.That(t.Guess.Size.NumbersAfterDecimalPlace, Is.EqualTo(14)); + }); } @@ -421,16 +466,22 @@ public void TestGuesser_TrailingZeroesFallbackToString() var t = new Guesser(); t.AdjustToCompensateForValue("-111.000"); - Assert.AreEqual(typeof(int), t.Guess.CSharpType); - Assert.AreEqual(3, t.Guess.Size.NumbersBeforeDecimalPlace); + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(int))); + Assert.That(t.Guess.Size.NumbersBeforeDecimalPlace, Is.EqualTo(3)); - //even though they are trailing zeroes we still need this much space... there must be a reason why they are there right? (also makes it easier to go to string later if needed eh!) - Assert.AreEqual(0, t.Guess.Size.NumbersAfterDecimalPlace); + //even though they are trailing zeroes we still need this much space... there must be a reason why they are there right? (also makes it easier to go to string later if needed eh!) + Assert.That(t.Guess.Size.NumbersAfterDecimalPlace, Is.EqualTo(0)); + }); t.AdjustToCompensateForValue("P"); - Assert.AreEqual(typeof(string), t.Guess.CSharpType); - Assert.AreEqual(8, t.Guess.Width); + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(string))); + Assert.That(t.Guess.Width, Is.EqualTo(8)); + }); } [Test] @@ -441,13 +492,13 @@ public void TestGuesser_IntFloatString() var t = new Guesser(); t.AdjustToCompensateForValue("-1000"); - Assert.AreEqual("int",t.GetSqlDBType(tt)); + Assert.That(t.GetSqlDBType(tt), Is.EqualTo("int")); t.AdjustToCompensateForValue("1.1"); - Assert.AreEqual("decimal(5,1)", t.GetSqlDBType(tt)); + Assert.That(t.GetSqlDBType(tt), Is.EqualTo("decimal(5,1)")); t.AdjustToCompensateForValue("A"); - Assert.AreEqual("varchar(6)", t.GetSqlDBType(tt)); + Assert.That(t.GetSqlDBType(tt), Is.EqualTo("varchar(6)")); } [Test] @@ -457,8 +508,11 @@ public void TestGuesser_FallbackOntoVarcharFromFloat() t.AdjustToCompensateForValue("15.5"); t.AdjustToCompensateForValue("F"); - Assert.AreEqual(typeof(string), t.Guess.CSharpType); - Assert.AreEqual("varchar(4)", t.GetSqlDBType(_translater)); + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(string))); + Assert.That(t.GetSqlDBType(_translater), Is.EqualTo("varchar(4)")); + }); } [Test] public void TestGuesser_Time() @@ -466,8 +520,11 @@ public void TestGuesser_Time() var t = new Guesser(); t.AdjustToCompensateForValue("12:30:00"); - Assert.AreEqual(typeof(TimeSpan), t.Guess.CSharpType); - Assert.AreEqual("time", t.GetSqlDBType(_translater)); + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(TimeSpan))); + Assert.That(t.GetSqlDBType(_translater), Is.EqualTo("time")); + }); } [Test] @@ -476,8 +533,11 @@ public void TestGuesser_TimeNoSeconds() var t = new Guesser(); t.AdjustToCompensateForValue("12:01"); - Assert.AreEqual(typeof(TimeSpan), t.Guess.CSharpType); - Assert.AreEqual("time", t.GetSqlDBType(_translater)); + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(TimeSpan))); + Assert.That(t.GetSqlDBType(_translater), Is.EqualTo("time")); + }); } [Test] @@ -486,8 +546,11 @@ public void TestGuesser_TimeWithPM() var t = new Guesser(); t.AdjustToCompensateForValue("1:01PM"); - Assert.AreEqual(typeof(TimeSpan), t.Guess.CSharpType); - Assert.AreEqual("time", t.GetSqlDBType(_translater)); + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(TimeSpan))); + Assert.That(t.GetSqlDBType(_translater), Is.EqualTo("time")); + }); } [Test] public void TestGuesser_24Hour() @@ -495,8 +558,11 @@ public void TestGuesser_24Hour() var t = new Guesser(); t.AdjustToCompensateForValue("23:01"); - Assert.AreEqual(typeof(TimeSpan), t.Guess.CSharpType); - Assert.AreEqual("time", t.GetSqlDBType(_translater)); + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(TimeSpan))); + Assert.That(t.GetSqlDBType(_translater), Is.EqualTo("time")); + }); } [Test] public void TestGuesser_Midnight() @@ -504,8 +570,11 @@ public void TestGuesser_Midnight() var t = new Guesser(); t.AdjustToCompensateForValue("00:00"); - Assert.AreEqual(typeof(TimeSpan), t.Guess.CSharpType); - Assert.AreEqual("time", t.GetSqlDBType(_translater)); + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(TimeSpan))); + Assert.That(t.GetSqlDBType(_translater), Is.EqualTo("time")); + }); } [Test] public void TestGuesser_TimeObject() @@ -513,19 +582,25 @@ public void TestGuesser_TimeObject() var t = new Guesser(); t.AdjustToCompensateForValue(new TimeSpan(10,1,1)); - Assert.AreEqual(typeof(TimeSpan), t.Guess.CSharpType); - Assert.AreEqual("time", t.GetSqlDBType(_translater)); + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(TimeSpan))); + Assert.That(t.GetSqlDBType(_translater), Is.EqualTo("time")); + }); } [Test] public void TestGuesser_MixedDateAndTime_FallbackToString() { var t = new Guesser(); t.AdjustToCompensateForValue("09:01"); - Assert.AreEqual(typeof(TimeSpan), t.Guess.CSharpType); + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(TimeSpan))); t.AdjustToCompensateForValue("2001-12-29 23:01"); - Assert.AreEqual(typeof(string), t.Guess.CSharpType); - Assert.AreEqual("varchar(16)", t.GetSqlDBType(_translater)); + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(string))); + Assert.That(t.GetSqlDBType(_translater), Is.EqualTo("varchar(16)")); + }); } [TestCase("1-1000")] @@ -533,7 +608,7 @@ public void TestGuesser_ValidDateStrings(string wierdDateString) { var t = new Guesser(); t.AdjustToCompensateForValue(wierdDateString); - Assert.AreEqual(typeof(DateTime), t.Guess.CSharpType); + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(DateTime))); } [Test] @@ -544,9 +619,12 @@ public void TestGuesser_HardTypeFloats() t.AdjustToCompensateForValue(100.01f); t.AdjustToCompensateForValue(10000f); - Assert.AreEqual(typeof(float), t.Guess.CSharpType); - Assert.AreEqual(2,t.Guess.Size.NumbersAfterDecimalPlace); - Assert.AreEqual(5, t.Guess.Size.NumbersBeforeDecimalPlace); + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(float))); + Assert.That(t.Guess.Size.NumbersAfterDecimalPlace, Is.EqualTo(2)); + Assert.That(t.Guess.Size.NumbersBeforeDecimalPlace, Is.EqualTo(5)); + }); } [Test] @@ -559,9 +637,12 @@ public void TestGuesser_HardTypeInts() t.AdjustToCompensateForValue(10000); t.AdjustToCompensateForValue(DBNull.Value); - Assert.AreEqual(typeof(int), t.Guess.CSharpType); - Assert.AreEqual(0, t.Guess.Size.NumbersAfterDecimalPlace); - Assert.AreEqual(5, t.Guess.Size.NumbersBeforeDecimalPlace); + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(int))); + Assert.That(t.Guess.Size.NumbersAfterDecimalPlace, Is.EqualTo(0)); + Assert.That(t.Guess.Size.NumbersBeforeDecimalPlace, Is.EqualTo(5)); + }); } @@ -576,9 +657,12 @@ public void TestGuesser_HardTypeDoubles() t.AdjustToCompensateForValue(10000d);//<- d is required because Types must be homogenous t.AdjustToCompensateForValue(DBNull.Value); - Assert.AreEqual(typeof(double), t.Guess.CSharpType); - Assert.AreEqual(3, t.Guess.Size.NumbersAfterDecimalPlace); - Assert.AreEqual(5, t.Guess.Size.NumbersBeforeDecimalPlace); + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(double))); + Assert.That(t.Guess.Size.NumbersAfterDecimalPlace, Is.EqualTo(3)); + Assert.That(t.Guess.Size.NumbersBeforeDecimalPlace, Is.EqualTo(5)); + }); } @@ -593,14 +677,17 @@ public void TestGuesser_FallbackOntoStringLength(string legitType, Type expected //give it the legit hard typed value e.g. a date t.AdjustToCompensateForValue(legitType); - Assert.AreEqual(expectedLegitType, t.Guess.CSharpType); + Assert.That(t.Guess.CSharpType, Is.EqualTo(expectedLegitType)); //then give it a string t.AdjustToCompensateForValue(str); - Assert.AreEqual(typeof(string), t.Guess.CSharpType); + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(string))); - //the length should be the max of the length of the legit string and the string str - Assert.AreEqual(expectedLength, t.Guess.Width); + //the length should be the max of the length of the legit string and the string str + Assert.That(t.Guess.Width, Is.EqualTo(expectedLength)); + }); } @@ -614,7 +701,7 @@ public void TestGuesser_RandomCrud(string randomCrud) { var t = new Guesser(); t.AdjustToCompensateForValue(randomCrud); - Assert.AreEqual(typeof(string), t.Guess.CSharpType); + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(string))); } [Test] @@ -623,10 +710,13 @@ public void TestGuesser_ScientificNotation() const string val = "-4.10235746055587E-05"; //-0.0000410235746055587 var t = new Guesser(); t.AdjustToCompensateForValue(val); - Assert.AreEqual(typeof(decimal), t.Guess.CSharpType); + Assert.Multiple(() => + { + Assert.That(t.Guess.CSharpType, Is.EqualTo(typeof(decimal))); - Assert.AreEqual(0, t.Guess.Size.NumbersBeforeDecimalPlace); - Assert.AreEqual(19, t.Guess.Size.NumbersAfterDecimalPlace); + Assert.That(t.Guess.Size.NumbersBeforeDecimalPlace, Is.EqualTo(0)); + Assert.That(t.Guess.Size.NumbersAfterDecimalPlace, Is.EqualTo(19)); + }); } [TestCase("didn’t")] @@ -637,16 +727,19 @@ public void Test_NonAscii_CharacterLength(string word) var t = new Guesser(); t.AdjustToCompensateForValue(word); - //computer should have picked up that it needs unicode - Assert.IsTrue(t.Guess.Unicode); + Assert.Multiple(() => + { + //computer should have picked up that it needs unicode + Assert.That(t.Guess.Unicode); - //in most DBMS - Assert.AreEqual(t.Guess.Width,word.Length); + //in most DBMS + Assert.That(word, Has.Length.EqualTo(t.Guess.Width)); + }); //in the world of Oracle where you need varchar2(6) to store "It’s" t = new Guesser {ExtraLengthPerNonAsciiCharacter = 3}; t.AdjustToCompensateForValue(word); - Assert.AreEqual(word.Length + 3, t.Guess.Width); + Assert.That(t.Guess.Width, Is.EqualTo(word.Length + 3)); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/TypeTranslation/TypeTranslaterTests.cs b/Tests/FAnsiTests/TypeTranslation/TypeTranslaterTests.cs index 4225f1e1..dc120754 100644 --- a/Tests/FAnsiTests/TypeTranslation/TypeTranslaterTests.cs +++ b/Tests/FAnsiTests/TypeTranslation/TypeTranslaterTests.cs @@ -22,7 +22,7 @@ namespace FAnsiTests.TypeTranslation; /// public class TypeTranslaterTests : DatabaseTests { - private readonly Dictionary _translaters = new(); + private readonly Dictionary _translaters = []; [OneTimeSetUp] public void SetupDatabases() @@ -49,7 +49,7 @@ public void Test_CSharpToDbType_String10(DatabaseType type,string expectedType) { var cSharpType = new DatabaseTypeRequest(typeof (string), 10); - Assert.AreEqual(expectedType,_translaters[type].GetSQLDBTypeForCSharpType(cSharpType));} + Assert.That(_translaters[type].GetSQLDBTypeForCSharpType(cSharpType), Is.EqualTo(expectedType));} [TestCase(DatabaseType.MicrosoftSQLServer, "varchar(max)")] [TestCase(DatabaseType.MySql, "longtext")] @@ -59,14 +59,17 @@ public void Test_CSharpToDbType_StringMax(DatabaseType type,string expectedType) { var cSharpType = new DatabaseTypeRequest(typeof(string), 10000000); - //Does a request for a max length string give the expected data type? - Assert.AreEqual(expectedType,_translaters[type].GetSQLDBTypeForCSharpType(cSharpType)); + Assert.Multiple(() => + { + //Does a request for a max length string give the expected data type? + Assert.That(_translaters[type].GetSQLDBTypeForCSharpType(cSharpType), Is.EqualTo(expectedType)); - //Does the TypeTranslater know that this datatype has no limit on characters? - Assert.AreEqual(int.MaxValue, _translaters[type].GetLengthIfString(expectedType)); + //Does the TypeTranslater know that this datatype has no limit on characters? + Assert.That(_translaters[type].GetLengthIfString(expectedType), Is.EqualTo(int.MaxValue)); - //And does the TypeTranslater know that this datatype is string - Assert.AreEqual(typeof(string), _translaters[type].GetCSharpTypeForSQLDBType(expectedType)); + //And does the TypeTranslater know that this datatype is string + Assert.That(_translaters[type].GetCSharpTypeForSQLDBType(expectedType), Is.EqualTo(typeof(string))); + }); } [TestCase(DatabaseType.MicrosoftSQLServer, "varchar(max)",false)] @@ -78,12 +81,15 @@ public void Test_CSharpToDbType_StringMax(DatabaseType type,string expectedType) [TestCase(DatabaseType.PostgreSql, "text", false)] public void Test_GetLengthIfString_VarcharMaxCols(DatabaseType type, string datatype, bool expectUnicode) { - Assert.AreEqual(int.MaxValue, _translaters[type].GetLengthIfString(datatype)); + Assert.That(_translaters[type].GetLengthIfString(datatype), Is.EqualTo(int.MaxValue)); var dbType = _translaters[type].GetDataTypeRequestForSQLDBType(datatype); - Assert.AreEqual(typeof(string), dbType.CSharpType); - Assert.AreEqual(int.MaxValue, dbType.Width); - Assert.AreEqual(expectUnicode, dbType.Unicode); + Assert.Multiple(() => + { + Assert.That(dbType.CSharpType, Is.EqualTo(typeof(string))); + Assert.That(dbType.Width, Is.EqualTo(int.MaxValue)); + Assert.That(dbType.Unicode, Is.EqualTo(expectUnicode)); + }); } [TestCase(DatabaseType.MicrosoftSQLServer,"bigint",typeof(long))] @@ -228,21 +234,24 @@ private void RunKnownTypeTest(DatabaseType type, string sqlType, Type expectedTy //What type does FAnsi think this is? var tBefore = tt.TryGetCSharpTypeForSQLDBType(sqlType); - Assert.IsNotNull(tBefore,"We asked to create a '{0}', DBMS created a '{1}'. FAnsi didn't recognise '{0}' as a supported Type",sqlType,col.DataType.SQLType); + Assert.That(tBefore, Is.Not.Null, "We asked to create a '{0}', DBMS created a '{1}'. FAnsi didn't recognise '{0}' as a supported Type",sqlType,col.DataType.SQLType); //Does FAnsi understand the datatype that was actually created on the server (sometimes you specify something and it is an //alias for something else e.g. Oracle creates 'varchar2' when you ask for 'CHAR VARYING' var Guesser = col.GetGuesser(); - Assert.IsNotNull(Guesser.Guess.CSharpType); + Assert.That(Guesser.Guess.CSharpType, Is.Not.Null); var tAfter = Guesser.Guess.CSharpType; - //was the Type REQUESTED correct according to the test case expectation - Assert.AreEqual(expectedType, tBefore,"We asked to create a '{0}', DBMS created a '{1}'. FAnsi decided that '{0}' is '{2}' and that '{1}' is '{3}'",sqlType,col.DataType.SQLType,tBefore,tAfter); + Assert.Multiple(() => + { + //was the Type REQUESTED correct according to the test case expectation + Assert.That(tBefore, Is.EqualTo(expectedType), $"We asked to create a '{sqlType}', DBMS created a '{col.DataType.SQLType}'. FAnsi decided that '{sqlType}' is '{tBefore}' and that '{col.DataType.SQLType}' is '{tAfter}'"); - //Was the Type CREATED matching the REQUESTED type (as far as FAnsi is concerned) - Assert.AreEqual(tBefore, tAfter,"We asked to create a '{0}', DBMS created a '{1}'. FAnsi decided that '{0}' is '{2}' and that '{1}' is '{3}'",sqlType,col.DataType.SQLType,tBefore,tAfter); + //Was the Type CREATED matching the REQUESTED type (as far as FAnsi is concerned) + Assert.That(tAfter, Is.EqualTo(tBefore), $"We asked to create a '{sqlType}', DBMS created a '{col.DataType.SQLType}'. FAnsi decided that '{sqlType}' is '{tBefore}' and that '{col.DataType.SQLType}' is '{tAfter}'"); + }); - if(!string.Equals(col.DataType.SQLType,sqlType,StringComparison.CurrentCultureIgnoreCase)) + if (!string.Equals(col.DataType.SQLType,sqlType,StringComparison.CurrentCultureIgnoreCase)) TestContext.WriteLine("{0} created a '{1}' when asked to create a '{2}'", type, col.DataType.SQLType, sqlType); @@ -266,6 +275,6 @@ private void RunKnownTypeTest(DatabaseType type, string sqlType, Type expectedTy [TestCase(DatabaseType.Oracle, "MLSLABEL")] public void TestNotSupportedTypes(DatabaseType type, string sqlType) { - Assert.IsFalse(_translaters[type].IsSupportedSQLDBType(sqlType)); + Assert.That(_translaters[type].IsSupportedSQLDBType(sqlType), Is.False); } } \ No newline at end of file diff --git a/Tests/FAnsiTests/TypeTranslation/TypeTranslaterUnitTests.cs b/Tests/FAnsiTests/TypeTranslation/TypeTranslaterUnitTests.cs index 6d730724..6db11ce6 100644 --- a/Tests/FAnsiTests/TypeTranslation/TypeTranslaterUnitTests.cs +++ b/Tests/FAnsiTests/TypeTranslation/TypeTranslaterUnitTests.cs @@ -21,6 +21,6 @@ internal class TypeTranslaterUnitTests public void Test_IsSupportedType(DatabaseType dbType,string sqlDbType,bool expectedOutcome) { var tt = ImplementationManager.GetImplementation(dbType).GetQuerySyntaxHelper().TypeTranslater; - Assert.AreEqual(expectedOutcome,tt.IsSupportedSQLDBType(sqlDbType),$"Unexpected result for IsSupportedSQLDBType with {dbType}. Input was '{sqlDbType}' expected {expectedOutcome}"); + Assert.That(tt.IsSupportedSQLDBType(sqlDbType), Is.EqualTo(expectedOutcome), $"Unexpected result for IsSupportedSQLDBType with {dbType}. Input was '{sqlDbType}' expected {expectedOutcome}"); } } \ No newline at end of file