Files
sql-utilities/tests/Strata.SqlTools.SqlBreakdown.Tests/ExpressionTests/ExpressionObjectTests.cs
T
Thom LambandClaude Opus 4.7 f5d539b906 chore(sonar): hoist constant array literals to static readonly fields (CA1861)
Applied via `dotnet format analyzers --diagnostics CA1861 --severity info`,
plus manual cleanup:

- Renamed two cryptic fixer-generated field names:
  - QueryBreakdownCollection.stringArray -> SnowflakeFunctionNames (and
    inlined the now-redundant local alias)
  - ExpressionObjectTests.arg2 -> NotInValues
- Deduped three identical `separator = ['\r','\n']` fields the fixer
  emitted in the same test class (kept the first declaration; the other
  two test methods now reuse it).

8 files touched.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 15:45:16 -05:00

75 lines
3.0 KiB
C#

using Strata.SqlTools.SqlBreakdown.Expressions;
using Strata.SqlTools.SqlBreakdown.Expressions.Conditional;
using Strata.SqlTools.SqlBreakdown.Expressions.Conditional.Comparisons;
namespace Strata.SqlTools.SqlBreakdown.Tests.ExpressionTests;
[TestFixture]
public class ExpressionObjectTests : ExpressionTestsBase
{
[Test]
public void RegisteredTableColumnExpression_CreatesWithProperties()
{
// Arrange & Act
var columnExp = new RegisteredTableColumnExpression(5, "TEST_COLUMN", _table);
// Assert
Assert.That(columnExp, Is.Not.Null);
Assert.That(columnExp.ColumnName, Is.EqualTo("TEST_COLUMN"));
}
[Test]
public void ParameterExpression_CreatesWithName()
{
// Arrange & Act
var paramExp = new ParameterExpression("MY_PARAM");
// Assert
Assert.That(paramExp, Is.Not.Null);
Assert.That(paramExp.ParameterName, Is.EqualTo("MY_PARAM"));
}
private static readonly string[] NotInValues = new[] { "value1", "value2", "value3" };
private static IEnumerable<TestCaseData> ComparisonExpressionTestCases()
{
yield return new TestCaseData("GreaterThanOrEqual", 250, typeof(GreaterThanOrEqualToExpression))
.SetName("GreaterThanOrEqual_{m}");
yield return new TestCaseData("LessThan", 1000, typeof(LessThanExpression))
.SetName("LessThan_{m}");
yield return new TestCaseData("Equals", "TestDept", typeof(EqualToExpression))
.SetName("Equals_{m}");
yield return new TestCaseData("NotIn", NotInValues, typeof(NotInExpression))
.SetName("NotIn_{m}");
yield return new TestCaseData("Like", "%pattern%", typeof(LikeExpression))
.SetName("Like_{m}");
yield return new TestCaseData("Between", new object[] { 0, 5000 }, typeof(BetweenExpression))
.SetName("Between_{m}");
}
[TestCaseSource(nameof(ComparisonExpressionTestCases))]
public void ComparisonExpression_CreatesExpression(string expressionType, object testValue, Type expectedType)
{
// Arrange & Act
BooleanExpression expression = expressionType switch
{
"GreaterThanOrEqual" => new GreaterThanOrEqualToExpression(_costColumnExp, (int)testValue),
"LessThan" => new LessThanExpression(_revenueColumnExp, (int)testValue),
"Equals" => new EqualToExpression(_nameColumnExp, (string)testValue),
"NotIn" => new NotInExpression(_nameColumnExp, ((string[])testValue).Select(v => (Expression)v).ToArray()),
"Like" => new LikeExpression(_nameColumnExp, (string)testValue),
"Between" => new BetweenExpression(_revenueColumnExp, (Expression)(int)((object[])testValue)[0], (Expression)(int)((object[])testValue)[1]),
_ => throw new ArgumentException($"Unknown expression type: {expressionType}")
};
// Assert
Assert.That(expression, Is.Not.Null);
Assert.That(expression, Is.TypeOf(expectedType));
}
}