Skip to content

Commit

Permalink
Support projection on the Packages() endpoint ($select) (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
joelverhagen committed Dec 15, 2017
1 parent ffc2b36 commit f5aa2ba
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/NuGet.Server.V2/Controllers/NuGetODataController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ protected NuGetODataController(
}

// GET /Packages
// Never seen this invoked. NuGet.Exe and Visual Studio seems to use 'Search' for all package listing.
// Probably required to be OData compliant?
[HttpGet]
[EnableQuery(PageSize = 100, HandleNullPropagation = HandleNullPropagationOption.False)]
public virtual async Task<IHttpActionResult> Get(
ODataQueryOptions<ODataPackage> options,
[FromUri] string semVerLevel = "",
Expand Down
34 changes: 34 additions & 0 deletions test/NuGet.Server.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,40 @@ public async Task PushPackageThenReadPackages()
}
}

[Theory]
[MemberData(nameof(EndpointsSupportingProjection))]
public async Task CanQueryUsingProjection(string endpoint)
{
// Arrange
using (var tc = new TestContext())
{
var packagePath = Path.Combine(tc.PackagesDirectory, "package.nupkg");
TestData.CopyResourceToPath(TestData.PackageResource, packagePath);

// Act
using (var request = new HttpRequestMessage(HttpMethod.Get, $"/nuget/{endpoint}$select=Id,Version"))
using (var response = await tc.Client.SendAsync(request))
{
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var content = await response.Content.ReadAsStringAsync();

// Assert
Assert.Contains(TestData.PackageId, content);
Assert.Contains(TestData.PackageVersionString, content);
}
}
}

public static IEnumerable<object[]> EndpointsSupportingProjection
{
get
{
yield return new object[] { "Packages()?" };
yield return new object[] { "Search()?searchTerm=''&targetFramework=''&includePrerelease=true&includeDelisted=true&" };
yield return new object[] { $"FindPackagesById()?id='{TestData.PackageId}'&" };
}
}

private sealed class TestContext : IDisposable
{
private readonly HttpServer _server;
Expand Down

0 comments on commit f5aa2ba

Please sign in to comment.