This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
using Strata.SqlTools.SqlBreakdown.Classes;
|
||||
using Strata.SqlTools.SqlBreakdown.Expressions;
|
||||
|
||||
namespace Strata.SqlTools.SqlBreakdown.Tests.ExpressionTests;
|
||||
|
||||
[TestFixture]
|
||||
public class DateFunctionTests : ExpressionTestsBase
|
||||
{
|
||||
private static IEnumerable<TestCaseData> DateFunctionTestCases()
|
||||
{
|
||||
var testCases = new[]
|
||||
{
|
||||
new ExpressionTestCase
|
||||
{
|
||||
Name = "GetFiscalYearMonthExpression_{m}",
|
||||
Arrange = new Dictionary<string, Expression>
|
||||
{
|
||||
["dischargeDate"] = new RegisteredTableColumnExpression(4, "DISCHARGE_DATE", new RegisteredTableSource(101, "CLIENT_DSS", "DEPT", "PES"))
|
||||
},
|
||||
Act = (columns, visitor) =>
|
||||
{
|
||||
var dischargeDate = columns["dischargeDate"];
|
||||
var fiscal = TestExpressionFactory.GetFiscalYearMonthExpression(dischargeDate, 7, 1);
|
||||
return fiscal.Accept(visitor);
|
||||
},
|
||||
Assertions = result =>
|
||||
{
|
||||
var sql = (string)result;
|
||||
Assert.That(sql, Is.Not.Null);
|
||||
Assert.That(sql.Length, Is.GreaterThan(0));
|
||||
Assert.That(sql, Is.EqualTo("DATE_TRUNC('month', DATEADD('month', 6, PES.DISCHARGE_DATE))"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
foreach (var testCase in testCases)
|
||||
{
|
||||
yield return new TestCaseData(testCase).SetName(testCase.Name);
|
||||
}
|
||||
}
|
||||
|
||||
[TestCaseSource(nameof(DateFunctionTestCases))]
|
||||
public void DateFunction_GeneratesCorrectSql(ExpressionTestCase testCase)
|
||||
=> ExecuteExpressionTest(testCase);
|
||||
}
|
||||
Reference in New Issue
Block a user