Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

64 lines (50 sloc) 2.37 kb
using System.Text.RegularExpressions;
using NUnit.Framework;
using Simple.Data.SqlCe40;
using System.Linq;
namespace Simple.Data.SqlCe40Test
{
[TestFixture]
public class SqlCe40QueryPagerTest
{
static readonly Regex Normalize = new Regex(@"\s+", RegexOptions.Multiline);
[Test]
public void ShouldApplyLimitUsingTop()
{
var sql = "select a,b,c from d where a = 1 order by c";
var expected = new[] { "select top(5) a,b,c from d where a = 1 order by c" };
var pagedSql = new SqlCe40QueryPager().ApplyLimit(sql, 5);
var modified = pagedSql.Select(x => Normalize.Replace(x, " ").ToLowerInvariant());
Assert.IsTrue(expected.SequenceEqual(modified));
}
[Test]
public void ShouldApplyLimitUsingTopWithDistinct()
{
var sql = "select distinct a,b,c from d where a = 1 order by c";
var expected = new[] { "select distinct top(5) a,b,c from d where a = 1 order by c" };
var pagedSql = new SqlCe40QueryPager().ApplyLimit(sql, 5);
var modified = pagedSql.Select(x => Normalize.Replace(x, " ").ToLowerInvariant());
Assert.IsTrue(expected.SequenceEqual(modified));
}
[Test]
public void ShouldApplyPagingUsingOrderBy()
{
var sql = "select a,b,c from d where a = 1 order by c";
var expected = new[]{
"select a,b,c from d where a = 1 order by c offset 5 rows fetch next 10 rows only"};
var pagedSql = new SqlCe40QueryPager().ApplyPaging(sql, new string[0], 5, 10);
var modified = pagedSql.Select(x=> Normalize.Replace(x, " ").ToLowerInvariant());
Assert.IsTrue(expected.SequenceEqual(modified));
}
[Test]
public void ShouldApplyPagingUsingOrderByFirstColumnIfNotAlreadyOrdered()
{
var sql = "select a,b,c from d where a = 1";
var expected = new[]{
"select a,b,c from d where a = 1 order by a offset 10 rows fetch next 20 rows only"};
var pagedSql = new SqlCe40QueryPager().ApplyPaging(sql, new string[0], 10, 20);
var modified = pagedSql.Select(x => Normalize.Replace(x, " ").ToLowerInvariant());
Assert.IsTrue(expected.SequenceEqual(modified));
}
}
}
Jump to Line
Something went wrong with that request. Please try again.