Skip to content

Commit b5615a0

Browse files
Add test for proper binding placement
1 parent c832c52 commit b5615a0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

QueryBuilder.Tests/GeneralTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,5 +478,28 @@ public void AdHoc_TwoRows()
478478
Assert.Equal("WITH \"ROWS\" AS (SELECT 1 AS a, 2 AS b, 3 AS c FROM RDB$DATABASE UNION ALL SELECT 4 AS a, 5 AS b, 6 AS c FROM RDB$DATABASE)\nSELECT * FROM \"ROWS\"", c[EngineCodes.Firebird].ToString());
479479
Assert.Equal("WITH \"rows\" AS (SELECT 1 AS a, 2 AS b, 3 AS c FROM DUAL UNION ALL SELECT 4 AS a, 5 AS b, 6 AS c FROM DUAL)\nSELECT * FROM \"rows\"", c[EngineCodes.Oracle].ToString());
480480
}
481+
482+
[Fact]
483+
public void AdHoc_ProperBindingsPlacement()
484+
{
485+
var query = new Query("rows")
486+
.With("othercte", q => q.From("othertable").Where("othertable.status", "A"))
487+
.Where("rows.foo", "bar")
488+
.With("rows",
489+
new[] { "a", "b", "c" },
490+
new object[][] {
491+
new object[] { 1, 2, 3 },
492+
new object[] { 4, 5, 6 },
493+
})
494+
.Where("rows.baz", "buzz");
495+
496+
var c = Compilers.Compile(query);
497+
498+
Assert.Equal(string.Join("\n", new[] {
499+
"WITH [othercte] AS (SELECT * FROM [othertable] WHERE [othertable].[status] = 'A'),",
500+
"[rows] AS (SELECT 1 AS a, 2 AS b, 3 AS c UNION ALL SELECT 4 AS a, 5 AS b, 6 AS c)",
501+
"SELECT * FROM [rows] WHERE [rows].[foo] = 'bar' AND [rows].[baz] = 'buzz'",
502+
}), c[EngineCodes.SqlServer].ToString());
503+
}
481504
}
482505
}

0 commit comments

Comments
 (0)