- Changed IsThrottleException to internal static in ExecuteQueryRetryHelper - Changed BuildPagedViewXml to internal static in SharePointPaginationHelper - Created ExecuteQueryRetryHelperTests: 5 tests (throttle true x3, non-throttle false, nested false) - Created SharePointPaginationHelperTests: 5 tests (null, empty, whitespace, replace, append)
50 lines
1.9 KiB
C#
50 lines
1.9 KiB
C#
using SharepointToolbox.Core.Helpers;
|
|
|
|
namespace SharepointToolbox.Tests.Helpers;
|
|
|
|
[Trait("Category", "Unit")]
|
|
public class SharePointPaginationHelperTests
|
|
{
|
|
[Fact]
|
|
public void BuildPagedViewXml_NullInput_ReturnsViewWithRowLimit()
|
|
{
|
|
var result = SharePointPaginationHelper.BuildPagedViewXml(null, 2000);
|
|
Assert.Equal("<View><RowLimit>2000</RowLimit></View>", result);
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildPagedViewXml_EmptyString_ReturnsViewWithRowLimit()
|
|
{
|
|
var result = SharePointPaginationHelper.BuildPagedViewXml("", 2000);
|
|
Assert.Equal("<View><RowLimit>2000</RowLimit></View>", result);
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildPagedViewXml_WhitespaceOnly_ReturnsViewWithRowLimit()
|
|
{
|
|
var result = SharePointPaginationHelper.BuildPagedViewXml(" ", 2000);
|
|
Assert.Equal("<View><RowLimit>2000</RowLimit></View>", result);
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildPagedViewXml_ExistingRowLimit_Replaces()
|
|
{
|
|
var input = "<View><RowLimit>100</RowLimit></View>";
|
|
var result = SharePointPaginationHelper.BuildPagedViewXml(input, 2000);
|
|
Assert.Equal("<View><RowLimit>2000</RowLimit></View>", result);
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildPagedViewXml_NoRowLimit_AppendsBeforeClosingView()
|
|
{
|
|
var input = "<View><Query><OrderBy><FieldRef Name='Title'/></OrderBy></Query></View>";
|
|
var result = SharePointPaginationHelper.BuildPagedViewXml(input, 2000);
|
|
Assert.Contains("<RowLimit>2000</RowLimit>", result);
|
|
Assert.EndsWith("</View>", result);
|
|
// Ensure RowLimit is inserted before the closing </View>
|
|
var rowLimitIndex = result.IndexOf("<RowLimit>2000</RowLimit>", StringComparison.Ordinal);
|
|
var closingViewIndex = result.LastIndexOf("</View>", StringComparison.Ordinal);
|
|
Assert.True(rowLimitIndex < closingViewIndex, "RowLimit should appear before </View>");
|
|
}
|
|
}
|