Skip to content

Commit 27f5dc4

Browse files
committed
Create tests for grouped filters
1 parent 97e2acb commit 27f5dc4

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

QueryBuilder.Tests/WhereTests.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using SqlKata.Compilers;
2+
using SqlKata.Tests.Infrastructure;
3+
using Xunit;
4+
5+
namespace SqlKata.Tests
6+
{
7+
public class WhereTests : TestSupport
8+
{
9+
[Fact]
10+
public void GroupedWhereFilters()
11+
{
12+
var q = new Query("Table1")
13+
.Where(q => q.Or().Where("Column1", 10).Or().Where("Column2", 20))
14+
.Where("Column3", 30);
15+
16+
var c = Compile(q);
17+
18+
Assert.Equal(@"SELECT * FROM ""Table1"" WHERE (""Column1"" = 10 OR ""Column2"" = 20) AND ""Column3"" = 30", c[EngineCodes.PostgreSql]);
19+
}
20+
21+
[Fact]
22+
public void GroupedHavingFilters()
23+
{
24+
var q = new Query("Table1")
25+
.Having(q => q.Or().HavingRaw("SUM([Column1]) = ?", 10).Or().HavingRaw("SUM([Column2]) = ?", 20))
26+
.HavingRaw("SUM([Column3]) = ?", 30);
27+
28+
var c = Compile(q);
29+
30+
Assert.Equal(@"SELECT * FROM ""Table1"" HAVING (SUM(""Column1"") = 10 OR SUM(""Column2"") = 20) AND SUM(""Column3"") = 30", c[EngineCodes.PostgreSql]);
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)