1919using NuGet . Server . Core . Logging ;
2020using NuGet . Server . Core . Tests ;
2121using NuGet . Server . Core . Tests . Infrastructure ;
22+ using NuGet . Server . V2 ;
2223using Xunit ;
2324using Xunit . Abstractions ;
2425using ISystemDependencyResolver = System . Web . Http . Dependencies . IDependencyResolver ;
@@ -162,6 +163,51 @@ public async Task PushPackageThenReadPackages()
162163 }
163164 }
164165
166+ [ Fact ]
167+ public async Task CanSupportMultipleSetsOfRoutes ( )
168+ {
169+ // Arrange
170+ using ( var tc = new TestContext ( _output ) )
171+ {
172+ // Enable another set of routes.
173+ NuGetV2WebApiEnabler . UseNuGetV2WebApiFeed (
174+ tc . Config ,
175+ "NuGetDefault2" ,
176+ "nuget2" ,
177+ TestablePackagesODataController . Name ) ;
178+
179+ string apiKey = "foobar" ;
180+ tc . SetApiKey ( apiKey ) ;
181+
182+ var packagePath = Path . Combine ( tc . TemporaryDirectory , "package.nupkg" ) ;
183+ TestData . CopyResourceToPath ( TestData . PackageResource , packagePath ) ;
184+
185+ // Act & Assert
186+ // 1. Push to the legacy route.
187+ await tc . PushPackageAsync ( apiKey , packagePath , "/api/v2/package" ) ;
188+
189+ // 2. Make a request to the first set of routes.
190+ using ( var request = new HttpRequestMessage ( HttpMethod . Get , "/nuget/Packages()" ) )
191+ using ( var response = await tc . Client . SendAsync ( request ) )
192+ {
193+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
194+ var content = await response . Content . ReadAsStringAsync ( ) ;
195+
196+ Assert . Contains ( TestData . PackageId , content ) ;
197+ }
198+
199+ // 3. Make a request to the second set of routes.
200+ using ( var request = new HttpRequestMessage ( HttpMethod . Get , "/nuget2/Packages()" ) )
201+ using ( var response = await tc . Client . SendAsync ( request ) )
202+ {
203+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
204+ var content = await response . Content . ReadAsStringAsync ( ) ;
205+
206+ Assert . Contains ( TestData . PackageId , content ) ;
207+ }
208+ }
209+ }
210+
165211 /// <summary>
166212 /// Added due to https://github.com/NuGet/NuGetGallery/issues/6960. There was a concurrency issue when pushing
167213 /// packages that could lead to unnecessary cache rebuilds.
@@ -354,7 +400,6 @@ public static IEnumerable<object[]> EndpointsSupportingProjection
354400 private sealed class TestContext : IDisposable
355401 {
356402 private readonly HttpServer _server ;
357- private readonly HttpConfiguration _config ;
358403
359404 public TestContext ( ITestOutputHelper output )
360405 {
@@ -371,13 +416,13 @@ public TestContext(ITestOutputHelper output)
371416
372417 ServiceResolver = new DefaultServiceResolver ( PackagesDirectory , Settings , Logger ) ;
373418
374- _config = new HttpConfiguration ( ) ;
375- _config . IncludeErrorDetailPolicy = IncludeErrorDetailPolicy . Always ;
376- _config . DependencyResolver = new DependencyResolverAdapter ( ServiceResolver ) ;
419+ Config = new HttpConfiguration ( ) ;
420+ Config . IncludeErrorDetailPolicy = IncludeErrorDetailPolicy . Always ;
421+ Config . DependencyResolver = new DependencyResolverAdapter ( ServiceResolver ) ;
377422
378- NuGetODataConfig . Initialize ( _config , "TestablePackagesOData" ) ;
423+ NuGetODataConfig . Initialize ( Config , TestablePackagesODataController . Name ) ;
379424
380- _server = new HttpServer ( _config ) ;
425+ _server = new HttpServer ( Config ) ;
381426 Client = new SystemHttpClient ( _server ) ;
382427 Client . BaseAddress = new Uri ( "http://localhost/" ) ;
383428 }
@@ -388,6 +433,7 @@ public TestContext(ITestOutputHelper output)
388433 public TemporaryDirectory TemporaryDirectory { get ; }
389434 public TemporaryDirectory PackagesDirectory { get ; }
390435 public NameValueCollection Settings { get ; }
436+ public HttpConfiguration Config { get ; }
391437 public SystemHttpClient Client { get ; }
392438
393439 public void SetApiKey ( string apiKey )
@@ -416,30 +462,27 @@ public MultipartContent GetFileUploadContent(params string[] paths)
416462 return content ;
417463 }
418464
419- public async Task PushPackageAsync ( string apiKey , string packagePath )
465+ public async Task PushPackageAsync ( string apiKey , string packagePath , string pushUrl = "/nuget" )
420466 {
421- using ( var request = new HttpRequestMessage ( HttpMethod . Put , "/nuget" )
467+ using ( var request = new HttpRequestMessage ( HttpMethod . Put , pushUrl )
422468 {
423469 Headers =
424470 {
425471 { "X-NUGET-APIKEY" , apiKey }
426472 } ,
427473 Content = GetFileUploadContent ( packagePath )
428474 } )
475+ using ( var response = await Client . SendAsync ( request ) )
429476 {
430- using ( request )
431- using ( var response = await Client . SendAsync ( request ) )
432- {
433- Assert . Equal ( HttpStatusCode . Created , response . StatusCode ) ;
434- }
477+ Assert . Equal ( HttpStatusCode . Created , response . StatusCode ) ;
435478 }
436479 }
437480
438481 public void Dispose ( )
439482 {
440483 Client . Dispose ( ) ;
441484 _server . Dispose ( ) ;
442- _config . Dispose ( ) ;
485+ Config . Dispose ( ) ;
443486 ServiceResolver . Dispose ( ) ;
444487 PackagesDirectory . Dispose ( ) ;
445488 TemporaryDirectory . Dispose ( ) ;
0 commit comments