File tree Expand file tree Collapse file tree
src/NuGet.Server.V2/Controllers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -45,10 +45,7 @@ protected NuGetODataController(
4545 }
4646
4747 // GET /Packages
48- // Never seen this invoked. NuGet.Exe and Visual Studio seems to use 'Search' for all package listing.
49- // Probably required to be OData compliant?
5048 [ HttpGet ]
51- [ EnableQuery ( PageSize = 100 , HandleNullPropagation = HandleNullPropagationOption . False ) ]
5249 public virtual async Task < IHttpActionResult > Get (
5350 ODataQueryOptions < ODataPackage > options ,
5451 [ FromUri ] string semVerLevel = "" ,
Original file line number Diff line number Diff line change @@ -98,6 +98,40 @@ public async Task PushPackageThenReadPackages()
9898 }
9999 }
100100
101+ [ Theory ]
102+ [ MemberData ( nameof ( EndpointsSupportingProjection ) ) ]
103+ public async Task CanQueryUsingProjection ( string endpoint )
104+ {
105+ // Arrange
106+ using ( var tc = new TestContext ( ) )
107+ {
108+ var packagePath = Path . Combine ( tc . PackagesDirectory , "package.nupkg" ) ;
109+ TestData . CopyResourceToPath ( TestData . PackageResource , packagePath ) ;
110+
111+ // Act
112+ using ( var request = new HttpRequestMessage ( HttpMethod . Get , $ "/nuget/{ endpoint } $select=Id,Version") )
113+ using ( var response = await tc . Client . SendAsync ( request ) )
114+ {
115+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
116+ var content = await response . Content . ReadAsStringAsync ( ) ;
117+
118+ // Assert
119+ Assert . Contains ( TestData . PackageId , content ) ;
120+ Assert . Contains ( TestData . PackageVersionString , content ) ;
121+ }
122+ }
123+ }
124+
125+ public static IEnumerable < object [ ] > EndpointsSupportingProjection
126+ {
127+ get
128+ {
129+ yield return new object [ ] { "Packages()?" } ;
130+ yield return new object [ ] { "Search()?searchTerm=''&targetFramework=''&includePrerelease=true&includeDelisted=true&" } ;
131+ yield return new object [ ] { $ "FindPackagesById()?id='{ TestData . PackageId } '&" } ;
132+ }
133+ }
134+
101135 private sealed class TestContext : IDisposable
102136 {
103137 private readonly HttpServer _server ;
You can’t perform that action at this time.
0 commit comments