Skip to content

Commit eaf4723

Browse files
Merge pull request #48 from microsoftgraph/mmainer/extPagingIssue
Handle cases where a filter is applied to an expanded navigation prop…
2 parents 266e11f + d40e194 commit eaf4723

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

src/Microsoft.Graph.Core/Requests/BaseRequest.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,16 @@ private string InitializeUrl(string requestUrl)
327327
var queryOptions = queryString.Split('&').Select(
328328
queryValue =>
329329
{
330-
var segments = queryValue.Split('=');
330+
// We want to split on the first occurrence of = since there are scenarios where a query option can
331+
// have 'sub-query' options on navigation properties for $expand scenarios. This way we can properly
332+
// split the query option name/value into the QueryOption object. Take this for example:
333+
// $expand=extensions($filter=Id%20eq%20'SMB'%20)
334+
// We want to get '$expand' as the name and 'extensions($filter=Id%20eq%20'SMB'%20)' as the value
335+
// for QueryOption object.
336+
// OData URL conventions 5.1.2 System Query Option $expand
337+
// http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/part2-url-conventions/odata-v4.0-errata03-os-part2-url-conventions-complete.html#_Toc453752359
338+
339+
var segments = queryValue.Split(new[] { '=' }, 2);
331340
return new QueryOption(
332341
segments[0],
333342
segments.Length > 1 ? segments[1] : string.Empty);

tests/Microsoft.Graph.Test/Microsoft.Graph.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
<Compile Include="Requests\Extensions\MailFolderMessagesCollectionRequestBuilderExtensionsTests.cs" />
9090
<Compile Include="Requests\Functional\GraphTestBase.cs" />
9191
<Compile Include="Requests\Functional\MailTests.cs" />
92+
<Compile Include="Requests\Functional\ContactTests.cs" />
9293
<Compile Include="Requests\Functional\UsersTests.cs" />
9394
<Compile Include="Requests\Generated\EntityWithReferenceRequestTests.cs" />
9495
<Compile Include="Requests\Generated\EntityReferenceRequestTests.cs" />
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Threading.Tasks;
6+
7+
namespace Microsoft.Graph.Test.Requests.Functional
8+
{
9+
[Ignore]
10+
[TestClass]
11+
public class ContactTests : GraphTestBase
12+
{
13+
// OData URL convention test to make sure we handle 'sub-query option' on expanded navigation properties.
14+
// OData URL conventions 5.1.2 System Query Option $expand
15+
[TestMethod]
16+
public async Task ContactsExpandExtensionsPaging()
17+
{
18+
try
19+
{
20+
IUserContactsCollectionPage page = await graphClient.Me.Contacts.Request().Expand($"extensions($filter=Id eq 'Microsoft.OutlookServices.OpenTypeExtension.Com.Contoso.Mainer')").GetAsync();
21+
22+
// When expanding extensions, a filter must be provided to specify which extensions to expand. For example $expand=Extensions($filter=Id eq 'Com.Insightly.CRMOpportunity').
23+
while (page.NextPageRequest != null)
24+
{
25+
page = await page.NextPageRequest.GetAsync();
26+
}
27+
}
28+
catch (Microsoft.Graph.ServiceException e)
29+
{
30+
Assert.Fail("Something happened, check out a trace. Error code: {0}", e.Error.Code);
31+
}
32+
}
33+
34+
[TestMethod]
35+
public async Task GetContactsPaging()
36+
{
37+
try
38+
{
39+
IUserContactsCollectionPage page = await graphClient.Me.Contacts.Request().GetAsync();
40+
41+
while (page.NextPageRequest != null)
42+
{
43+
page = await page.NextPageRequest.GetAsync();
44+
}
45+
}
46+
catch (Microsoft.Graph.ServiceException e)
47+
{
48+
Assert.Fail("Something happened, check out a trace. Error code: {0}", e.Error.Code);
49+
}
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)