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 SemVerLevel propagation in Odata Next links. #5582

Merged
merged 6 commits into from
Mar 7, 2018
Merged
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
Expand Up @@ -183,7 +183,7 @@ private async Task<IHttpActionResult> GetCore(
.ToV2FeedPackageQuery(GetSiteRoot(), _configurationService.Features.FriendlyLicenses, semVerLevelKey);

return QueryResult(options, pagedQueryable, MaxPageSize, totalHits, (o, s, resultCount) =>
SearchAdaptor.GetNextLink(Request.RequestUri, resultCount, new { id }, o, s));
SearchAdaptor.GetNextLink(Request.RequestUri, resultCount, new { id }, o, s, semVerLevelKey));
}
}
catch (Exception ex)
Expand Down Expand Up @@ -299,7 +299,8 @@ public async Task<IHttpActionResult> Search(
resultCount,
new { searchTerm, targetFramework, includePrerelease },
o,
s);
s,
semVerLevelKey);
}
return null;
});
Expand Down
6 changes: 3 additions & 3 deletions src/NuGetGallery/Controllers/ODataV2FeedController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public async Task<IHttpActionResult> Get(
semVerLevelKey);

return QueryResult(options, pagedQueryable, MaxPageSize, totalHits, (o, s, resultCount) =>
SearchAdaptor.GetNextLink(Request.RequestUri, resultCount, null, o, s));
SearchAdaptor.GetNextLink(Request.RequestUri, resultCount, null, o, s, semVerLevelKey));
}
}
}
Expand Down Expand Up @@ -251,7 +251,7 @@ private async Task<IHttpActionResult> GetCore(
semVerLevelKey);

return QueryResult(options, pagedQueryable, MaxPageSize, totalHits, (o, s, resultCount) =>
SearchAdaptor.GetNextLink(Request.RequestUri, resultCount, new { id }, o, s));
SearchAdaptor.GetNextLink(Request.RequestUri, resultCount, new { id }, o, s, semVerLevelKey));
}
}
catch (Exception ex)
Expand Down Expand Up @@ -358,7 +358,7 @@ public async Task<IHttpActionResult> Search(
// Strip it of for backward compatibility.
if (o.Top == null || (resultCount.HasValue && o.Top.Value >= resultCount.Value))
{
return SearchAdaptor.GetNextLink(Request.RequestUri, resultCount, new { searchTerm, targetFramework, includePrerelease }, o, s);
return SearchAdaptor.GetNextLink(Request.RequestUri, resultCount, new { searchTerm, targetFramework, includePrerelease }, o, s, semVerLevelKey);
}
return null;
});
Expand Down
12 changes: 11 additions & 1 deletion src/NuGetGallery/OData/SearchService/SearchAdaptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private static bool TryReadSearchFilter(bool allVersionsInIndex, string url, boo
return true;
}

public static Uri GetNextLink(Uri currentRequestUri, long? totalResultCount, object queryParameters, ODataQueryOptions options, ODataQuerySettings settings)
public static Uri GetNextLink(Uri currentRequestUri, long? totalResultCount, object queryParameters, ODataQueryOptions options, ODataQuerySettings settings, int? semVerLevelKey = null)
{
if (!totalResultCount.HasValue || totalResultCount.Value <= MaxPageSize || totalResultCount.Value == 0)
{
Expand Down Expand Up @@ -374,6 +374,16 @@ public static Uri GetNextLink(Uri currentRequestUri, long? totalResultCount, obj
queryBuilder.Append("&");
}

if (semVerLevelKey != null)
{
if(semVerLevelKey == SemVerLevelKey.SemVer2)
{
queryBuilder.Append("semVerLevel=");
queryBuilder.Append(SemVerLevelKey.SemVerLevel2);
queryBuilder.Append("&");
}
}

var queryString = queryBuilder.ToString().TrimEnd('&');

var builder = new UriBuilder(currentRequestUri);
Expand Down
17 changes: 17 additions & 0 deletions tests/NuGetGallery.Facts/Services/SearchAdaptorFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,23 @@ public void GeneratesNextLinkForComplexUrl()
// Assert
Assert.Equal(new Uri("https://localhost:8081/api/v2/Search()?searchTerm='foo'&$orderby=Id&$skip=200&$top=1000"), nextLink);
}

[Fact]
public void GeneratesNextLinkForComplexUrlWithSemVerLevel2()
{
// Arrange
var requestUri = new Uri("https://localhost:8081/api/v2/Search()?searchTerm='foo'&$orderby=Id&$skip=100&$top=1000&semVerLevel=2.0.0");
var resultCount = 2000; // our result set contains 2000 elements

// Act
var nextLink = SearchAdaptor.GetNextLink(requestUri, resultCount, new { searchTerm = "foo" },
GetODataQueryOptionsForTest(requestUri),
GetODataQuerySettingsForTest(),
SemVerLevelKey.SemVer2);

// Assert
Assert.Equal(new Uri("https://localhost:8081/api/v2/Search()?searchTerm='foo'&$orderby=Id&$skip=200&$top=1000&semVerLevel=2.0.0"), nextLink);
}
}
}
}