Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/paging #1572

Merged
merged 32 commits into from
Jun 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ca29e87
Add paging extension
calebkiage May 17, 2022
a571b18
Add paging information to request executors
calebkiage May 17, 2022
64f96e5
Merge remote-tracking branch 'origin/main' into feat/paging
calebkiage May 17, 2022
8f5cfbd
Update tests
calebkiage May 18, 2022
d3c2ce8
Update CodeMethod clone
calebkiage May 18, 2022
41b26b8
Merge branch 'main' into feat/paging
calebkiage May 18, 2022
ef06869
Update ChangeLog
calebkiage May 18, 2022
f042a50
Fix null reference exception on CodeMethod clone
calebkiage May 18, 2022
1369e57
Add paging service
calebkiage May 24, 2022
446fce3
Merge JSON streams when fetching multiple pages
calebkiage May 26, 2022
00b971a
Fix boolean flags in collection binding
calebkiage May 27, 2022
fa5fbe5
Update paging algorithm
calebkiage May 27, 2022
04ae848
Update code method writer to emit pageable requests
calebkiage May 27, 2022
61cf706
Bump CLI commons version
calebkiage May 27, 2022
8198726
Merge branch 'main' into feat/paging
calebkiage May 27, 2022
18a7a88
Fix build error
calebkiage May 27, 2022
73dd345
Apply suggestions from code review
baywet May 27, 2022
d9a2cb5
Fix missing param in xml doc
calebkiage May 27, 2022
9674ca5
Simplify computing next page link
calebkiage Jun 2, 2022
69517de
Merge branch 'main' into feat/paging
baywet Jun 2, 2022
943c7ea
Fix exception when response isn't valid JSON
calebkiage Jun 2, 2022
c67910f
Merge remote-tracking branch 'origin/feat/paging' into feat/paging
calebkiage Jun 2, 2022
c81e5d4
Remove redundant null check
calebkiage Jun 2, 2022
3c00ec9
Refactor paging to have a base abstract class
calebkiage Jun 2, 2022
81b482a
Remove hardcoded response format
calebkiage Jun 2, 2022
1878cd5
Update System.CommandLine to beta 4
calebkiage Jun 3, 2022
05dfdaf
Revert "Update System.CommandLine to beta 4"
calebkiage Jun 3, 2022
8e9d490
Fix merge response on null array in input stream
calebkiage Jun 3, 2022
522772b
Remove graph specific top parameter handling
calebkiage Jun 3, 2022
8fc634c
Update System.CommandLine to beta 4 (#1614)
calebkiage Jun 3, 2022
eb81eb6
Allow inheriting from paging service
calebkiage Jun 3, 2022
19f72d4
Merge branch 'feat/paging' of https://github.com/microsoft/kiota into…
calebkiage Jun 3, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Added a parameter to specify why mime types to evaluate for models. [#134](https://github.com/microsoft/kiota/issues/134)
- Added an explicit error message for external references in the schema. [#1580](https://github.com/microsoft/kiota/issues/1580)
- Added support for paging. [#1569](https://github.com/microsoft/kiota/issues/1569)

### Changed

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Kiota.Abstractions;
using Microsoft.Kiota.Cli.Commons.IO;
using Xunit;

namespace Microsoft.Kiota.Cli.Commons.Tests.IO;

public class ODataPagingServiceTest
{
public class GetNextPageLinkAsyncFunction_Should
{
[Fact]
public async Task Return_Null_on_No_Next_Link()
{
var pagingService = new ODataPagingService();
var stream = Stream.Null;
var requestInfo = new RequestInformation();
var pagingData = new PageLinkData(requestInfo, stream);

var nextLink = await pagingService.GetNextPageLinkAsync(pagingData);

Assert.Null(nextLink);
}

[Fact]
public async Task Return_Next_Link_From_Response()
{
var pagingService = new ODataPagingService();
var bytes = Encoding.UTF8.GetBytes("{\"nextLink\": \"https://testlink\"}");
using var ms = new MemoryStream(bytes);
var requestInfo = new RequestInformation();
requestInfo.Headers.Add("Accept", "application/json");
var pagingData = new PageLinkData(requestInfo, ms);

var nextLink = await pagingService.GetNextPageLinkAsync(pagingData);

Assert.Equal(new Uri("https://testlink"), nextLink);
}

[Fact]
public async Task Return_Null_On_Next_Link_Missing()
{
var pagingService = new ODataPagingService();
var bytes = Encoding.UTF8.GetBytes("{}");
using var ms = new MemoryStream(bytes);
var requestInfo = new RequestInformation();
var pagingData = new PageLinkData(requestInfo, ms);

var nextLink = await pagingService.GetNextPageLinkAsync(pagingData);

Assert.Null(nextLink);
}
}

public class MergeJsonStreamsFunction_Should
{
[Fact]
public async Task Return_Null_on_Null_Streams()
{
var pagingService = new ODataPagingService();

var response = await pagingService.MergeJsonStreamsAsync(null, null);

Assert.Null(response);
}

[Fact]
public async Task Return_Left_on_Null_Right_Stream()
{
var pagingService = new ODataPagingService();

using var ms = new MemoryStream(Encoding.UTF8.GetBytes("{\"value\": [20]}"));
var response = await pagingService.MergeJsonStreamsAsync(ms, null);

Assert.Equal(ms, response);
}

[Fact]
public async Task Return_Right_on_Null_Left_Stream()
{
var pagingService = new ODataPagingService();

using var ms = new MemoryStream(Encoding.UTF8.GetBytes("{\"value\": [20]}"));
var response = await pagingService.MergeJsonStreamsAsync(null, ms);

Assert.Equal(ms, response);
}

[Fact]
public async Task Return_Left_On_Null_Data_In_Right_Stream()
{
var pagingService = new ODataPagingService();

using var leftMs = new MemoryStream(Encoding.UTF8.GetBytes("{\"value\": [20]}"));
using var rightMs = new MemoryStream(Encoding.UTF8.GetBytes("{\"value\": null}"));
var response = await pagingService.MergeJsonStreamsAsync(leftMs, rightMs);
using var reader = new StreamReader(response ?? Stream.Null);
var result = await reader.ReadToEndAsync();

Assert.Equal("{\"value\": [20]}", result);
}

[Fact]
public async Task Return_Right_On_Null_Data_In_Left_Stream()
{
var pagingService = new ODataPagingService();

using var leftMs = new MemoryStream(Encoding.UTF8.GetBytes("{\"value\": null}"));
using var rightMs = new MemoryStream(Encoding.UTF8.GetBytes("{\"value\": [20]}"));
var response = await pagingService.MergeJsonStreamsAsync(leftMs, rightMs);
using var reader = new StreamReader(response ?? Stream.Null);
var result = await reader.ReadToEndAsync();

Assert.Equal("{\"value\": [20]}", result);
}

[Theory]
[InlineData(null, "[20,21,24]", "[30]", "[20,21,24,30]")]
[InlineData("", "[20,21,24]", "[30]", "[20,21,24,30]")]
[InlineData("value", "{\"value\": [20]}", "{\"value\": [30]}", "{\"value\":[20,30]}")]
[InlineData("value", "{\"value\": [{\"a\": 1}, {\"a\": 2}]}", "{\"value\": [{\"b\": 4}]}", "{\"value\":[{\"a\":1},{\"a\":2},{\"b\":4}]}")]
public async Task Return_Merged_Stream(string itemName, string left, string right, string expected)
{
var pagingService = new ODataPagingService();

using var leftMs = new MemoryStream(Encoding.UTF8.GetBytes(left));
using var rightMs = new MemoryStream(Encoding.UTF8.GetBytes(right));
var response = await pagingService.MergeJsonStreamsAsync(leftMs, rightMs, itemName);
using var reader = new StreamReader(response ?? Stream.Null);
var result = await reader.ReadToEndAsync();

Assert.Equal(expected, result);
}

[Theory]
[InlineData("{\"value\":[20],\"nextLink\":\"test1\"}", "{\"value\":[30],\"nextLink\":\"test2\"}", "{\"value\":[20,30],\"nextLink\":\"test2\"}")]
[InlineData("{\"value\":[{\"a\": 1}],\"nextLink\":\"test2\"}", "{\"value\":[{\"b\":4}],\"nextLink\":\"test2\"}", "{\"value\":[{\"a\":1},{\"b\":4}],\"nextLink\":\"test2\"}")]
public async Task Return_With_Next_Link_From_Right_Stream(string left, string right, string expected)
{
var pagingService = new ODataPagingService();

using var leftMs = new MemoryStream(Encoding.UTF8.GetBytes(left));
using var rightMs = new MemoryStream(Encoding.UTF8.GetBytes(right));
var response = await pagingService.MergeJsonStreamsAsync(leftMs, rightMs);
using var reader = new StreamReader(response ?? Stream.Null);
var result = await reader.ReadToEndAsync();

Assert.Equal(expected, result);
}
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading