-
-
Notifications
You must be signed in to change notification settings - Fork 510
/
Copy pathAggregateTests.cs
92 lines (68 loc) · 2.69 KB
/
AggregateTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using SqlKata.Compilers;
using SqlKata.Tests.Infrastructure;
using Xunit;
namespace SqlKata.Tests
{
public class AggregateTests : TestSupport
{
[Fact]
public void Count()
{
var query = new Query("A").AsCount();
var c = Compile(query);
Assert.Equal("SELECT COUNT(*) AS [count] FROM [A]", c[EngineCodes.SqlServer]);
Assert.Equal("SELECT COUNT(*) AS `count` FROM `A`", c[EngineCodes.MySql]);
Assert.Equal("SELECT COUNT(*) AS \"count\" FROM \"A\"", c[EngineCodes.PostgreSql]);
Assert.Equal("SELECT COUNT(*) AS \"COUNT\" FROM \"A\"", c[EngineCodes.Firebird]);
}
[Fact]
public void CountMultipleColumns()
{
var query = new Query("A").AsCount(new[] { "ColumnA", "ColumnB" });
var c = Compile(query);
Assert.Equal("SELECT COUNT(*) AS [count] FROM (SELECT 1 FROM [A] WHERE [ColumnA] IS NOT NULL AND [ColumnB] IS NOT NULL) AS [countQuery]", c[EngineCodes.SqlServer]);
}
[Fact]
public void DistinctCount()
{
var query = new Query("A").Distinct().AsCount();
var c = Compile(query);
Assert.Equal("SELECT COUNT(*) AS [count] FROM (SELECT DISTINCT * FROM [A]) AS [countQuery]", c[EngineCodes.SqlServer]);
}
[Fact]
public void DistinctCountMultipleColumns()
{
var query = new Query("A").Distinct().AsCount(new[] { "ColumnA", "ColumnB" });
var c = Compile(query);
Assert.Equal("SELECT COUNT(*) AS [count] FROM (SELECT DISTINCT [ColumnA], [ColumnB] FROM [A]) AS [countQuery]", c[EngineCodes.SqlServer]);
}
[Fact]
public void Average()
{
var query = new Query("A").AsAverage("TTL");
var c = Compile(query);
Assert.Equal("SELECT AVG([TTL]) AS [avg] FROM [A]", c[EngineCodes.SqlServer]);
}
[Fact]
public void Sum()
{
var query = new Query("A").AsSum("PacketsDropped");
var c = Compile(query);
Assert.Equal("SELECT SUM([PacketsDropped]) AS [sum] FROM [A]", c[EngineCodes.SqlServer]);
}
[Fact]
public void Max()
{
var query = new Query("A").AsMax("LatencyMs");
var c = Compile(query);
Assert.Equal("SELECT MAX([LatencyMs]) AS [max] FROM [A]", c[EngineCodes.SqlServer]);
}
[Fact]
public void Min()
{
var query = new Query("A").AsMin("LatencyMs");
var c = Compile(query);
Assert.Equal("SELECT MIN([LatencyMs]) AS [min] FROM [A]", c[EngineCodes.SqlServer]);
}
}
}