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)); }
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)); }
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, 5, 10); var modified = pagedSql.Select(x=> Normalize.Replace(x, " ").ToLowerInvariant()); Assert.IsTrue(expected.SequenceEqual(modified)); }
public void ShouldApplyPagingUsingOrderByFirstColumnIfNotAlreadyOrdered() { const string sql = "select a,b,c from d where a = 1"; const string expected = "select a,b,c from d where a = 1 order by a offset @skip rows fetch next @take rows only"; var modified = new SqlCe40QueryPager().ApplyPaging(sql, "@skip", "@take"); modified = Normalize.Replace(modified, " ").ToLowerInvariant(); Assert.AreEqual(expected, modified); }