Files
sql-utilities/tests/Strata.SqlTools.SqlBreakdown.Tests/ExpressionTests/ExpressionTestsBase.cs
T
Thom LambandClaude Opus 4.7 84b06557e5 chore(sonar)!: mark instance-data-free members static (CA1822)
Applied via `dotnet format analyzers --diagnostics CA1822 --severity info`.
12 files touched. The fixer also updated internal callers in tests to use
the type-name form (e.g. `gen.Method(x)` -> `Generator.Method(x)`); build
and full test suite remain green.

BREAKING CHANGE: two public methods become static and therefore can no
longer be invoked through an instance reference by external consumers:
- Strata.SqlTools.Markdown.LinqToSql.QueryBreakdownGenerator.GenerateMethodChainDiagram
- Strata.SqlTools.Markdown.LinqToSql.SqlStatementGenerator.GenerateLinqPipelineDiagram

Both are stateless utility methods on Generator classes — the static form
is the correct shape; the only callers in this repo already used the
type-name form. External code should change `gen.GenerateMethodChainDiagram(...)`
to `QueryBreakdownGenerator.GenerateMethodChainDiagram(...)`.

All other CA1822 hits in this commit are on private/protected members
(no public-surface impact).

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

73 lines
2.9 KiB
C#

using Strata.SqlTools.SqlBreakdown.Classes;
using Strata.SqlTools.SqlBreakdown.Expressions;
using Strata.SqlTools.SqlBreakdown.Expressions.Conditional;
using Strata.SqlTools.Query;
using Strata.SqlTools.SqlBreakdown.Tests.RegisteredTables;
using Strata.SqlTools.Visitors.Snowflake;
using ExpressionFactoryBase = Strata.SqlTools.SqlServer.ExpressionFactory.ExpressionFactory;
namespace Strata.SqlTools.SqlBreakdown.Tests.ExpressionTests;
/// <summary>
/// Test implementation of ExpressionFactory for unit testing.
/// Uses July 1 as the fiscal year start date.
/// </summary>
internal class TestExpressionFactory : ExpressionFactoryBase
{
protected override DateTime GetCurrentFiscalYearStart()
{
return new DateTime(DateTime.UtcNow.Year, 7, 1, 0, 0, 0, DateTimeKind.Utc);
}
protected override RegisteredTableColumnExpression GetColumnExpression(int dataColumnId)
{
return RegisteredTableColumns.GetColumn(dataColumnId);
}
// Public wrappers for testing protected methods
public new BooleanExpression CreateBooleanExpression(Filter filter) => base.CreateBooleanExpression(filter);
public static new Expression GetFiscalYearMonthExpression(Expression dateColumnExpr, int fiscalYearStartMonth, int fiscalYearStartDay)
=> ExpressionFactoryBase.GetFiscalYearMonthExpression(dateColumnExpr, fiscalYearStartMonth, fiscalYearStartDay);
}
/// <summary>
/// Base class for expression tests with common setup.
/// </summary>
public abstract class ExpressionTestsBase
{
protected RegisteredTableSource _table = null!;
protected RegisteredTableColumnExpression _nameColumnExp = null!;
protected RegisteredTableColumnExpression _revenueColumnExp = null!;
protected RegisteredTableColumnExpression _costColumnExp = null!;
protected RegisteredTableColumnExpression _dischargeDateColumnExp = null!;
protected CommandVisitor _sqlVisitor = null!;
[SetUp]
public void SetUp()
{
_table = new RegisteredTableSource(101, "CLIENT_DSS", "FACT_PATIENT_ENCOUNTER_SUMMARY", "PES");
_nameColumnExp = new RegisteredTableColumnExpression(1, "DEPARTMENT_NAME", _table);
_revenueColumnExp = new RegisteredTableColumnExpression(2, "NET_REVENUE", _table);
_costColumnExp = new RegisteredTableColumnExpression(3, "COST", _table);
_dischargeDateColumnExp = new RegisteredTableColumnExpression(4, "DISCHARGE_DATE", _table);
_sqlVisitor = new CommandVisitor();
}
/// <summary>
/// Executes an expression test case with arrange, act, and assert phases.
/// </summary>
/// <param name="testCase">The test case to execute.</param>
protected static void ExecuteExpressionTest(ExpressionTestCase testCase)
{
// Arrange
var visitor = new CommandVisitor();
var arrange = testCase.Arrange;
// Act
var result = testCase.Act(arrange, visitor);
// Assert
Assert.That(testCase.Assertions(result));
}
}