mirror of
https://github.com/Shchoholiev/shopping-assistant-api.git
synced 2025-04-04 16:49:36 +00:00
fix unpredictable results from GetPage method
This commit is contained in:
parent
9c9081a44f
commit
f24365a3eb
@ -17,6 +17,21 @@ public class MessagesRepository : BaseRepository<Message>, IMessagesRepository
|
||||
pageSize = Math.Clamp(pageSize, 1, messageCount);
|
||||
var numberOfPages = messageCount / pageSize;
|
||||
|
||||
if (pageNumber > numberOfPages)
|
||||
{
|
||||
return new List<Message>();
|
||||
}
|
||||
|
||||
if (pageNumber < 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
if (pageSize < 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
return await _collection.Find(predicate)
|
||||
.Skip((numberOfPages - pageNumber) * pageSize)
|
||||
.Limit(pageSize)
|
||||
|
@ -310,6 +310,8 @@ public class WishlistsTests : IClassFixture<TestingFactory<Program>>
|
||||
var responseString = await response.Content.ReadAsStringAsync();
|
||||
var document = JsonConvert.DeserializeObject<dynamic>(responseString);
|
||||
|
||||
Console.WriteLine(document);
|
||||
|
||||
var personalWishlistsPageItems = Enumerable.ToList(document.data.personalWishlistsPage.items);
|
||||
|
||||
Assert.Empty(personalWishlistsPageItems);
|
||||
@ -342,6 +344,9 @@ public class WishlistsTests : IClassFixture<TestingFactory<Program>>
|
||||
var responseString = await response.Content.ReadAsStringAsync();
|
||||
var document = JsonConvert.DeserializeObject<dynamic>(responseString);
|
||||
|
||||
Console.WriteLine(document);
|
||||
|
||||
|
||||
var personalWishlistsPageItems = Enumerable.ToList(document.data.personalWishlistsPage.items);
|
||||
var personalWishlistCreatedById = (string) personalWishlistsPageItems[0].createdById;
|
||||
|
||||
@ -446,7 +451,17 @@ public class WishlistsTests : IClassFixture<TestingFactory<Program>>
|
||||
var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
|
||||
|
||||
using var response = await _httpClient.PostAsync("graphql", content);
|
||||
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
var responseString = await response.Content.ReadAsStringAsync();
|
||||
var document = JsonConvert.DeserializeObject<dynamic>(responseString);
|
||||
|
||||
Console.WriteLine(document);
|
||||
|
||||
|
||||
var messagesPageFromPersonalWishlistItems = Enumerable.ToList(document.data.messagesPageFromPersonalWishlist.items);
|
||||
|
||||
Assert.Empty(messagesPageFromPersonalWishlistItems);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -476,6 +491,9 @@ public class WishlistsTests : IClassFixture<TestingFactory<Program>>
|
||||
var responseString = await response.Content.ReadAsStringAsync();
|
||||
var document = JsonConvert.DeserializeObject<dynamic>(responseString);
|
||||
|
||||
Console.WriteLine(document);
|
||||
|
||||
|
||||
var messagesPageFromPersonalWishlist = Enumerable.ToList(document.data.messagesPageFromPersonalWishlist.items);
|
||||
var firstMessageInPage = messagesPageFromPersonalWishlist[0];
|
||||
var secondMessageInPage = messagesPageFromPersonalWishlist[1];
|
||||
|
Loading…
Reference in New Issue
Block a user