Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[*.cs]
root = true

[*.cs]
max_line_length = 120
charset = utf-8

Expand Down Expand Up @@ -173,3 +175,18 @@ dotnet_diagnostic.S4456.severity = none

[*.ps1]
end_of_line = crlf

[{tests,benchmarks}/**/*.cs]

dotnet_diagnostic.S2344.severity = none
dotnet_diagnostic.S3010.severity = none
dotnet_diagnostic.S4144.severity = none
dotnet_diagnostic.S3459.severity = none
dotnet_diagnostic.S3453.severity = none
dotnet_diagnostic.S1144.severity = none
dotnet_diagnostic.S1172.severity = none
dotnet_diagnostic.S3963.severity = none
dotnet_diagnostic.S6562.severity = none
dotnet_diagnostic.S2925.severity = none
dotnet_diagnostic.S5034.severity = none
dotnet_diagnostic.S2696.severity = none
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Roslynator.Analyzers" Version="4.16.1">
<PackageReference Include="Roslynator.Analyzers" Version="5.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public List<dynamic> Query_Dynamic_Command()
["ByteValue"] = dataReader.GetByte(ordinal++),
["CharValue"] = dataReader.GetChars(ordinal++, 0, charBuffer, 0, 1) == 1
? charBuffer[0]
: throw new(),
: throw new InvalidOperationException(),
["DateTimeValue"] = DateTime.Parse(dataReader.GetString(ordinal++), CultureInfo.InvariantCulture),
["DecimalValue"] = Decimal.Parse(dataReader.GetString(ordinal++), CultureInfo.InvariantCulture),
["DoubleValue"] = dataReader.GetDouble(ordinal++),
Expand All @@ -62,7 +62,7 @@ public List<dynamic> Query_Dynamic_Command()
["Int32Value"] = (Int32)dataReader.GetInt64(ordinal++),
["Int64Value"] = dataReader.GetInt64(ordinal++),
["SingleValue"] = dataReader.GetFloat(ordinal++),
["StringValue"] = dataReader.GetString(ordinal++)
["StringValue"] = dataReader.GetString(ordinal)
};

entities.Add(new DataRow(dictionary));
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/DbConnectionPlus.Benchmarks/Benchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private static BenchmarkEntity ReadEntity(IDataReader dataReader)
BooleanValue = dataReader.GetInt64(ordinal++) == 1,
BytesValue = (Byte[])dataReader.GetValue(ordinal++),
ByteValue = dataReader.GetByte(ordinal++),
CharValue = dataReader.GetChars(ordinal++, 0, charBuffer, 0, 1) == 1 ? charBuffer[0] : throw new(),
CharValue = dataReader.GetChars(ordinal++, 0, charBuffer, 0, 1) == 1 ? charBuffer[0] : throw new InvalidOperationException(),
DateTimeValue = DateTime.Parse(dataReader.GetString(ordinal++), CultureInfo.InvariantCulture),
DecimalValue = Decimal.Parse(dataReader.GetString(ordinal++), CultureInfo.InvariantCulture),
DoubleValue = dataReader.GetDouble(ordinal++),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ await this.CallApi(
TestContext.Current.CancellationToken
);

