Skip to content

Commit

Permalink
NUnit 4 API fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
jas88 committed Nov 27, 2023
1 parent 86996e7 commit 9b936d4
Show file tree
Hide file tree
Showing 57 changed files with 1,297 additions and 868 deletions.
1 change: 1 addition & 0 deletions FAnsiSql/Connections/ManagedConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public ManagedConnection Clone()
/// </summary>
public void Dispose()
{
System.GC.SuppressFinalize(this);
if (CloseOnDispose)
Connection.Dispose();
}
Expand Down
3 changes: 2 additions & 1 deletion FAnsiSql/DatabaseOperationArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions FAnsiSql/Discovery/BulkCopy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void InvalidateTableSchema()
/// </summary>
public virtual void Dispose()
{
GC.SuppressFinalize(this);
Connection.Dispose();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,19 @@ namespace FAnsi.Discovery.ConnectionStringDefaults;
///
/// <para>Also handles connection string keyword aliases (where two words mean the same thing)</para>
/// </summary>
public class ConnectionStringKeywordAccumulator
/// <remarks>
/// Initialises a new blank instance that does nothing. Call <see cref="AddOrUpdateKeyword"/> to adjust the template connection string options.
/// </remarks>
/// <param name="databaseType"></param>
public sealed class ConnectionStringKeywordAccumulator(DatabaseType databaseType)
{
/// <summary>
/// <see cref="DatabaseType"/> describing what implmentation of DbConnectionStringBuilder is being manipulated
/// <see cref="DatabaseType"/> describing what implementation of DbConnectionStringBuilder is being manipulated
/// </summary>
public DatabaseType DatabaseType { get; private set; }
public DatabaseType DatabaseType { get; private set; } = databaseType;

private readonly Dictionary<string, Tuple<string, ConnectionStringKeywordPriority>> _keywords = new(StringComparer.CurrentCultureIgnoreCase);
private readonly DbConnectionStringBuilder _builder;

/// <summary>
/// Initialises a new blank instance that does nothing. Call <see cref="AddOrUpdateKeyword"/> to adjust the template connection string options.
/// </summary>
/// <param name="databaseType"></param>
public ConnectionStringKeywordAccumulator(DatabaseType databaseType)
{
DatabaseType = databaseType;
_builder = ImplementationManager.GetImplementation(databaseType).GetBuilder();
}
private readonly DbConnectionStringBuilder _builder = ImplementationManager.GetImplementation(databaseType).GetBuilder();

/// <summary>
/// Adds a new connection string option (which must be compatible with <see cref="DatabaseType"/>)
Expand Down
5 changes: 2 additions & 3 deletions FAnsiSql/Discovery/Constraints/DiscoveredRelationship.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class DiscoveredRelationship
/// Mapping of primary key column(s) in <see cref="PrimaryKeyTable"/> to foreign key column(s) in <see cref="ForeignKeyTable"/>. If there are more than one entry
/// then the foreign key is a composite key.
/// </summary>
public Dictionary<DiscoveredColumn, DiscoveredColumn> Keys { get; private set; }
public Dictionary<DiscoveredColumn, DiscoveredColumn> Keys { get; }

/// <summary>
/// Describes what happens to records in the <see cref="ForeignKeyTable"/> when thier parent records (in the <see cref="PrimaryKeyTable"/>) are deleted.
Expand All @@ -51,9 +51,8 @@ public DiscoveredRelationship(string fkName, DiscoveredTable pkTable, Discovered
Name = fkName;
PrimaryKeyTable = pkTable;
ForeignKeyTable = fkTable;
Keys = [];
CascadeDelete = deleteRule;

Keys = new Dictionary<DiscoveredColumn, DiscoveredColumn>();
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion FAnsiSql/Discovery/DiscoveredDataType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class DiscoveredDataType
/// <summary>
/// All values read from the database record retrieved when assembling the data type (E.g. the cells of the sys.columns record)
/// </summary>
public Dictionary<string, object> ProprietaryDatatype = new();
public Dictionary<string, object> ProprietaryDatatype = [];

/// <summary>
/// API constructor, instead use <see cref="DiscoveredTable.DiscoverColumns"/> instead.
Expand Down
4 changes: 2 additions & 2 deletions FAnsiSql/Discovery/DiscoveredDatabaseHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public DiscoveredTable CreateTable(CreateTableArgs args)
var columns = new List<DatabaseColumnRequest>();
var customRequests = args.ExplicitColumnDefinitions != null
? args.ExplicitColumnDefinitions.ToList()
: new List<DatabaseColumnRequest>();
: [];

if(args.DataTable != null)
{
Expand Down Expand Up @@ -294,7 +294,7 @@ public void ExecuteBatchNonQuery(string sql, DbConnection conn, DbTransaction tr
/// <param name="timeout">Timeout in seconds to run each batch in the <paramref name="sql"/></param>
public void ExecuteBatchNonQuery(string sql, DbConnection conn, DbTransaction transaction, out Dictionary<int, Stopwatch> performanceFigures, int timeout = 30)
{
performanceFigures = new Dictionary<int, Stopwatch>();
performanceFigures = [];

var sqlBatch = new StringBuilder();

Expand Down
2 changes: 1 addition & 1 deletion FAnsiSql/Discovery/DiscoveredServerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace FAnsi.Discovery;
/// </summary>
public abstract class DiscoveredServerHelper:IDiscoveredServerHelper
{
private static readonly Dictionary<DatabaseType,ConnectionStringKeywordAccumulator> ConnectionStringKeywordAccumulators = new();
private static readonly Dictionary<DatabaseType,ConnectionStringKeywordAccumulator> ConnectionStringKeywordAccumulators = [];

/// <summary>
/// Register a system wide rule that all connection strings of <paramref name="databaseType"/> should include the given <paramref name="keyword"/>.
Expand Down
4 changes: 2 additions & 2 deletions FAnsiSql/Discovery/QuerySyntaxHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public abstract class QuerySyntaxHelper : IQuerySyntaxHelper

public ITypeTranslater TypeTranslater { get; private set; }

private readonly Dictionary<CultureInfo,TypeDeciderFactory> factories = new();
private readonly Dictionary<CultureInfo,TypeDeciderFactory> factories = [];

public IAggregateHelper AggregateHelper { get; private set; }
public IUpdateHelper UpdateHelper { get; set; }
Expand Down Expand Up @@ -95,7 +95,7 @@ protected string GetAliasConst()
public static HashSet<string> GetAllParameterNamesFromQuery(string query)
{
if (string.IsNullOrWhiteSpace(query))
return new HashSet<string>();
return [];

var toReturn = new HashSet<string>(ParameterNameRegex.Matches(query).Cast<Match>().Select(match => match.Groups[1].Value.Trim()), StringComparer.InvariantCultureIgnoreCase);
return toReturn;
Expand Down
4 changes: 4 additions & 0 deletions FAnsiSql/FAnsi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
</PackageReference>
<PackageReference Include="MySqlConnector" Version="2.3.1" />
<PackageReference Include="Npgsql" Version="8.0.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.9.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="3.21.120" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion FAnsiSql/Implementation/ImplementationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ImplementationManager

private ImplementationManager()
{
_implementations = new List<IImplementation>();
_implementations = [];
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion FAnsiSql/Implementations/Oracle/OracleQuerySyntaxHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public override string GetAutoIncrementKeywordIfAny()

public override Dictionary<string, string> GetSQLFunctionsDictionary()
{
return new Dictionary<string, string>();
return [];
}

public override string HowDoWeAchieveMd5(string selectSql)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public override string GetAutoIncrementKeywordIfAny()

public override Dictionary<string, string> GetSQLFunctionsDictionary()
{
return new Dictionary<string, string>();
return [];
}

public override string HowDoWeAchieveMd5(string selectSql)
Expand Down
1 change: 1 addition & 0 deletions Packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
6 changes: 3 additions & 3 deletions Tests/FAnsiTests/Aggregation/AggregationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace FAnsiTests.Aggregation;

internal class AggregationTests:DatabaseTests
{
private readonly Dictionary<DatabaseType, DiscoveredTable> _easyTables = new();
private readonly Dictionary<DatabaseType, DiscoveredTable> _hardTables = new();
private readonly Dictionary<DatabaseType, DiscoveredTable> _easyTables = [];
private readonly Dictionary<DatabaseType, DiscoveredTable> _hardTables = [];

[OneTimeSetUp]
public void Setup()
Expand Down Expand Up @@ -88,7 +88,7 @@ private void SetupDatabaseTable(bool easy, string name)

protected void AssertHasRow(DataTable dt, params object[] cells)
{
Assert.IsTrue(dt.Rows.Cast<DataRow>().Any(r=>IsMatch(r,cells)),"Did not find expected row:{0}", string.Join("|",cells));
Assert.That(dt.Rows.Cast<DataRow>().Any(r=>IsMatch(r,cells)),"Did not find expected row:{0}", string.Join("|",cells));
}

/// <summary>
Expand Down
16 changes: 10 additions & 6 deletions Tests/FAnsiTests/Aggregation/BasicAggregationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}


Expand Down Expand Up @@ -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));
});
}
}
Loading

0 comments on commit 9b936d4

Please sign in to comment.