Adding cursor size tests

This commit is contained in:
Brandon Watson
2021-03-05 14:30:25 -05:00
parent b61ffde4c9
commit 24fd683cb7
3 changed files with 57 additions and 15 deletions

View File

@ -34,6 +34,10 @@ namespace Aurora.Cursor
public CursorResult<T> GetNextPage()
{
if (this._pageSize < 0)
{
throw new InvalidOperationException("Page Size must be greater than zero");
}
List<KeyValuePair<string, T>> tmpList;
// Sort reference list
@ -61,20 +65,14 @@ namespace Aurora.Cursor
int endIdx = startIdx + this._pageSize;
List<T> selection = new List<T>();
// Get page
for (int i = startIdx; i < tmpList.Count && i < endIdx; i++)
{
selection.Add(tmpList.ElementAt(i).Value);
}
List<KeyValuePair<string, T>> selection = tmpList.GetRange(startIdx, this._pageSize > tmpList.Count ? tmpList.Count : this._pageSize);
return new CursorResult<T>
{
NextPageToken = selection[selection.Count - 1].Id,
PrevPageToken = selection[0].Id,
NextPageToken = selection[selection.Count - 1].Key,
PrevPageToken = selection[0].Key,
Count = this._list.Count,
Result = selection
Result = selection.ConvertAll(item => item.Value)
};
}
@ -83,13 +81,13 @@ namespace Aurora.Cursor
throw new NotImplementedException();
}
public Cursor<T> WithNextPage(string nextPageToken)
public Cursor<T> WithNextPageToken(string nextPageToken)
{
this._nextPageToken = nextPageToken;
return this;
}
public Cursor<T> WithPreviousPage(string prevPageToken)
public Cursor<T> WithPreviousPageToken(string prevPageToken)
{
this._previousPageToken = prevPageToken;
return this;