Skip to content

Commit a99512b

Browse files
committed
fix
1 parent c3eacb0 commit a99512b

File tree

4 files changed

+41
-19
lines changed

4 files changed

+41
-19
lines changed

Eocron.Algorithms.Tests/PagingQueryableTests.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,24 @@ public class PagingQueryableTests
1616
public void Setup()
1717
{
1818
var now = new DateTime(2017, 12, 1);
19-
_items = new List<TestDbEntity>()
20-
{
21-
new TestDbEntity(){Id = Guid.Parse("10000000-0000-0000-0000-000000000001"),Name = "Test1", Modified = now.AddDays(1)},
22-
new TestDbEntity(){Id = Guid.Parse("10000000-0000-0000-0000-000000000002"),Name = "Test2", Modified = now.AddDays(2)},
23-
new TestDbEntity(){Id = Guid.Parse("10000000-0000-0000-0000-000000000003"),Name = "Test3", Modified = now.AddDays(3)},
24-
new TestDbEntity(){Id = Guid.Parse("10000000-0000-0000-0000-000000000004"),Name = "Test4", Modified = now.AddDays(4)},
25-
new TestDbEntity(){Id = Guid.Parse("10000000-0000-0000-0000-000000000005"),Name = "Test5", Modified = now.AddDays(5)},
26-
new TestDbEntity(){Id = Guid.Parse("10000000-0000-0000-0000-000000000006"),Name = "Test6", Modified = now.AddDays(6)},
27-
};
19+
_items = [
20+
new(){Id = Guid.Parse("10000000-0000-0000-0000-000000000001"),Name = "Test1", Modified = now.AddDays(1)},
21+
new(){Id = Guid.Parse("10000000-0000-0000-0000-000000000002"),Name = "Test2", Modified = now.AddDays(2)},
22+
new(){Id = Guid.Parse("10000000-0000-0000-0000-000000000003"),Name = "Test3", Modified = now.AddDays(3)},
23+
new(){Id = Guid.Parse("10000000-0000-0000-0000-000000000004"),Name = "Test4", Modified = now.AddDays(4)},
24+
new(){Id = Guid.Parse("10000000-0000-0000-0000-000000000005"),Name = "Test5", Modified = now.AddDays(5)},
25+
new(){Id = Guid.Parse("10000000-0000-0000-0000-000000000006"),Name = "Test6", Modified = now.AddDays(6)},
26+
];
2827
}
2928

3029
[Test]
3130
public void SanityCheck()
3231
{
3332
var queryable = _items.AsQueryable();
3433

35-
var cfg = new PagingConfiguration<TestDbEntity>();
36-
cfg.AddKeySelector(x=> x.Modified, isDescending: true);
37-
cfg.AddKeySelector(x=> x.Id);
34+
var cfg = new PagingConfiguration<TestDbEntity>()
35+
.OrderByDescending(x => x.Modified)
36+
.OrderBy(x => x.Id);
3837

3938
var result = new List<TestDbEntity>();
4039
var queries = new List<string>();
@@ -66,8 +65,8 @@ public void SanityCheck()
6665
"System.Collections.Generic.List`1[Eocron.Algorithms.Tests.PagingQueryableTests+TestDbEntity].OrderByDescending(x => x.Modified).ThenBy(x => x.Id).Where(x => (((x.Modified == 12/2/2017 12:00:00 AM) AndAlso (x.Id > 10000000-0000-0000-0000-000000000001)) OrElse (x.Modified < 12/2/2017 12:00:00 AM)))"
6766
]);
6867
}
69-
70-
public class TestDbEntity
68+
69+
private class TestDbEntity
7170
{
7271
public Guid Id { get; set; }
7372

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Linq.Expressions;
3+
4+
namespace Eocron.Algorithms.Queryable.Paging
5+
{
6+
public interface IPagingConfiguration<TEntity>
7+
{
8+
void AddKeySelector<TKey>(Expression<Func<TEntity, TKey>> keySelector, bool isDescending = false);
9+
string GetContinuationToken(TEntity entity);
10+
}
11+
}

Eocron.Algorithms/Queryable/Paging/PagingConfiguration.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66

77
namespace Eocron.Algorithms.Queryable.Paging
88
{
9-
public sealed class PagingConfiguration<TEntity>
9+
public sealed class PagingConfiguration<TEntity> : IPagingConfiguration<TEntity>
1010
{
1111
private readonly List<PagingKeyConfiguration> _keys = new();
1212

13-
public ParameterExpression Input = Expression.Parameter(typeof(TEntity), "x");
14-
15-
public IReadOnlyList<PagingKeyConfiguration> Keys => _keys;
13+
internal ParameterExpression Input = Expression.Parameter(typeof(TEntity), "x");
14+
internal IReadOnlyList<PagingKeyConfiguration> Keys => _keys;
1615

1716
private static readonly JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings()
1817
{
@@ -45,7 +44,7 @@ public string GetContinuationToken(TEntity entity)
4544
JsonSerializerSettings);
4645
}
4746

48-
public List<object> GetKeyValues(string continuationToken)
47+
internal List<object> GetKeyValues(string continuationToken)
4948
{
5049
if (string.IsNullOrWhiteSpace(continuationToken))
5150
throw new ArgumentNullException(nameof(continuationToken));

Eocron.Algorithms/Queryable/Paging/PagingQueryableExtensions.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@ namespace Eocron.Algorithms.Queryable.Paging
99
/// </summary>
1010
public static class PagingQueryableExtensions
1111
{
12+
public static PagingConfiguration<TEntity> OrderBy<TEntity, TKey>(this PagingConfiguration<TEntity> configuration,
13+
Expression<Func<TEntity, TKey>> orderByExpression)
14+
{
15+
configuration.AddKeySelector(orderByExpression);
16+
return configuration;
17+
}
18+
19+
public static PagingConfiguration<TEntity> OrderByDescending<TEntity, TKey>(this PagingConfiguration<TEntity> configuration,
20+
Expression<Func<TEntity, TKey>> orderByExpression)
21+
{
22+
configuration.AddKeySelector(orderByExpression, isDescending: true);
23+
return configuration;
24+
}
1225
/// <summary>
1326
/// Applies configured ordering.
1427
/// Applies skipping WHERE condition to IQueryable if continuation token is not empty.

0 commit comments

Comments
 (0)