this.Connection.QueryFirst<MappingTestEntityAttributes>($"SELECT * FROM {Q("MappingTestEntity")}")
(await this.Connection.QueryFirstAsync<MappingTestEntityAttributes>($"SELECT * FROM {Q("MappingTestEntity")}"))
.Should().BeEquivalentTo(
entity,
options => options.Using<String>(context => context.Subject.Should().BeNull())
Expand Down Expand Up @@ -137,7 +137,7 @@ await this.CallApi(
TestContext.Current.CancellationToken
);

this.Connection.QueryFirst<MappingTestEntityFluentApi>($"SELECT * FROM {Q("MappingTestEntity")}")
(await this.Connection.QueryFirstAsync<MappingTestEntityFluentApi>($"SELECT * FROM {Q("MappingTestEntity")}"))
.Should().BeEquivalentTo(
entity,
options => options.Using<String>(context => context.Subject.Should().BeNull())
Expand All @@ -160,7 +160,7 @@ await this.CallApi(
TestContext.Current.CancellationToken
);

this.Connection.QueryFirst<MappingTestEntity>($"SELECT * FROM {Q("MappingTestEntity")}")
(await this.Connection.QueryFirstAsync<MappingTestEntity>($"SELECT * FROM {Q("MappingTestEntity")}"))
.Should().BeEquivalentTo(entity);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ await this.CallApi(
TestContext.Current.CancellationToken
);

this.Connection.QueryFirst<MappingTestEntityAttributes>($"SELECT * FROM {Q("MappingTestEntity")}")
(await this.Connection.QueryFirstAsync<MappingTestEntityAttributes>($"SELECT * FROM {Q("MappingTestEntity")}"))
.Should().BeEquivalentTo(
updatedEntity,
options => options.Using<String>(context => context.Subject.Should().BeNull())
Expand Down Expand Up @@ -225,7 +225,7 @@ await this.CallApi(
TestContext.Current.CancellationToken
);

this.Connection.QueryFirst<MappingTestEntityFluentApi>($"SELECT * FROM {Q("MappingTestEntity")}")
(await this.Connection.QueryFirstAsync<MappingTestEntityFluentApi>($"SELECT * FROM {Q("MappingTestEntity")}"))
.Should().BeEquivalentTo(
updatedEntity,
options => options.Using<String>(context => context.Subject.Should().BeNull())
Expand Down Expand Up @@ -271,7 +271,7 @@ await this.CallApi(
TestContext.Current.CancellationToken
);

this.Connection.QueryFirst<MappingTestEntity>($"SELECT * FROM {Q("MappingTestEntity")}")
(await this.Connection.QueryFirstAsync<MappingTestEntity>($"SELECT * FROM {Q("MappingTestEntity")}"))
.Should().BeEquivalentTo(updatedEntity);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ Boolean useAsyncApi
dataRow
.Should().NotBeNull();

dataRow!["Id"]
dataRow["Id"]
.Should().Be(entityIds[0]);

this.ExistsTemporaryTableInDb(temporaryTableName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ Boolean useAsyncApi
dataRow
.Should().NotBeNull();

dataRow!["Id"]
dataRow["Id"]
.Should().Be(entityId);

this.ExistsTemporaryTableInDb(temporaryTableName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageReference Include="Npgsql" Version="10.0.3" />
<PackageReference Include="NSubstitute" Version="5.3.0" />
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="23.26.300" />
<PackageReference Include="System.Linq.Async" Version="7.0.1" />
<PackageReference Include="System.Linq.AsyncEnumerable" Version="10.0.11" />
<!--
The four database servers the suite tests against. Testcontainers starts each container on demand and
removes it when the run ends - see TestDatabase/Containers/. Testcontainers.XunitV3, not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ SELECT 1
FROM {Q(metadata.TableName)}
WHERE {String.Join(
" AND ",
[.. keyProperties.Select(p => $"{Q(p.ColumnName)} = {P(p.PropertyName)}")]
keyProperties.Select(p => $"{Q(p.ColumnName)} = {P(p.PropertyName)}").ToList()
)}
""",
keyProperties.Select(p => (p.PropertyName, p.PropertyGetter!(entity))).ToArray()!
Expand Down Expand Up @@ -387,7 +387,9 @@ private void InterceptDbCommand(DbCommand command, IReadOnlyList<InterpolatedTem
/// <returns>A <see cref="CancellationToken" /> that will be cancelled after 100 milliseconds.</returns>
protected static CancellationToken CreateCancellationTokenThatIsCancelledAfter100Milliseconds()
{
#pragma warning disable S2930
var cancellationTokenSource = new CancellationTokenSource();
#pragma warning restore S2930
cancellationTokenSource.CancelAfter(100);
return cancellationTokenSource.Token;
}
Expand All @@ -397,7 +399,9 @@ protected static CancellationToken CreateCancellationTokenThatIsCancelledAfter10
/// <summary>
/// The connection to the test database for the currently running integration test.
/// </summary>
#pragma warning disable S2743
private static readonly AsyncLocal<DbConnection> currentTestDatabaseConnection = new();
#pragma warning restore S2743

/// <summary>
/// The database adapter for the test database of the currently running integration test.
Expand All @@ -406,5 +410,7 @@ protected static CancellationToken CreateCancellationTokenThatIsCancelledAfter10
/// The adapter rather than the provider: an interface that declares a static abstract member - which
/// <see cref="ITestDatabaseProvider.StartDatabaseAsync" /> is - cannot be used as a type argument.
/// </remarks>
#pragma warning disable S2743
private static readonly AsyncLocal<IDatabaseAdapter> currentDatabaseAdapter = new();
#pragma warning restore S2743
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void Read_OperationCancelledViaCancellationToken_ShouldThrowOperationCanc
using var command = this.Connection.CreateCommand();
command.CommandText = "SELECT 1; " + this.TestDatabaseProvider.DelayTwoSecondsStatement + " SELECT 1;";

var cancellationTokenSource = new CancellationTokenSource();
using var cancellationTokenSource = new CancellationTokenSource();
var cancellationToken = cancellationTokenSource.Token;

ThreadPool.QueueUserWorkItem(_ =>
Expand Down Expand Up @@ -86,7 +86,7 @@ public async Task ReadAsync_OperationCancelledViaCancellationToken_ShouldThrowOp
await using var command = this.Connection.CreateCommand();
command.CommandText = "SELECT 1; " + this.TestDatabaseProvider.DelayTwoSecondsStatement + " SELECT 1;";

var cancellationTokenSource = new CancellationTokenSource();
using var cancellationTokenSource = new CancellationTokenSource();
var cancellationToken = cancellationTokenSource.Token;

ThreadPool.QueueUserWorkItem(_ =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class DbCommandBuilderTests : UnitTestsBase
[InlineData(true)]
public async Task BuildDbCommand_CancellationToken_ShouldUseCancellationToken(Boolean useAsyncApi)
{
var cancellationTokenSource = new CancellationTokenSource();
using var cancellationTokenSource = new CancellationTokenSource();
var cancellationToken = cancellationTokenSource.Token;

await cancellationTokenSource.CancelAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class DbCommandDisposerTests : UnitTestsBase
[Fact]
public void Dispose_AlreadyDisposed_ShouldNotDisposeCommandResourcesAgain()
{
var cancellationTokenSource = new CancellationTokenSource();
using var cancellationTokenSource = new CancellationTokenSource();
var cancellationToken = cancellationTokenSource.Token;
var cancellationTokenRegistration =
DbCommandHelper.RegisterDbCommandCancellation(this.MockDbCommand, cancellationToken);
Expand Down Expand Up @@ -45,7 +45,7 @@ public void Dispose_AlreadyDisposed_ShouldNotDisposeCommandResourcesAgain()
[Fact]
public void Dispose_ShouldDisposeCommandResources()
{
var cancellationTokenSource = new CancellationTokenSource();
using var cancellationTokenSource = new CancellationTokenSource();
var cancellationToken = cancellationTokenSource.Token;
var cancellationTokenRegistration =
DbCommandHelper.RegisterDbCommandCancellation(this.MockDbCommand, cancellationToken);
Expand Down Expand Up @@ -82,7 +82,7 @@ public void Dispose_ShouldDisposeCommandResources()
[Fact]
public async Task DisposeAsync_AlreadyDisposed_ShouldNotDisposeCommandResourcesAsyncAgain()
{
var cancellationTokenSource = new CancellationTokenSource();
using var cancellationTokenSource = new CancellationTokenSource();
var cancellationToken = cancellationTokenSource.Token;
var cancellationTokenRegistration =
DbCommandHelper.RegisterDbCommandCancellation(this.MockDbCommand, cancellationToken);
Expand Down Expand Up @@ -117,7 +117,7 @@ public async Task DisposeAsync_AlreadyDisposed_ShouldNotDisposeCommandResourcesA
[Fact]
public async Task DisposeAsync_ShouldDisposeCommandResourcesAsync()
{
var cancellationTokenSource = new CancellationTokenSource();
using var cancellationTokenSource = new CancellationTokenSource();
var cancellationToken = cancellationTokenSource.Token;
var cancellationTokenRegistration =
DbCommandHelper.RegisterDbCommandCancellation(this.MockDbCommand, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class DbCommandHelperTests : UnitTestsBase
[Fact]
public void RegisterDbCommandCancellation_CancellationToken_ShouldRegister()
{
var cancellationTokenSource = new CancellationTokenSource();
using var cancellationTokenSource = new CancellationTokenSource();
var cancellationToken = cancellationTokenSource.Token;

var registration = DbCommandHelper.RegisterDbCommandCancellation(this.MockDbCommand, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@
<PackageReference Include="NSubstitute.Community.DbConnection" Version="2.15.0" />
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="23.26.300" />
<PackageReference Include="RentADeveloper.ArgumentNullGuards" Version="1.1.0" />
<PackageReference Include="System.Linq.Async" Version="7.0.1" />
<PackageReference Include="System.Linq.AsyncEnumerable" Version="10.0.11" />
<PackageReference Include="xunit.v3" Version="4.0.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
<!-- The native MTP coverage extension CI uses to produce the OpenCover report for SonarQube. -->
<PackageReference Include="coverlet.MTP" Version="10.0.1">
<PrivateAssets>all</PrivateAssets>
Expand Down
2 changes: 2 additions & 0 deletions tests/DbConnectionPlus.UnitTests/TestData/Generate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ static Generate()
}
);

#pragma warning disable S2930
var cancellationTokenSource = new CancellationTokenSource();
#pragma warning restore S2930
fixture.Register<CancellationToken>(() => cancellationTokenSource.Token);

TypeAdapterConfig<Entity, EntityWithDifferentCasingProperties>
Expand Down
2 changes: 1 addition & 1 deletion tests/DbConnectionPlus.UnitTests/TestData/TestEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace RentADeveloper.DbConnectionPlus.UnitTests.TestData;

public enum TestEnum : Int32
public enum TestEnum
{
Value1 = 1,
Value2 = 2,
Expand Down
Loading