Skip to content

Commit

Permalink
Extended tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMpn committed Sep 27, 2023
1 parent 203ac33 commit 38fa3f1
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions MarkMpn.Sql4Cds.Engine.Tests/CteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,9 @@ UNION ALL
Assert.AreEqual(1, plans.Length);

var select = AssertNode<SelectNode>(plans[0]);
Assert.AreEqual("contactid", select.ColumnSet[0].OutputColumn);
Assert.AreEqual("firstname", select.ColumnSet[1].OutputColumn);
Assert.AreEqual("lastname", select.ColumnSet[2].OutputColumn);
var spoolProducer = AssertNode<IndexSpoolNode>(select.Source);
var concat = AssertNode<ConcatenateNode>(spoolProducer.Source);
var depth0 = AssertNode<ComputeScalarNode>(concat.Sources[0]);
Expand Down Expand Up @@ -577,6 +580,42 @@ UNION ALL
}
}

[TestMethod]
public void FactorialCalcFiltered()
{

using (var con = new Sql4CdsConnection(_localDataSource))
using (var cmd = con.CreateCommand())
{
cmd.CommandText = @"
WITH Factorial (N, Factorial) AS (
SELECT 1, 1
UNION ALL
SELECT N + 1, (N + 1) * Factorial FROM Factorial WHERE N < 5)
SELECT Factorial FROM Factorial WHERE N = 3";

Assert.AreEqual(6, cmd.ExecuteScalar());
}
}

[TestMethod]
public void FactorialCalcFilteredCaseInsensitive()
{
using (var con = new Sql4CdsConnection(_localDataSource))
using (var cmd = con.CreateCommand())
{
cmd.CommandText = @"
with factorial (N, Factorial) as (
select 1, 1
union all
select N + 1, (N + 1) * factorial from factorial where n < 10
)
select factorial from factorial where n = 3";

Assert.AreEqual(6, cmd.ExecuteScalar());
}
}

private T AssertNode<T>(IExecutionPlanNode node) where T : IExecutionPlanNode
{
Assert.IsInstanceOfType(node, typeof(T));
Expand Down

0 comments on commit 38fa3f1

Please sign in to comment.