From d48ce858304d1b8c16824cd7b49f2cb812050cc9 Mon Sep 17 00:00:00 2001 From: electricessence <5899455+electricessence@users.noreply.github.com> Date: Fri, 4 Dec 2026 08:49:06 -0800 Subject: [PATCH 1/5] Remove the using directives no target framework needs Two files in Core had a using directive that no code in them uses on any target framework (CaptureNames and the output-parameter part of ExpressiveCommandBase). Two more (ChunkChain and PooledArray) use System.Runtime.InteropServices only for CollectionsMarshal, which exists from .NET 8, so on the netstandard targets the directive was unused there; it is now inside the same #if NET8_0_OR_GREATER that guards its use. No behavior change and no public API change. Co-Authored-By: Claude Sonnet 5.5 --- Source/Core/CaptureNames.cs | 2 -- Source/Core/ChunkChain.cs | 2 ++ Source/Core/ExpressiveCommandBase.Output.cs | 2 -- Source/Core/PooledArray.cs | 2 ++ 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Core/CaptureNames.cs b/Source/Core/CaptureNames.cs index 474bb091..3873c975 100644 --- a/Source/Core/CaptureNames.cs +++ b/Source/Core/CaptureNames.cs @@ -1,5 +1,3 @@ -using System.Runtime.CompilerServices; - namespace Open.Database.Extensions; /// diff --git a/Source/Core/ChunkChain.cs b/Source/Core/ChunkChain.cs index 8c236dec..ff9a8beb 100644 --- a/Source/Core/ChunkChain.cs +++ b/Source/Core/ChunkChain.cs @@ -1,4 +1,6 @@ +#if NET8_0_OR_GREATER using System.Runtime.InteropServices; +#endif namespace Open.Database.Extensions.Core; diff --git a/Source/Core/ExpressiveCommandBase.Output.cs b/Source/Core/ExpressiveCommandBase.Output.cs index 0374d07f..293c64d1 100644 --- a/Source/Core/ExpressiveCommandBase.Output.cs +++ b/Source/Core/ExpressiveCommandBase.Output.cs @@ -1,5 +1,3 @@ -using System.Diagnostics; - namespace Open.Database.Extensions; // A call that reads output parameters passes its OutputRun as the state of the run, and the run recognizes it by its type: diff --git a/Source/Core/PooledArray.cs b/Source/Core/PooledArray.cs index 8c2fead2..5d6c7976 100644 --- a/Source/Core/PooledArray.cs +++ b/Source/Core/PooledArray.cs @@ -1,5 +1,7 @@ using System.Diagnostics; +#if NET8_0_OR_GREATER using System.Runtime.InteropServices; +#endif namespace Open.Database.Extensions; From 56fa492dd78b8099b0a5ecceb8f2ddc9bf0f046d Mon Sep 17 00:00:00 2001 From: electricessence <5899455+electricessence@users.noreply.github.com> Date: Fri, 4 Dec 2026 08:49:11 -0800 Subject: [PATCH 2/5] Fix the Roslyn and Roslynator findings in the tests and samples Redundant casts (IDE0004) and an unnecessary null-forgiving operator (IDE0370) are removed in Core.Tests, Generator.Tests and the docs sample, together with the sample comment that described the cast. A test that used the legacy package's extension class by name now calls the extension as an instance method (RCS1196), and its unused alias is gone. A fake transaction is disposed with await using in an async test (RCS1261). The docs sample compares a string with Length instead of with "" (RCS1156). Where the finding cannot be fixed without changing what the test checks, it is suppressed in source with the reason beside it: block-bodied discard lambdas passed to Assert.Throws (an expression body would bind to the Func overload that xUnit rejects, RCS1021), a property over an initialized backing field and a retired parameter that are the cases under test (RCS1085, RCS1163). Tests only; no test asserts anything different. Co-Authored-By: Claude Sonnet 5.5 --- .../CaptureStreamTests.cs | 4 +++- .../CaptureTests.cs | 2 ++ .../NameCacheSharedTierTests.cs | 2 +- .../NameCacheSourceTests.cs | 11 +++++------ .../OutputParameterLocalDbTests.cs | 6 ++++-- .../OutputParameterTests.cs | 2 ++ .../ToChannelTargetTests.cs | 4 ++-- .../ParityTests.Errors.cs | 2 +- .../ParityTests.NullStart.cs | 4 ++-- .../ParityTests.Shapes.cs | 2 ++ .../ParityTests.Trusted.cs | 2 +- docsite/samples/Defined.cs | 6 ++---- docsite/samples/Program.cs | 2 +- 13 files changed, 28 insertions(+), 21 deletions(-) diff --git a/Tests/Open.Database.Extensions.Core.Tests/CaptureStreamTests.cs b/Tests/Open.Database.Extensions.Core.Tests/CaptureStreamTests.cs index 4bca471f..df4164b1 100644 --- a/Tests/Open.Database.Extensions.Core.Tests/CaptureStreamTests.cs +++ b/Tests/Open.Database.Extensions.Core.Tests/CaptureStreamTests.cs @@ -5,6 +5,8 @@ namespace Open.Database.Extensions.Tests; +#pragma warning disable RCS1021 // A block body keeps the lambda an Action: an expression body binds Assert.Throws to its Func overload, which xUnit rejects. + // The captures on the stream paths (Stream, StreamBuffered, the pooled // streams and buffer), on the Channel and Dataflow members, and on the edges: // a failed run, a stall, a cancel mid-read, a command that re-implements its @@ -198,7 +200,7 @@ public static void APooledBuffer_WhoseSchedulerRefusesTheStart_FaultsIt() Assert.IsType(thrown); Task task = total.AsTask(); Assert.True(task.IsFaulted); - Assert.Same(thrown, task.Exception!.InnerException); + Assert.Same(thrown, task.Exception.InnerException); Assert.Equal(0, c.Executed); } diff --git a/Tests/Open.Database.Extensions.Core.Tests/CaptureTests.cs b/Tests/Open.Database.Extensions.Core.Tests/CaptureTests.cs index 53abdfb0..299be65b 100644 --- a/Tests/Open.Database.Extensions.Core.Tests/CaptureTests.cs +++ b/Tests/Open.Database.Extensions.Core.Tests/CaptureTests.cs @@ -5,6 +5,8 @@ namespace Open.Database.Extensions.Tests; +#pragma warning disable RCS1021 // A block body keeps the lambda an Action: an expression body binds Assert.Throws to its Func overload, which xUnit rejects. + // The captures (CaptureOutput, CaptureOutputDecimal, CaptureReturn) on a // command and on a mapped query, over a provider that records its // parameters, fills the outputs when it executes, and can hold an execution diff --git a/Tests/Open.Database.Extensions.Core.Tests/NameCacheSharedTierTests.cs b/Tests/Open.Database.Extensions.Core.Tests/NameCacheSharedTierTests.cs index d4155b00..de95634d 100644 --- a/Tests/Open.Database.Extensions.Core.Tests/NameCacheSharedTierTests.cs +++ b/Tests/Open.Database.Extensions.Core.Tests/NameCacheSharedTierTests.cs @@ -524,7 +524,7 @@ public static async Task ADbNonQuery_InATransactionOnAFreshConnectionForEachCall for (int i = 0; i < 3; i++) { NameServer.NameConnection connection = server.Connect(); - using DbTransaction transaction = connection.BeginTransaction(); + await using DbTransaction transaction = connection.BeginTransaction(); await write.Using(transaction) .AddParam(OrderId) .ExecuteNonQueryAsync(Token); diff --git a/Tests/Open.Database.Extensions.Core.Tests/NameCacheSourceTests.cs b/Tests/Open.Database.Extensions.Core.Tests/NameCacheSourceTests.cs index a5b1e70e..36861110 100644 --- a/Tests/Open.Database.Extensions.Core.Tests/NameCacheSourceTests.cs +++ b/Tests/Open.Database.Extensions.Core.Tests/NameCacheSourceTests.cs @@ -5,7 +5,6 @@ using MsCommand = mssql::Open.Database.Extensions.ExpressiveSqlCommand; using MsExtensions = mssql::Open.Database.Extensions.SqlConnectionExtensions; using LegacyCommand = global::Open.Database.Extensions.ExpressiveSqlCommand; -using LegacyExtensions = global::Open.Database.Extensions.SqlConnectionExtensions; namespace Open.Database.Extensions.Tests; @@ -367,12 +366,12 @@ public static async Task TwoCommands_FromOneLegacySqlServerFunction_ReadTheNames var trips = new Trips(); Func create = CountingLegacy(trips); - await RunAsync(LegacyExtensions.StoredProcedure(create, name)); + await RunAsync(create.StoredProcedure(name)); long first = trips.Take(); - await RunAsync(LegacyExtensions.StoredProcedure(create, name)); + await RunAsync(create.StoredProcedure(name)); long second = trips.Take(); await RunAsync( - LegacyExtensions.Command(create, name, CommandType.StoredProcedure)); + create.Command(name, CommandType.StoredProcedure)); long third = trips.Take(); Assert.True(first > 0); @@ -563,8 +562,8 @@ public static void ANullFunction_IsRefused_BySqlServerExtensions() Assert.Equal("ArgumentNullException:factory", Refusal(() => MsExtensions.StoredProcedure((Func)null!, "proc"))); Assert.Equal("ArgumentNullException:factory", Refusal(() => MsExtensions.Command((Func)null!, "proc", CommandType.StoredProcedure))); #pragma warning disable CS0618 // System.Data.SqlClient is obsolete; it is one of the two packages under test - Assert.Equal("ArgumentNullException:factory", Refusal(() => LegacyExtensions.StoredProcedure((Func)null!, "proc"))); - Assert.Equal("ArgumentNullException:factory", Refusal(() => LegacyExtensions.Command((Func)null!, "proc", CommandType.StoredProcedure))); + Assert.Equal("ArgumentNullException:factory", Refusal(() => ((Func)null!).StoredProcedure("proc"))); + Assert.Equal("ArgumentNullException:factory", Refusal(() => ((Func)null!).Command("proc", CommandType.StoredProcedure))); #pragma warning restore CS0618 } } diff --git a/Tests/Open.Database.Extensions.Core.Tests/OutputParameterLocalDbTests.cs b/Tests/Open.Database.Extensions.Core.Tests/OutputParameterLocalDbTests.cs index 27033f65..cfd48c87 100644 --- a/Tests/Open.Database.Extensions.Core.Tests/OutputParameterLocalDbTests.cs +++ b/Tests/Open.Database.Extensions.Core.Tests/OutputParameterLocalDbTests.cs @@ -5,6 +5,8 @@ namespace Open.Database.Extensions.Tests; +#pragma warning disable RCS1021 // A block body keeps the lambda an Action: an expression body binds Assert.Throws to its Func overload, which xUnit rejects. + // ExecuteOutputAsync() and its named form against SQL Server: one test per fact the design rests on (sizes, decimal scale, // datetime2, NULLs, the lost default, the return code, names known and forgotten, a text's markers, a later statement's error). // Skipped without LocalDB (see LocalDbFixture). @@ -546,9 +548,9 @@ public static async Task TheDecimalForms_ReadADecimal_ByItsPrecisionAndScale() string name = "dbo." + procedure.Name; decimal total = await connection.StoredProcedure(name).ExecuteOutputAsync("total", 19, 4, Token); - Assert.Equal((12.3456m, 4), (total, (int)total.Scale)); + Assert.Equal((12.3456m, 4), (total, total.Scale)); decimal? same = await connection.StoredProcedure(name).ExecuteOutputDecimalAsync("total", 19, 4, Token); - Assert.Equal((12.3456m, 4), (same!.Value, (int)same.Value.Scale)); + Assert.Equal((12.3456m, 4), (same!.Value, same.Value.Scale)); Assert.Null(await connection.StoredProcedure(name).AddParam("nulls", true).ExecuteOutputDecimalAsync("total", 19, 4, Token)); Assert.Null(await connection.StoredProcedure(name).AddParam("nulls", true).ExecuteOutputAsync("total", 19, 4, Token)); diff --git a/Tests/Open.Database.Extensions.Core.Tests/OutputParameterTests.cs b/Tests/Open.Database.Extensions.Core.Tests/OutputParameterTests.cs index eba09511..7cb3aeb4 100644 --- a/Tests/Open.Database.Extensions.Core.Tests/OutputParameterTests.cs +++ b/Tests/Open.Database.Extensions.Core.Tests/OutputParameterTests.cs @@ -446,7 +446,9 @@ static void ThrowsAtTheCall(Func call, param where TException : Exception { var c = new OutputConnection(); +#pragma warning disable RCS1021 // A block body keeps the lambda an Action: an expression body binds Assert.Throws to its Func overload, which xUnit rejects. var ex = Assert.Throws(() => { _ = call(c); }); +#pragma warning restore RCS1021 foreach (string phrase in phrases) Assert.Contains(phrase, ex.Message); Assert.Null(c.Last); } diff --git a/Tests/Open.Database.Extensions.Core.Tests/ToChannelTargetTests.cs b/Tests/Open.Database.Extensions.Core.Tests/ToChannelTargetTests.cs index 50665b75..0a2cd6fc 100644 --- a/Tests/Open.Database.Extensions.Core.Tests/ToChannelTargetTests.cs +++ b/Tests/Open.Database.Extensions.Core.Tests/ToChannelTargetTests.cs @@ -328,9 +328,9 @@ public static void WhenEveryArgumentIsNull_EachOverloadNamesItsFirstGuard() IMappedQuery none = null; Assert.Equal("channel", Assert.Throws( - () => Drop(none.ToChannel((Channel)null, Ct))).ParamName); + () => Drop(none.ToChannel(null, Ct))).ParamName); Assert.Equal("channel", Assert.Throws( - () => Drop(none.ToChannel((Channel)null, true, Ct))).ParamName); + () => Drop(none.ToChannel(null, true, Ct))).ParamName); Assert.Equal("source", Assert.Throws( () => Drop(none.ToChannel((ChannelWriter)null, Ct))).ParamName); } diff --git a/Tests/Open.Database.Extensions.Generator.Tests/ParityTests.Errors.cs b/Tests/Open.Database.Extensions.Generator.Tests/ParityTests.Errors.cs index 23ed6dfe..9f85491a 100644 --- a/Tests/Open.Database.Extensions.Generator.Tests/ParityTests.Errors.cs +++ b/Tests/Open.Database.Extensions.Generator.Tests/ParityTests.Errors.cs @@ -234,7 +234,7 @@ static void FaultReport( { var e = Assert.IsType(generated); Assert.IsType(expected.GetType(), e.InnerException); - Assert.Equal(expected.Message, e.InnerException!.Message); + Assert.Equal(expected.Message, e.InnerException.Message); Assert.Equal(model, e.TargetType); Assert.Equal("", e.PropertyName); Assert.Equal("", e.ColumnName); diff --git a/Tests/Open.Database.Extensions.Generator.Tests/ParityTests.NullStart.cs b/Tests/Open.Database.Extensions.Generator.Tests/ParityTests.NullStart.cs index 6c041ee4..0ccb6877 100644 --- a/Tests/Open.Database.Extensions.Generator.Tests/ParityTests.NullStart.cs +++ b/Tests/Open.Database.Extensions.Generator.Tests/ParityTests.NullStart.cs @@ -127,11 +127,11 @@ public sealed partial class NullStartPartial public sealed partial class NullStartPartial { -#pragma warning disable IDE0032 // Use auto property: the initialized backing field is the case under test. +#pragma warning disable IDE0032, RCS1085 // Use auto property: the initialized backing field is the case under test. int? _qty = 5; public partial int? Qty { get => _qty; set => _qty = value; } -#pragma warning restore IDE0032 +#pragma warning restore IDE0032, RCS1085 } /// A struct with no declared constructor and a setter with a body: a NULL must reach the setter. diff --git a/Tests/Open.Database.Extensions.Generator.Tests/ParityTests.Shapes.cs b/Tests/Open.Database.Extensions.Generator.Tests/ParityTests.Shapes.cs index 20daae7a..5fc42a2f 100644 --- a/Tests/Open.Database.Extensions.Generator.Tests/ParityTests.Shapes.cs +++ b/Tests/Open.Database.Extensions.Generator.Tests/ParityTests.Shapes.cs @@ -202,7 +202,9 @@ internal sealed class RetiredListPost internal sealed class RetiredParameterPost { [Obsolete("Retired.")] +#pragma warning disable RCS1163 // Unused parameter: the retired parameter is the case under test. public RetiredParameterPost(int id, RetiredState state = default) => Id = id; +#pragma warning restore RCS1163 public int Id { get; } } diff --git a/Tests/Open.Database.Extensions.Generator.Tests/ParityTests.Trusted.cs b/Tests/Open.Database.Extensions.Generator.Tests/ParityTests.Trusted.cs index 8a11ec62..1d34728c 100644 --- a/Tests/Open.Database.Extensions.Generator.Tests/ParityTests.Trusted.cs +++ b/Tests/Open.Database.Extensions.Generator.Tests/ParityTests.Trusted.cs @@ -37,7 +37,7 @@ public void A_trusted_model_with_a_gap_skips_the_column_between_and_leaves_what_ OrderedGapPost post = Assert.Single(q.Map().ToList()); Assert.Equal(1, Counts.Now().Since(start).Literal); - Assert.Equal((7, "kept", PostState.Archived, (object)1.5), (post.Id, post.Display, post.State, post.Extra)); + Assert.Equal((7, "kept", PostState.Archived, 1.5), (post.Id, post.Display, post.State, post.Extra)); } [Fact] diff --git a/docsite/samples/Defined.cs b/docsite/samples/Defined.cs index 3364ab3c..dd263ee3 100644 --- a/docsite/samples/Defined.cs +++ b/docsite/samples/Defined.cs @@ -1,4 +1,3 @@ -using System.Data.Common; using Microsoft.Data.Sqlite; using Open.Database.Extensions; using static Samples.Sql; @@ -61,9 +60,8 @@ public static ValueTask InsertInTransactionAsync( => connectionFactory.UsingAsync(connection => connection.ExecuteTransactionAsync(async transaction => { - // The definition runs on the transaction. Using takes a - // DbTransaction; the callback's is an IDbTransaction. - await InsertTemporary.Using((DbTransaction)transaction) + // The definition runs on the transaction. + await InsertTemporary.Using(transaction) .AddParam("id", 100) .ExecuteNonQueryAsync(cancellationToken); }, cancellationToken)); diff --git a/docsite/samples/Program.cs b/docsite/samples/Program.cs index 1f3a9dc4..10096393 100644 --- a/docsite/samples/Program.cs +++ b/docsite/samples/Program.cs @@ -749,7 +749,7 @@ await OutputParameters.Export(exported, littleCodeToken) == 2 await factory.Command("delete from posts where id = @id").AddParam("id", definedNewId).ExecuteNonQueryAsync(); Check((await DefinedTerminals.PageAsync(factory, 1, 2, CancellationToken.None)).Select(p => p.Id).SequenceEqual([2, 3]), "a declared query is paged where it runs"); Dictionary definedBodies = await DefinedTerminals.BodiesAsync(factory, CancellationToken.None); -Check(definedBodies.Count == 5 && definedBodies[1] == "Body 1" && definedBodies[2] == "", "a declared query builds a dictionary with a key and a value selector"); +Check(definedBodies.Count == 5 && definedBodies[1] == "Body 1" && definedBodies[2].Length == 0, "a declared query builds a dictionary with a key and a value selector"); Check(await DefinedTerminals.StopAtAsync(factory, "Post 3", CancellationToken.None) == 3, "a declared query streams and stops early"); using (PooledBuffer definedBuffer = DefinedBuffers.LatestPosts(factory, CancellationToken.None)) { From ac40f46d18cebc8de85d8978a636bafa82a58fbd Mon Sep 17 00:00:00 2001 From: electricessence <5899455+electricessence@users.noreply.github.com> Date: Fri, 4 Dec 2026 08:49:11 -0800 Subject: [PATCH 3/5] Explain the Roslynator findings the benchmarks must keep The benchmarks keep the synchronous dispose of the data reader, a static member the benchmark class has to own for BenchmarkDotNet, and the single field of an inline array. Each Roslynator finding about them (RCS1261, RCS1158, RCS1213, RCS1169) is suppressed in source around exactly that code, with the reason beside it. Changing any of them would change what the benchmarks measure or whether they compile. No code change. Co-Authored-By: Claude Sonnet 5.5 --- .../CopyOutCollectorBenchmarks.cs | 10 ++++++++++ .../OneRowLookupBenchmarks.cs | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/Benchmarks/Open.Database.Extensions.Benchmarks/CopyOutCollectorBenchmarks.cs b/Benchmarks/Open.Database.Extensions.Benchmarks/CopyOutCollectorBenchmarks.cs index fe2e3d41..8c166823 100644 --- a/Benchmarks/Open.Database.Extensions.Benchmarks/CopyOutCollectorBenchmarks.cs +++ b/Benchmarks/Open.Database.Extensions.Benchmarks/CopyOutCollectorBenchmarks.cs @@ -40,6 +40,7 @@ public abstract class CopyOutCollectorBenchmarks [ParamsSource(nameof(RowsValues))] public int Rows { get; set; } +#pragma warning disable RCS1158 // BenchmarkDotNet reads the ParamsSource member from the benchmark class itself, by name. public static IEnumerable RowsValues() { string? value = Environment.GetEnvironmentVariable("ODX_COPYOUT_ROWS"); @@ -47,6 +48,7 @@ public static IEnumerable RowsValues() ? [0, 1, 5, 10, 100, 1000, 100_000] : value.Split(',').Select(static s => int.Parse(s.Trim())); } +#pragma warning restore RCS1158 DataTable _table = null!; Func _read = null!; @@ -203,6 +205,7 @@ public ValueTask> Async_Chain_ToImmutableArray() return Finish(reader, reader.Map(_read).ToImmutableArrayAsync()); } +#pragma warning disable RCS1261 // The synchronous dispose of the reader is part of what these benchmarks measure; await using would change the published numbers. [Benchmark(Baseline = true), BenchmarkCategory("Async")] public async ValueTask> Async_List_Grow() { @@ -238,6 +241,7 @@ public async ValueTask> Async_RawChain_ToList() while (await reader.ReadAsync().ConfigureAwait(false)) chain.Add(_read(reader)); return chain.ToList(); } +#pragma warning restore RCS1261 // The reader is the caller's: disposed when the terminal is done. static async ValueTask Finish(DataTableReader reader, ValueTask terminal) @@ -269,6 +273,7 @@ static async ValueTask Finish(DataTableReader reader, ValueTas _ => throw new ArgumentException(variant, nameof(variant)), }; +#pragma warning disable RCS1158 // The checks read the variant names of every T from one place, beside the benchmarks they name. internal static readonly string[] Variants = [ nameof(Sync_Chain_ToList), nameof(Sync_Chain_ToArray), nameof(Sync_Chain_ToImmutableArray), @@ -279,6 +284,7 @@ static async ValueTask Finish(DataTableReader reader, ValueTas nameof(Async_Chain_ToList), nameof(Async_Chain_ToArray), nameof(Async_Chain_ToImmutableArray), nameof(Async_List_Grow), nameof(Async_List_ToArray), nameof(Async_Builder_ToImmutable), ]; +#pragma warning restore RCS1158 } /// A row with no references: 16 bytes. @@ -314,14 +320,18 @@ public class CopyOutClass : CopyOutCollectorBenchmarks [InlineArray(8)] public struct Scratch8 { +#pragma warning disable RCS1213 // An inline array has exactly one field, its element: the compiler indexes it. T _element0; +#pragma warning restore RCS1213 } /// Up to 27 segments, held inline, so the builder allocates no array of arrays. [InlineArray(27)] public struct Segments { +#pragma warning disable RCS1169, RCS1213 // An inline array has exactly one field, its element: the compiler indexes and writes it. T[] _element0; +#pragma warning restore RCS1169, RCS1213 } // A prototype for the question "would a small stack scratch in front of the chain win at small counts?". diff --git a/Benchmarks/Open.Database.Extensions.Benchmarks/OneRowLookupBenchmarks.cs b/Benchmarks/Open.Database.Extensions.Benchmarks/OneRowLookupBenchmarks.cs index d85c534b..f0168ef5 100644 --- a/Benchmarks/Open.Database.Extensions.Benchmarks/OneRowLookupBenchmarks.cs +++ b/Benchmarks/Open.Database.Extensions.Benchmarks/OneRowLookupBenchmarks.cs @@ -123,6 +123,7 @@ public T Sync_Single_One() // ---- asynchronous ----------------------------------------------------- +#pragma warning disable RCS1261 // The synchronous dispose of the reader is part of what these benchmarks measure; await using would change the published numbers. [Benchmark(Baseline = true), BenchmarkCategory("Async")] public async ValueTask Async_Hand_One() { @@ -181,6 +182,7 @@ public async ValueTask Async_Single_One() using DataTableReader reader = _one.CreateDataReader(); return await reader.Map(_read).SingleOrDefaultAsync().ConfigureAwait(false); } +#pragma warning restore RCS1261 // The same calls, for the checks: every variant by name. internal object? Run(string variant) => variant switch @@ -204,6 +206,7 @@ public async ValueTask Async_Single_One() _ => throw new ArgumentException(variant, nameof(variant)), }; +#pragma warning disable RCS1158 // The checks read the variant names of every T from one place, beside the benchmarks they name. internal static readonly string[] Variants = [ nameof(Sync_Hand_One), nameof(Sync_Hand_Single_One), nameof(Sync_First_One), nameof(Sync_First_Many), @@ -211,6 +214,7 @@ public async ValueTask Async_Single_One() nameof(Async_Hand_One), nameof(Async_Hand_Single_One), nameof(Async_First_One), nameof(Async_First_Many), nameof(Async_FirstOrDefault_One), nameof(Async_FirstOrDefault_Many), nameof(Async_Single_One), nameof(Async_SingleOrDefault_One), ]; +#pragma warning restore RCS1158 } /// A row that is a class with a string. From ddc78f090ad05c67ab8c2c11ce756c7a6e0a4321 Mon Sep 17 00:00:00 2001 From: electricessence <5899455+electricessence@users.noreply.github.com> Date: Fri, 4 Dec 2026 09:33:39 -0800 Subject: [PATCH 4/5] Narrow the Roslynator suppressions and fix the generic-type statics Suppression is now at method level, with each reason written once. - RCS1021 (block-bodied discard lambdas passed to Assert.Throws): the file-level pragmas in three test files are gone. The 14 test methods that need a block body carry [SuppressMessage] with one shared reason constant. - RCS1261 (await using) in the benchmarks: the two block pragmas over the async sections are replaced by [SuppressMessage] on each of the 12 benchmark methods, with one shared reason constant. The reader still disposes synchronously, so what the benchmarks measure is unchanged. - RCS1158 (static member in a generic type) is fixed, not suppressed: the variant names move to non-generic holders (the checks read them from there) and the ParamsSource member becomes an instance method, which BenchmarkDotNet resolves on the concrete benchmark type. - One reason names both IDE0032 and RCS1085, and a test with two long lines and a split call is wrapped. No test asserts anything different and no benchmark body changed. Co-Authored-By: Claude Sonnet 5.5 --- .../CopyOutChecks.cs | 2 +- .../CopyOutCollectorBenchmarks.cs | 44 ++++++++++++------- .../OneRowChecks.cs | 2 +- .../OneRowLookupBenchmarks.cs | 39 ++++++++++++---- .../SuppressionReasons.cs | 16 +++++++ .../CaptureStreamTests.cs | 4 +- .../CaptureTests.cs | 10 ++++- .../NameCacheSourceTests.cs | 12 +++-- .../OutputParameterLocalDbTests.cs | 5 ++- .../OutputParameterTests.cs | 3 +- .../TestHelpers/SuppressionReasons.cs | 17 +++++++ .../ParityTests.NullStart.cs | 2 +- 12 files changed, 117 insertions(+), 39 deletions(-) create mode 100644 Benchmarks/Open.Database.Extensions.Benchmarks/SuppressionReasons.cs create mode 100644 Tests/Open.Database.Extensions.Core.Tests/TestHelpers/SuppressionReasons.cs diff --git a/Benchmarks/Open.Database.Extensions.Benchmarks/CopyOutChecks.cs b/Benchmarks/Open.Database.Extensions.Benchmarks/CopyOutChecks.cs index ffd9e674..c0ff0ef3 100644 --- a/Benchmarks/Open.Database.Extensions.Benchmarks/CopyOutChecks.cs +++ b/Benchmarks/Open.Database.Extensions.Benchmarks/CopyOutChecks.cs @@ -39,7 +39,7 @@ static int Run(Func create, Func key) continue; } - foreach (string variant in CopyOutCollectorBenchmarks.Variants) + foreach (string variant in CopyOutVariants.Names) { // Twice: the second call rents the parked chain and pooled arrays of the first. for (int attempt = 0; attempt < 2; attempt++) diff --git a/Benchmarks/Open.Database.Extensions.Benchmarks/CopyOutCollectorBenchmarks.cs b/Benchmarks/Open.Database.Extensions.Benchmarks/CopyOutCollectorBenchmarks.cs index 8c166823..116203e7 100644 --- a/Benchmarks/Open.Database.Extensions.Benchmarks/CopyOutCollectorBenchmarks.cs +++ b/Benchmarks/Open.Database.Extensions.Benchmarks/CopyOutCollectorBenchmarks.cs @@ -1,6 +1,7 @@ using System.Buffers; using System.Collections.Immutable; using System.Data; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using BenchmarkDotNet.Attributes; @@ -40,15 +41,13 @@ public abstract class CopyOutCollectorBenchmarks [ParamsSource(nameof(RowsValues))] public int Rows { get; set; } -#pragma warning disable RCS1158 // BenchmarkDotNet reads the ParamsSource member from the benchmark class itself, by name. - public static IEnumerable RowsValues() + public IEnumerable RowsValues() { string? value = Environment.GetEnvironmentVariable("ODX_COPYOUT_ROWS"); return string.IsNullOrWhiteSpace(value) ? [0, 1, 5, 10, 100, 1000, 100_000] : value.Split(',').Select(static s => int.Parse(s.Trim())); } -#pragma warning restore RCS1158 DataTable _table = null!; Func _read = null!; @@ -205,8 +204,8 @@ public ValueTask> Async_Chain_ToImmutableArray() return Finish(reader, reader.Map(_read).ToImmutableArrayAsync()); } -#pragma warning disable RCS1261 // The synchronous dispose of the reader is part of what these benchmarks measure; await using would change the published numbers. [Benchmark(Baseline = true), BenchmarkCategory("Async")] + [SuppressMessage("Roslynator", "RCS1261:Resource can be disposed asynchronously", Justification = SuppressionReasons.SyncDispose)] public async ValueTask> Async_List_Grow() { using DataTableReader reader = _table.CreateDataReader(); @@ -216,6 +215,7 @@ public async ValueTask> Async_List_Grow() } [Benchmark, BenchmarkCategory("Async")] + [SuppressMessage("Roslynator", "RCS1261:Resource can be disposed asynchronously", Justification = SuppressionReasons.SyncDispose)] public async ValueTask Async_List_ToArray() { using DataTableReader reader = _table.CreateDataReader(); @@ -225,6 +225,7 @@ public async ValueTask Async_List_ToArray() } [Benchmark, BenchmarkCategory("Async")] + [SuppressMessage("Roslynator", "RCS1261:Resource can be disposed asynchronously", Justification = SuppressionReasons.SyncDispose)] public async ValueTask> Async_Builder_ToImmutable() { using DataTableReader reader = _table.CreateDataReader(); @@ -234,6 +235,7 @@ public async ValueTask> Async_Builder_ToImmutable() } [Benchmark, BenchmarkCategory("Async")] + [SuppressMessage("Roslynator", "RCS1261:Resource can be disposed asynchronously", Justification = SuppressionReasons.SyncDispose)] public async ValueTask> Async_RawChain_ToList() { using DataTableReader reader = _table.CreateDataReader(); @@ -241,7 +243,6 @@ public async ValueTask> Async_RawChain_ToList() while (await reader.ReadAsync().ConfigureAwait(false)) chain.Add(_read(reader)); return chain.ToList(); } -#pragma warning restore RCS1261 // The reader is the caller's: disposed when the terminal is done. static async ValueTask Finish(DataTableReader reader, ValueTask terminal) @@ -272,19 +273,32 @@ static async ValueTask Finish(DataTableReader reader, ValueTas nameof(Async_Builder_ToImmutable) => Async_Builder_ToImmutable().AsTask().GetAwaiter().GetResult(), _ => throw new ArgumentException(variant, nameof(variant)), }; +} -#pragma warning disable RCS1158 // The checks read the variant names of every T from one place, beside the benchmarks they name. - internal static readonly string[] Variants = +/// The names of every variant of the copy-out benchmarks, for the checks. +static class CopyOutVariants +{ + public static readonly string[] Names = [ - nameof(Sync_Chain_ToList), nameof(Sync_Chain_ToArray), nameof(Sync_Chain_ToImmutableArray), - nameof(Sync_List_Grow), nameof(Sync_List_ToArray), nameof(Sync_Builder_ToImmutable), - nameof(Sync_RawChain_ToList), nameof(Sync_RawChain_ToArray), nameof(Sync_RawChain_ToImmutableArray), - nameof(Sync_Scratch_ToList), nameof(Sync_Scratch_ToArray), - nameof(Async_RawChain_ToList), - nameof(Async_Chain_ToList), nameof(Async_Chain_ToArray), nameof(Async_Chain_ToImmutableArray), - nameof(Async_List_Grow), nameof(Async_List_ToArray), nameof(Async_Builder_ToImmutable), + nameof(CopyOutCollectorBenchmarks<>.Sync_Chain_ToList), + nameof(CopyOutCollectorBenchmarks<>.Sync_Chain_ToArray), + nameof(CopyOutCollectorBenchmarks<>.Sync_Chain_ToImmutableArray), + nameof(CopyOutCollectorBenchmarks<>.Sync_List_Grow), + nameof(CopyOutCollectorBenchmarks<>.Sync_List_ToArray), + nameof(CopyOutCollectorBenchmarks<>.Sync_Builder_ToImmutable), + nameof(CopyOutCollectorBenchmarks<>.Sync_RawChain_ToList), + nameof(CopyOutCollectorBenchmarks<>.Sync_RawChain_ToArray), + nameof(CopyOutCollectorBenchmarks<>.Sync_RawChain_ToImmutableArray), + nameof(CopyOutCollectorBenchmarks<>.Sync_Scratch_ToList), + nameof(CopyOutCollectorBenchmarks<>.Sync_Scratch_ToArray), + nameof(CopyOutCollectorBenchmarks<>.Async_RawChain_ToList), + nameof(CopyOutCollectorBenchmarks<>.Async_Chain_ToList), + nameof(CopyOutCollectorBenchmarks<>.Async_Chain_ToArray), + nameof(CopyOutCollectorBenchmarks<>.Async_Chain_ToImmutableArray), + nameof(CopyOutCollectorBenchmarks<>.Async_List_Grow), + nameof(CopyOutCollectorBenchmarks<>.Async_List_ToArray), + nameof(CopyOutCollectorBenchmarks<>.Async_Builder_ToImmutable), ]; -#pragma warning restore RCS1158 } /// A row with no references: 16 bytes. diff --git a/Benchmarks/Open.Database.Extensions.Benchmarks/OneRowChecks.cs b/Benchmarks/Open.Database.Extensions.Benchmarks/OneRowChecks.cs index 4fa3fb7b..05137d24 100644 --- a/Benchmarks/Open.Database.Extensions.Benchmarks/OneRowChecks.cs +++ b/Benchmarks/Open.Database.Extensions.Benchmarks/OneRowChecks.cs @@ -22,7 +22,7 @@ static int Run(Func create, Func key) try { object expected = key((T)bench.Run(nameof(OneRowLookupBenchmarks<>.Sync_Hand_One))!); - foreach (string variant in OneRowLookupBenchmarks.Variants) + foreach (string variant in OneRowVariants.Names) { for (int attempt = 0; attempt < 2; attempt++) { diff --git a/Benchmarks/Open.Database.Extensions.Benchmarks/OneRowLookupBenchmarks.cs b/Benchmarks/Open.Database.Extensions.Benchmarks/OneRowLookupBenchmarks.cs index f0168ef5..08d579da 100644 --- a/Benchmarks/Open.Database.Extensions.Benchmarks/OneRowLookupBenchmarks.cs +++ b/Benchmarks/Open.Database.Extensions.Benchmarks/OneRowLookupBenchmarks.cs @@ -1,4 +1,5 @@ using System.Data; +using System.Diagnostics.CodeAnalysis; using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; @@ -123,8 +124,8 @@ public T Sync_Single_One() // ---- asynchronous ----------------------------------------------------- -#pragma warning disable RCS1261 // The synchronous dispose of the reader is part of what these benchmarks measure; await using would change the published numbers. [Benchmark(Baseline = true), BenchmarkCategory("Async")] + [SuppressMessage("Roslynator", "RCS1261:Resource can be disposed asynchronously", Justification = SuppressionReasons.SyncDispose)] public async ValueTask Async_Hand_One() { using DataTableReader reader = _one.CreateDataReader(); @@ -132,6 +133,7 @@ public async ValueTask Async_Hand_One() } [Benchmark, BenchmarkCategory("Async")] + [SuppressMessage("Roslynator", "RCS1261:Resource can be disposed asynchronously", Justification = SuppressionReasons.SyncDispose)] public async ValueTask Async_Hand_Single_One() { using DataTableReader reader = _one.CreateDataReader(); @@ -142,6 +144,7 @@ public async ValueTask Async_Hand_Single_One() } [Benchmark, BenchmarkCategory("Async")] + [SuppressMessage("Roslynator", "RCS1261:Resource can be disposed asynchronously", Justification = SuppressionReasons.SyncDispose)] public async ValueTask Async_First_One() { using DataTableReader reader = _one.CreateDataReader(); @@ -149,6 +152,7 @@ public async ValueTask Async_First_One() } [Benchmark, BenchmarkCategory("Async")] + [SuppressMessage("Roslynator", "RCS1261:Resource can be disposed asynchronously", Justification = SuppressionReasons.SyncDispose)] public async ValueTask Async_First_Many() { using DataTableReader reader = _many.CreateDataReader(); @@ -156,6 +160,7 @@ public async ValueTask Async_First_Many() } [Benchmark, BenchmarkCategory("Async")] + [SuppressMessage("Roslynator", "RCS1261:Resource can be disposed asynchronously", Justification = SuppressionReasons.SyncDispose)] public async ValueTask Async_FirstOrDefault_One() { using DataTableReader reader = _one.CreateDataReader(); @@ -163,6 +168,7 @@ public async ValueTask Async_First_Many() } [Benchmark, BenchmarkCategory("Async")] + [SuppressMessage("Roslynator", "RCS1261:Resource can be disposed asynchronously", Justification = SuppressionReasons.SyncDispose)] public async ValueTask Async_FirstOrDefault_Many() { using DataTableReader reader = _many.CreateDataReader(); @@ -170,6 +176,7 @@ public async ValueTask Async_First_Many() } [Benchmark, BenchmarkCategory("Async")] + [SuppressMessage("Roslynator", "RCS1261:Resource can be disposed asynchronously", Justification = SuppressionReasons.SyncDispose)] public async ValueTask Async_Single_One() { using DataTableReader reader = _one.CreateDataReader(); @@ -177,12 +184,12 @@ public async ValueTask Async_Single_One() } [Benchmark, BenchmarkCategory("Async")] + [SuppressMessage("Roslynator", "RCS1261:Resource can be disposed asynchronously", Justification = SuppressionReasons.SyncDispose)] public async ValueTask Async_SingleOrDefault_One() { using DataTableReader reader = _one.CreateDataReader(); return await reader.Map(_read).SingleOrDefaultAsync().ConfigureAwait(false); } -#pragma warning restore RCS1261 // The same calls, for the checks: every variant by name. internal object? Run(string variant) => variant switch @@ -205,16 +212,30 @@ public async ValueTask Async_Single_One() nameof(Async_SingleOrDefault_One) => Async_SingleOrDefault_One().AsTask().GetAwaiter().GetResult(), _ => throw new ArgumentException(variant, nameof(variant)), }; +} -#pragma warning disable RCS1158 // The checks read the variant names of every T from one place, beside the benchmarks they name. - internal static readonly string[] Variants = +/// The names of every variant of the one-row benchmarks, for the checks. +static class OneRowVariants +{ + public static readonly string[] Names = [ - nameof(Sync_Hand_One), nameof(Sync_Hand_Single_One), nameof(Sync_First_One), nameof(Sync_First_Many), - nameof(Sync_FirstOrDefault_One), nameof(Sync_FirstOrDefault_Many), nameof(Sync_Single_One), nameof(Sync_SingleOrDefault_One), - nameof(Async_Hand_One), nameof(Async_Hand_Single_One), nameof(Async_First_One), nameof(Async_First_Many), - nameof(Async_FirstOrDefault_One), nameof(Async_FirstOrDefault_Many), nameof(Async_Single_One), nameof(Async_SingleOrDefault_One), + nameof(OneRowLookupBenchmarks<>.Sync_Hand_One), + nameof(OneRowLookupBenchmarks<>.Sync_Hand_Single_One), + nameof(OneRowLookupBenchmarks<>.Sync_First_One), + nameof(OneRowLookupBenchmarks<>.Sync_First_Many), + nameof(OneRowLookupBenchmarks<>.Sync_FirstOrDefault_One), + nameof(OneRowLookupBenchmarks<>.Sync_FirstOrDefault_Many), + nameof(OneRowLookupBenchmarks<>.Sync_Single_One), + nameof(OneRowLookupBenchmarks<>.Sync_SingleOrDefault_One), + nameof(OneRowLookupBenchmarks<>.Async_Hand_One), + nameof(OneRowLookupBenchmarks<>.Async_Hand_Single_One), + nameof(OneRowLookupBenchmarks<>.Async_First_One), + nameof(OneRowLookupBenchmarks<>.Async_First_Many), + nameof(OneRowLookupBenchmarks<>.Async_FirstOrDefault_One), + nameof(OneRowLookupBenchmarks<>.Async_FirstOrDefault_Many), + nameof(OneRowLookupBenchmarks<>.Async_Single_One), + nameof(OneRowLookupBenchmarks<>.Async_SingleOrDefault_One), ]; -#pragma warning restore RCS1158 } /// A row that is a class with a string. diff --git a/Benchmarks/Open.Database.Extensions.Benchmarks/SuppressionReasons.cs b/Benchmarks/Open.Database.Extensions.Benchmarks/SuppressionReasons.cs new file mode 100644 index 00000000..b7a896ba --- /dev/null +++ b/Benchmarks/Open.Database.Extensions.Benchmarks/SuppressionReasons.cs @@ -0,0 +1,16 @@ +namespace Open.Database.Extensions.Benchmarks; + +/// +/// The reasons a benchmark suppresses an analyzer finding in source, each +/// written once. +/// +static class SuppressionReasons +{ + /// + /// A benchmark that disposes its reader with a plain using, because the + /// published numbers measure that call. + /// + public const string SyncDispose + = "The synchronous dispose of the reader is part of what this benchmark " + + "measures; await using would change the published numbers."; +} diff --git a/Tests/Open.Database.Extensions.Core.Tests/CaptureStreamTests.cs b/Tests/Open.Database.Extensions.Core.Tests/CaptureStreamTests.cs index df4164b1..921a548a 100644 --- a/Tests/Open.Database.Extensions.Core.Tests/CaptureStreamTests.cs +++ b/Tests/Open.Database.Extensions.Core.Tests/CaptureStreamTests.cs @@ -5,8 +5,6 @@ namespace Open.Database.Extensions.Tests; -#pragma warning disable RCS1021 // A block body keeps the lambda an Action: an expression body binds Assert.Throws to its Func overload, which xUnit rejects. - // The captures on the stream paths (Stream, StreamBuffered, the pooled // streams and buffer), on the Channel and Dataflow members, and on the edges: // a failed run, a stall, a cancel mid-read, a command that re-implements its @@ -547,6 +545,7 @@ await Assert.ThrowsAsync( // A canceled token throws at the call, before the stream exists: nothing // is armed, and awaiting the capture throws instead of waiting. [Fact] + [SuppressMessage("Roslynator", "RCS1021:Use expression-bodied lambda", Justification = SuppressionReasons.DiscardLambda)] public static async Task ACanceledToken_ThrowsAtTheCall_AndArmsNothing() { var c = new CaptureConnection(("total", 9)); @@ -776,6 +775,7 @@ await Assert.ThrowsAsync( // The synchronous refusal comes first, so it keeps its message. [Fact] + [SuppressMessage("Roslynator", "RCS1021:Use expression-bodied lambda", Justification = SuppressionReasons.DiscardLambda)] public static void ACommandCapture_OnAReimplementingCommand_RefusesSync() { var c = new CaptureConnection(("total", 9)); diff --git a/Tests/Open.Database.Extensions.Core.Tests/CaptureTests.cs b/Tests/Open.Database.Extensions.Core.Tests/CaptureTests.cs index 299be65b..903c3269 100644 --- a/Tests/Open.Database.Extensions.Core.Tests/CaptureTests.cs +++ b/Tests/Open.Database.Extensions.Core.Tests/CaptureTests.cs @@ -5,8 +5,6 @@ namespace Open.Database.Extensions.Tests; -#pragma warning disable RCS1021 // A block body keeps the lambda an Action: an expression body binds Assert.Throws to its Func overload, which xUnit rejects. - // The captures (CaptureOutput, CaptureOutputDecimal, CaptureReturn) on a // command and on a mapped query, over a provider that records its // parameters, fills the outputs when it executes, and can hold an execution @@ -177,6 +175,7 @@ public static async Task AnyAsyncAndCountAsync_OnACommand_FillIt() } [Fact] + [SuppressMessage("Roslynator", "RCS1021:Use expression-bodied lambda", Justification = SuppressionReasons.DiscardLambda)] public static void ASynchronousTerminal_Throws_AndArmsNothing() { var c = new CaptureConnection(("total", 5)); @@ -246,6 +245,7 @@ await Assert.ThrowsAsync( // Its argument and shape guards throw at the call, before the refusal: // nothing is armed, and the capture says it has not started. [Fact] + [SuppressMessage("Roslynator", "RCS1021:Use expression-bodied lambda", Justification = SuppressionReasons.DiscardLambda)] public static async Task ExecuteOutputAsync_WithABadArgument_ArmsNothing() { var c = new CaptureConnection(("total", 5)); @@ -279,6 +279,7 @@ await Assert.ThrowsAsync( // A guard inside an async method faults the task and arms nothing: the // capture says it has not started, and never waits. [Fact] + [SuppressMessage("Roslynator", "RCS1021:Use expression-bodied lambda", Justification = SuppressionReasons.DiscardLambda)] public static async Task ExecuteScalarAsync_WithANullTransform_ArmsNothing() { var c = new CaptureConnection(("total", 5)); @@ -606,6 +607,7 @@ public static async Task EveryBuilder_CarriesIt_AndItIsPartOfTheEquality() } [Fact] + [SuppressMessage("Roslynator", "RCS1021:Use expression-bodied lambda", Justification = SuppressionReasons.DiscardLambda)] public static async Task ASynchronousTerminal_OnAQuery_Throws_AndArmsNothing() { var c = new CaptureConnection(("total", 9)); @@ -690,6 +692,7 @@ public static async Task ItIsArmedAtTheCall_SoItCanBeAwaitedBeforeTheTerminal() } [Fact] + [SuppressMessage("Roslynator", "RCS1021:Use expression-bodied lambda", Justification = SuppressionReasons.DiscardLambda)] public static void BeforeTheTerminal_EveryMemberThrows() { var c = new CaptureConnection(); @@ -706,6 +709,7 @@ public static void BeforeTheTerminal_EveryMemberThrows() } [Fact] + [SuppressMessage("Roslynator", "RCS1021:Use expression-bodied lambda", Justification = SuppressionReasons.DiscardLambda)] public static void ADefaultValue_EveryMemberThrows() { DbCapture none = default; @@ -1042,6 +1046,7 @@ await Assert.ThrowsAsync( } [Fact] + [SuppressMessage("Roslynator", "RCS1021:Use expression-bodied lambda", Justification = SuppressionReasons.DiscardLambda)] public static async Task ALateCommandCapture_ThatConflicts_ThrowsAtTheTerminal() { var c = new CaptureConnection(("total", 9)); @@ -1131,6 +1136,7 @@ public static async Task ACommandCapture_AddedAfterTheStreamIsMade_IsNotFilled( Assert.Equal(9, await total); } + [SuppressMessage("Roslynator", "RCS1021:Use expression-bodied lambda", Justification = SuppressionReasons.DiscardLambda)] static void AssertNotFilled(CaptureConnection c, DbCapture late) { Assert.DoesNotContain( diff --git a/Tests/Open.Database.Extensions.Core.Tests/NameCacheSourceTests.cs b/Tests/Open.Database.Extensions.Core.Tests/NameCacheSourceTests.cs index 36861110..b9327488 100644 --- a/Tests/Open.Database.Extensions.Core.Tests/NameCacheSourceTests.cs +++ b/Tests/Open.Database.Extensions.Core.Tests/NameCacheSourceTests.cs @@ -370,8 +370,7 @@ public static async Task TwoCommands_FromOneLegacySqlServerFunction_ReadTheNames long first = trips.Take(); await RunAsync(create.StoredProcedure(name)); long second = trips.Take(); - await RunAsync( - create.Command(name, CommandType.StoredProcedure)); + await RunAsync(create.Command(name, CommandType.StoredProcedure)); long third = trips.Take(); Assert.True(first > 0); @@ -562,8 +561,13 @@ public static void ANullFunction_IsRefused_BySqlServerExtensions() Assert.Equal("ArgumentNullException:factory", Refusal(() => MsExtensions.StoredProcedure((Func)null!, "proc"))); Assert.Equal("ArgumentNullException:factory", Refusal(() => MsExtensions.Command((Func)null!, "proc", CommandType.StoredProcedure))); #pragma warning disable CS0618 // System.Data.SqlClient is obsolete; it is one of the two packages under test - Assert.Equal("ArgumentNullException:factory", Refusal(() => ((Func)null!).StoredProcedure("proc"))); - Assert.Equal("ArgumentNullException:factory", Refusal(() => ((Func)null!).Command("proc", CommandType.StoredProcedure))); + Func none = null!; + Assert.Equal( + "ArgumentNullException:factory", + Refusal(() => none.StoredProcedure("proc"))); + Assert.Equal( + "ArgumentNullException:factory", + Refusal(() => none.Command("proc", CommandType.StoredProcedure))); #pragma warning restore CS0618 } } diff --git a/Tests/Open.Database.Extensions.Core.Tests/OutputParameterLocalDbTests.cs b/Tests/Open.Database.Extensions.Core.Tests/OutputParameterLocalDbTests.cs index cfd48c87..600f529a 100644 --- a/Tests/Open.Database.Extensions.Core.Tests/OutputParameterLocalDbTests.cs +++ b/Tests/Open.Database.Extensions.Core.Tests/OutputParameterLocalDbTests.cs @@ -5,8 +5,6 @@ namespace Open.Database.Extensions.Tests; -#pragma warning disable RCS1021 // A block body keeps the lambda an Action: an expression body binds Assert.Throws to its Func overload, which xUnit rejects. - // ExecuteOutputAsync() and its named form against SQL Server: one test per fact the design rests on (sizes, decimal scale, // datetime2, NULLs, the lost default, the return code, names known and forgotten, a text's markers, a later statement's error). // Skipped without LocalDB (see LocalDbFixture). @@ -396,6 +394,7 @@ public static async Task EachType_AsAModelMember_IsRead() // (1) Outputs only, one value by name: each type, and the nullable form of each value type. // ExecuteOutputAsync(name) throws (see TheDecimalForm_ReadsADecimal_ByItsPrecisionAndScale). [Fact] + [SuppressMessage("Roslynator", "RCS1021:Use expression-bodied lambda", Justification = SuppressionReasons.DiscardLambda)] public static async Task EachType_AsANamedValue_IsRead_ADecimalByItsPrecisionAndScale() { LocalDbFixture.SkipUnlessAvailable(); @@ -509,6 +508,7 @@ public static async Task AConversionFailure_OnTheServer_IsTheProvidersError() // (5) Canceled before: nothing runs. Canceled during: the server stops the procedure and the call is canceled. [Fact] + [SuppressMessage("Roslynator", "RCS1021:Use expression-bodied lambda", Justification = SuppressionReasons.DiscardLambda)] public static async Task Cancel_BeforeAndDuring() { LocalDbFixture.SkipUnlessAvailable(); @@ -538,6 +538,7 @@ public static async Task Cancel_BeforeAndDuring() // decimal(19,4) (bound with int literals); NULL is null in decimal? and an error in decimal; an InputOutput takes a value in and reads // the changed one; a precision or scale out of range, a shape on another type, and a decimal without a shape throw before the run. [Fact] + [SuppressMessage("Roslynator", "RCS1021:Use expression-bodied lambda", Justification = SuppressionReasons.DiscardLambda)] public static async Task TheDecimalForms_ReadADecimal_ByItsPrecisionAndScale() { LocalDbFixture.SkipUnlessAvailable(); diff --git a/Tests/Open.Database.Extensions.Core.Tests/OutputParameterTests.cs b/Tests/Open.Database.Extensions.Core.Tests/OutputParameterTests.cs index 7cb3aeb4..9126f230 100644 --- a/Tests/Open.Database.Extensions.Core.Tests/OutputParameterTests.cs +++ b/Tests/Open.Database.Extensions.Core.Tests/OutputParameterTests.cs @@ -442,13 +442,12 @@ public static async Task NullIsNull_InANullableMember_AndAnErrorInANonNullableOn // ---- what throws before anything runs ---------------------------------------------- // Each message names the member, parameter or type, says what is wrong, and gives the fix: the phrases are asserted. + [SuppressMessage("Roslynator", "RCS1021:Use expression-bodied lambda", Justification = SuppressionReasons.DiscardLambda)] static void ThrowsAtTheCall(Func call, params string[] phrases) where TException : Exception { var c = new OutputConnection(); -#pragma warning disable RCS1021 // A block body keeps the lambda an Action: an expression body binds Assert.Throws to its Func overload, which xUnit rejects. var ex = Assert.Throws(() => { _ = call(c); }); -#pragma warning restore RCS1021 foreach (string phrase in phrases) Assert.Contains(phrase, ex.Message); Assert.Null(c.Last); } diff --git a/Tests/Open.Database.Extensions.Core.Tests/TestHelpers/SuppressionReasons.cs b/Tests/Open.Database.Extensions.Core.Tests/TestHelpers/SuppressionReasons.cs new file mode 100644 index 00000000..092a42e0 --- /dev/null +++ b/Tests/Open.Database.Extensions.Core.Tests/TestHelpers/SuppressionReasons.cs @@ -0,0 +1,17 @@ +namespace Open.Database.Extensions.Tests; + +/// +/// The reasons a test suppresses an analyzer finding in source, each written +/// once. +/// +[ExcludeFromCodeCoverage] +internal static class SuppressionReasons +{ + /// + /// A lambda that discards the result of a call that throws, passed to + /// Assert.Throws. + /// + public const string DiscardLambda + = "A block body keeps the lambda an Action: an expression body is a " + + "Func, and xUnit rejects Assert.Throws with async code."; +} diff --git a/Tests/Open.Database.Extensions.Generator.Tests/ParityTests.NullStart.cs b/Tests/Open.Database.Extensions.Generator.Tests/ParityTests.NullStart.cs index 0ccb6877..6ba754a4 100644 --- a/Tests/Open.Database.Extensions.Generator.Tests/ParityTests.NullStart.cs +++ b/Tests/Open.Database.Extensions.Generator.Tests/ParityTests.NullStart.cs @@ -127,7 +127,7 @@ public sealed partial class NullStartPartial public sealed partial class NullStartPartial { -#pragma warning disable IDE0032, RCS1085 // Use auto property: the initialized backing field is the case under test. +#pragma warning disable IDE0032, RCS1085 // IDE0032 and RCS1085 ask for an auto-property: the initialized backing field is the case under test. int? _qty = 5; public partial int? Qty { get => _qty; set => _qty = value; } From 1ff9e22febd6915a9c6bbf157479657d697e75be Mon Sep 17 00:00:00 2001 From: electricessence <5899455+electricessence@users.noreply.github.com> Date: Fri, 4 Dec 2026 09:35:08 -0800 Subject: [PATCH 5/5] Put a blank line above the first constant of the suppression reason holders Co-Authored-By: Claude Sonnet 5.5 --- .../Open.Database.Extensions.Benchmarks/SuppressionReasons.cs | 1 + .../TestHelpers/SuppressionReasons.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/Benchmarks/Open.Database.Extensions.Benchmarks/SuppressionReasons.cs b/Benchmarks/Open.Database.Extensions.Benchmarks/SuppressionReasons.cs index b7a896ba..c38a45fa 100644 --- a/Benchmarks/Open.Database.Extensions.Benchmarks/SuppressionReasons.cs +++ b/Benchmarks/Open.Database.Extensions.Benchmarks/SuppressionReasons.cs @@ -6,6 +6,7 @@ namespace Open.Database.Extensions.Benchmarks; /// static class SuppressionReasons { + /// /// A benchmark that disposes its reader with a plain using, because the /// published numbers measure that call. diff --git a/Tests/Open.Database.Extensions.Core.Tests/TestHelpers/SuppressionReasons.cs b/Tests/Open.Database.Extensions.Core.Tests/TestHelpers/SuppressionReasons.cs index 092a42e0..0af88030 100644 --- a/Tests/Open.Database.Extensions.Core.Tests/TestHelpers/SuppressionReasons.cs +++ b/Tests/Open.Database.Extensions.Core.Tests/TestHelpers/SuppressionReasons.cs @@ -7,6 +7,7 @@ namespace Open.Database.Extensions.Tests; [ExcludeFromCodeCoverage] internal static class SuppressionReasons { + /// /// A lambda that discards the result of a call that throws, passed to /// Assert.Throws.