You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The new paging support introduced in 1.12 works when you call GetComments() without selectors parameters.
It doesn't work when selectors is passed. i.e. It returns only 30 comments even when there are more on the page.
See code block below
Add the following unit test to the PagesTests.cs in PnP.Core.Test project
Run the test without mocking turned off.
Assertion failure since it returns 30 comments instead of 45 that get added in this test.
[TestMethod]
public async Task PageCommentingTestOnlyReturn30CommentsWithSelector()
{
TestCommon.Instance.Mocking = false;
using (var context = await TestCommon.Instance.GetContextAsync(TestCommon.TestSite))
{
IPage newPage = null;
try
{
newPage = await context.Web.NewPageAsync();
string pageName = TestCommon.GetPnPSdkTestAssetName("PageCommentingTestOnlyReturn30Comments.aspx");
// Save the page
await newPage.SaveAsync(pageName);
// Publish the page, required before it can be liked
newPage.Publish();
// Get Page comments
var comments = newPage.GetComments();
Assert.IsTrue(comments.Length == 0);
var noCommentsAdded = 45;
foreach (var i in Enumerable.Range(1, noCommentsAdded))
{
// Add a comment
await comments.AddBatchAsync($"Comment #: {i} added by unit test");
}
await context.ExecuteAsync();
comments = newPage.GetComments(
p => p.Author,
p => p.Text,
p => p.ReplyCount,
p => p.CreatedDate,
p => p.Replies);
// Expecting 45 but only 30 is returned.
Assert.IsTrue(comments.Length == noCommentsAdded);
}
finally
{
// Delete the page
await newPage.DeleteAsync();
}
}
}
Expected behavior
Calling GetComments() with selectors parameter should return all comments.
var comments = page.GetComments(
p => p.Author,
p => p.Text,
p => p.ReplyCount,
p => p.CreatedDate,
p => p.Replies);
Additional details: The more context you can provide, the easier it is (and therefore quicker) to help.
Additional context
After reviewing the code I noticed that in the code branch that handle when selectors is provided, the constructor call to ApiCall should have loadPages: true parameter. Specifically the BuildGetCommentsApiCallAsync method in ListItem.cs
Line 1703: return new ApiCall(query.ApiCall.Request, ApiType.SPORest, receivingProperty: nameof(Comments), loadPages: true);
Thanks for your contribution! Sharing is caring.
The text was updated successfully, but these errors were encountered:
@larry-lau : thanks for the detailed write up and analysis, I've fixed the code like you mentioned and updated the test case to cover this scenario. Fix will be part of the next nightly, closing issue now.
Category
Describe the bug
The new paging support introduced in 1.12 works when you call GetComments() without selectors parameters.
It doesn't work when selectors is passed. i.e. It returns only 30 comments even when there are more on the page.
This is related to #1361
Steps to reproduce
See code block below
Add the following unit test to the PagesTests.cs in PnP.Core.Test project
Run the test without mocking turned off.
Assertion failure since it returns 30 comments instead of 45 that get added in this test.
Expected behavior
Calling GetComments() with selectors parameter should return all comments.
var comments = page.GetComments(
p => p.Author,
p => p.Text,
p => p.ReplyCount,
p => p.CreatedDate,
p => p.Replies);
Environment details (development & target environment)
Additional context
After reviewing the code I noticed that in the code branch that handle when selectors is provided, the constructor call to ApiCall should have loadPages: true parameter. Specifically the BuildGetCommentsApiCallAsync method in ListItem.cs
Line 1703: return new ApiCall(query.ApiCall.Request, ApiType.SPORest, receivingProperty: nameof(Comments), loadPages: true);
Thanks for your contribution! Sharing is caring.
The text was updated successfully, but these errors were encountered: