Resolves SonarQube NUnit2045. The three independent parameter-index assertions now report together instead of short-circuiting on the first failure. The Is.Not.Null guard in the reflection helper stays outside the multiple block because it gates the subsequent Invoke. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
37 lines
1.4 KiB
C#
37 lines
1.4 KiB
C#
using Strata.SqlTools.Visitors.PostgreSql;
|
|
|
|
namespace Strata.SqlTools.SqlBreakdown.Tests.PostgreSql;
|
|
|
|
[TestFixture]
|
|
public class CommandVisitorTests
|
|
{
|
|
[Test]
|
|
public void TwoVisitors_HaveIndependentParameterIndices()
|
|
{
|
|
var visitor1 = new CommandVisitor();
|
|
var visitor2 = new CommandVisitor();
|
|
|
|
var param1a = InvokeFormatParameterName(visitor1, "p");
|
|
var param1b = InvokeFormatParameterName(visitor1, "p");
|
|
var param2a = InvokeFormatParameterName(visitor2, "p");
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(param1a, Is.EqualTo("$1"), "first visitor's first parameter should be $1");
|
|
Assert.That(param1b, Is.EqualTo("$2"), "first visitor's second parameter should be $2");
|
|
Assert.That(param2a, Is.EqualTo("$1"), "second visitor must start at $1, not inherit visitor1's counter");
|
|
});
|
|
}
|
|
|
|
private static string InvokeFormatParameterName(CommandVisitor visitor, string name)
|
|
{
|
|
var method = typeof(CommandVisitor).GetMethod(
|
|
"FormatParameterName",
|
|
System.Reflection.BindingFlags.Instance
|
|
| System.Reflection.BindingFlags.NonPublic
|
|
| System.Reflection.BindingFlags.Public);
|
|
Assert.That(method, Is.Not.Null, "FormatParameterName must exist as a protected override on CommandVisitor");
|
|
return (string)method!.Invoke(visitor, new object[] { name })!;
|
|
}
|
|
}
|