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

Fix relative next link #933

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Content":null,"ContentHeaders":null,"Method":"GET","RequestHeaders":[{"Key":"Accept","Value":["application\/json","application\/xml","application\/text"]}],"RequestUri":"http:\/\/localhost\/Products?$count=true"}
18 changes: 18 additions & 0 deletions MockData/ResponseReaderV4Tests.GetRelativeNextPageLink.2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"Content": "{\"@odata.context\": \"$metadata#Products\",\"@odata.metadataEtag\": \"W\/\\\"20240208144657\\\"\",\"value\": [{\"ProductID\": 1,\"ProductName\": \"VersaTray Essentials\",\"Discontinued\": false,\"UnitPrice\": 19.99}, {\"ProductID\": 2,\"ProductName\": \"InkScribe Chronicles\",\"Discontinued\": false,\"UnitPrice\": 12.99}, {\"ProductID\": 3,\"ProductName\": \"Quantum Whispers\",\"Discontinued\": false,\"UnitPrice\": 14.95}, {\"ProductID\": 4,\"ProductName\": \"LuminaSync Earbuds\",\"Discontinued\": false,\"UnitPrice\": 79.99}, {\"ProductID\": 5,\"ProductName\": \"UrbanTrail Hoodie\",\"Discontinued\": false,\"UnitPrice\": 49.95}, {\"ProductID\": 6,\"ProductName\": \"ZenBloom Wall Art\",\"Discontinued\": true,\"UnitPrice\": 39.99}, {\"ProductID\": 7,\"ProductName\": \"GlowDust Highlighter\",\"Discontinued\": false,\"UnitPrice\": 9.99}, {\"ProductID\": 8,\"ProductName\": \"SummitPulse Trekking Poles\",\"Discontinued\": false,\"UnitPrice\": 59.95}, {\"ProductID\": 9,\"ProductName\": \"NebulaNova Building Blocks\",\"Discontinued\": false,\"UnitPrice\": 24.99}, {\"ProductID\": 10,\"ProductName\": \"VelvetLuxe Lip Stains\",\"Discontinued\": false,\"UnitPrice\": 17.5}],\"@odata.nextLink\": \"Products?$skiptoken=10\"}",
"ContentHeaders": [{
"Key": "Content-Type",
"Value": ["application\/json; odata.metadata=minimal"]
}, {
"Key": "Content-Length",
"Value": ["590"]
}
],
"RequestUri": "http:\/\/localhost\/functions\/Products\/Default.MostExpensives()",
"ResponseHeaders": [{
"Key": "OData-Version",
"Value": ["4.0"]
}
],
"StatusCode": 200
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Content":null,"ContentHeaders":null,"Method":"GET","RequestHeaders":[{"Key":"Accept","Value":["application\/json","application\/xml","application\/text"]}],"RequestUri":"http:\/\/localhost\/Products?$count=true"}
18 changes: 18 additions & 0 deletions MockData/ResponseReaderV4Tests.GetRelativeNextPageLink.4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"Content": "{\"@odata.context\": \"$metadata#Products\",\"@odata.metadataEtag\": \"W\/\\\"20240208144657\\\"\",\"value\": [{\"ProductID\": 11,\"ProductName\": \"PawPal Comfort Bed\",\"Discontinued\": true,\"UnitPrice\": 34.99}, {\"ProductID\": 12,\"ProductName\": \"QuillCraft Vintage Journals\",\"Discontinued\": false}]}",
"ContentHeaders": [{
"Key": "Content-Type",
"Value": ["application\/json; odata.metadata=minimal"]
}, {
"Key": "Content-Length",
"Value": ["590"]
}
],
"RequestUri": "http:\/\/localhost\/functions\/Products\/Default.MostExpensives()",
"ResponseHeaders": [{
"Key": "OData-Version",
"Value": ["4.0"]
}
],
"StatusCode": 200
}
1 change: 1 addition & 0 deletions src/Simple.OData.Client.V4.Adapter/ODataExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static ODataMessageReaderSettings ToReaderSettings(this ODataClientSettin
readerSettings.Validations &= ~Microsoft.OData.ValidationKinds.ThrowOnUndeclaredPropertyForNonOpenType;
}

readerSettings.BaseUri = settings.BaseUri;
readerSettings.MessageQuotas.MaxReceivedMessageSize = int.MaxValue;
readerSettings.ShouldIncludeAnnotation = x => settings.IncludeAnnotationsInResults;

Expand Down
31 changes: 30 additions & 1 deletion src/Simple.OData.Tests.Client/Core/ResponseReaderV4Tests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System.Text;
using System.Text;
using FluentAssertions;
using Microsoft.OData;
using Microsoft.OData.Edm;
using Moq;
using Simple.OData.Client;
using Simple.OData.Client.V4.Adapter;
using Xunit;

Expand Down Expand Up @@ -51,4 +52,32 @@ public async Task ExampleActionReturnsComplexType()
mock.Setup(x => x.GetHeader("Content-Type")).Returns(() => "application/json; type=feed; charset=utf-8");
return mock.Object;
}

[Fact]
public async Task GetRelativeNextPageLink()
{
var settings = new ODataClientSettings {
BaseUri = new Uri("http://localhost"),
MetadataDocument = GetResourceAsString("Northwind4.xml"),
PayloadFormat = ODataPayloadFormat.Json
};
settings = settings.WithHttpMock();
var client = new ODataClient(settings);

var annotations = new ODataFeedAnnotations();

var response = await client
.For("Products")
.FindEntriesAsync(annotations);

Assert.Equal(10, response.Count());
Assert.NotNull(annotations.NextPageLink);

var response2 = await client
.For("Products")
.FindEntriesAsync(annotations);

Assert.Equal(2, response2.Count());
Assert.Null(annotations.NextPageLink);
}
}