Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
58 lines (48 loc) · 2.22 KB

File metadata and controls

58 lines (48 loc) · 2.22 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using NUnit.Framework;
using Simple.Data.SqlServer;
namespace Simple.Data.SqlTest
{
[TestFixture]
public class SqlQueryPagerTest
{
static readonly Regex Normalize = new Regex(@"\s+", RegexOptions.Multiline);
[Test]
public void ShouldApplyPagingUsingOrderBy()
{
const string sql = "select a,b,c from d where a = 1 order by c";
const string expected =
"with __data as (select a,b,c, row_number() over(order by c) as [_#_] from d where a = 1)"
+ " select a,b,c from __data where [_#_] between @skip + 1 and @skip + @take";
var modified = new SqlQueryPager().ApplyPaging(sql, "@skip", "@take");
modified = Normalize.Replace(modified, " ").ToLowerInvariant();
Assert.AreEqual(expected, modified);
}
[Test]
public void ShouldApplyPagingUsingOrderByFirstColumnIfNotAlreadyOrdered()
{
const string sql = "select a,b,c from d where a = 1";
const string expected =
"with __data as (select a,b,c, row_number() over(order by a) as [_#_] from d where a = 1)"
+ " select a,b,c from __data where [_#_] between @skip + 1 and @skip + @take";
var modified = new SqlQueryPager().ApplyPaging(sql, "@skip", "@take");
modified = Normalize.Replace(modified, " ").ToLowerInvariant();
Assert.AreEqual(expected, modified);
}
[Test]
public void ShouldCopeWithAliasedColumns()
{
const string sql = "select [a],[b] as [foo],[c] from [d] where [a] = 1";
const string expected =
"with __data as (select [a],[b] as [foo],[c], row_number() over(order by [a]) as [_#_] from [d] where [a] = 1)"
+ " select [a],[foo],[c] from __data where [_#_] between @skip + 1 and @skip + @take";
var modified = new SqlQueryPager().ApplyPaging(sql, "@skip", "@take");
modified = Normalize.Replace(modified, " ").ToLowerInvariant();
Assert.AreEqual(expected, modified);
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.