1- // Copyright (c) .NET Foundation. All rights reserved.
1+ // Copyright (c) .NET Foundation. All rights reserved.
22// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
44using System ;
@@ -135,6 +135,27 @@ public async Task FilterOnFramework()
135135 }
136136 }
137137
138+ [ Fact ]
139+ public async Task PushDuplicatePackage ( )
140+ {
141+ // Arrange
142+ using ( var tc = new TestContext ( _output ) )
143+ {
144+ string apiKey = "foobar" ;
145+ tc . SetApiKey ( apiKey ) ;
146+
147+ var packagePath = Path . Combine ( tc . TemporaryDirectory , "package.nupkg" ) ;
148+ TestData . CopyResourceToPath ( TestData . PackageResource , packagePath ) ;
149+
150+ // Act & Assert
151+ // 1. Push the package.
152+ await tc . PushPackageAsync ( apiKey , packagePath ) ;
153+
154+ // 2. Push the package again expecting a 409 as the Package already exists.
155+ await tc . PushPackageAsync ( apiKey , packagePath , excepectedStatusCode : HttpStatusCode . Conflict ) ;
156+ }
157+ }
158+
138159 [ Fact ]
139160 public async Task PushPackageThenReadPackages ( )
140161 {
@@ -462,7 +483,7 @@ public MultipartContent GetFileUploadContent(params string[] paths)
462483 return content ;
463484 }
464485
465- public async Task PushPackageAsync ( string apiKey , string packagePath , string pushUrl = "/nuget" )
486+ public async Task PushPackageAsync ( string apiKey , string packagePath , string pushUrl = "/nuget" , HttpStatusCode excepectedStatusCode = HttpStatusCode . Created )
466487 {
467488 using ( var request = new HttpRequestMessage ( HttpMethod . Put , pushUrl )
468489 {
@@ -474,7 +495,7 @@ public async Task PushPackageAsync(string apiKey, string packagePath, string pus
474495 } )
475496 using ( var response = await Client . SendAsync ( request ) )
476497 {
477- Assert . Equal ( HttpStatusCode . Created , response . StatusCode ) ;
498+ Assert . Equal ( excepectedStatusCode , response . StatusCode ) ;
478499 }
479500 }
480501
0 commit comments