Adding pagination tests

This commit is contained in:
Brandon Watson
2021-03-05 16:13:25 -05:00
parent 24fd683cb7
commit 4a4cef8dd7
2 changed files with 98 additions and 7 deletions

View File

@ -28,7 +28,7 @@ namespace Aurora.Cursor
this._pageSize = 10;
this._sortDelgate = delegate (KeyValuePair<string, T> item)
{
return item.Value.Id;
return item.Key;
};
}
@ -60,17 +60,26 @@ namespace Aurora.Cursor
if (!string.IsNullOrEmpty(this._nextPageToken))
{
// TODO find another way to index into the list that's not a regular array search
startIdx = tmpList.FindIndex(item => item.Key == this._nextPageToken);
startIdx = tmpList.FindIndex(item => item.Key == this._nextPageToken) + 1;
}
int endIdx = startIdx + this._pageSize;
int adjustedSize = this._pageSize;
if (startIdx + this._pageSize > tmpList.Count)
{
adjustedSize = this._pageSize - ((startIdx + _pageSize) - tmpList.Count);
}
List<KeyValuePair<string, T>> selection = tmpList.GetRange(startIdx, this._pageSize > tmpList.Count ? tmpList.Count : this._pageSize);
List<KeyValuePair<string, T>> selection = new List<KeyValuePair<string, T>>();
if (adjustedSize != 0)
{
selection = tmpList.GetRange(startIdx, adjustedSize);
}
return new CursorResult<T>
{
NextPageToken = selection[selection.Count - 1].Key,
PrevPageToken = selection[0].Key,
NextPageToken = this._pageSize == selection.Count ? selection[selection.Count - 1].Key : string.Empty,
PrevPageToken = string.Empty,
Count = this._list.Count,
Result = selection.ConvertAll(item => item.Value)
};