Skip to content

Commit

Permalink
Moved the DeletePackageFileAsync from IPackageFileService to ICorePac…
Browse files Browse the repository at this point in the history
…kageFileService (#4817)
  • Loading branch information
agr authored Oct 9, 2017
1 parent 337604e commit 6686259
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 22 deletions.
18 changes: 18 additions & 0 deletions src/NuGetGallery.Core/Services/CorePackageFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ public Task DeleteValidationPackageFileAsync(string id, string version)
return _fileStorageService.DeleteFileAsync(CoreConstants.ValidationFolderName, fileName);
}

public Task DeletePackageFileAsync(string id, string version)
{
if (String.IsNullOrWhiteSpace(id))
{
throw new ArgumentNullException(nameof(id));
}

if (String.IsNullOrWhiteSpace(version))
{
throw new ArgumentNullException(nameof(version));
}

var normalizedVersion = NuGetVersionFormatter.Normalize(version);

var fileName = BuildFileName(id, normalizedVersion, CoreConstants.PackageFileSavePathTemplate, CoreConstants.NuGetPackageFileExtension);
return _fileStorageService.DeleteFileAsync(CoreConstants.PackagesFolderName, fileName);
}

public Task<Uri> GetValidationPackageReadUriAsync(Package package, DateTimeOffset endOfAccess)
{
package = package ?? throw new ArgumentNullException(nameof(package));
Expand Down
7 changes: 7 additions & 0 deletions src/NuGetGallery.Core/Services/ICorePackageFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,12 @@ public interface ICorePackageFileService
/// <param name="id">The package ID. This value is case-insensitive.</param>
/// <param name="version">The package version. This value is case-insensitive and need not be normalized.</param>
Task DeleteValidationPackageFileAsync(string id, string version);

/// <summary>
/// Deletes the nupkg from the publicly available package storage.
/// </summary>
/// <param name="id">The package ID. This value is case-insensitive.</param>
/// <param name="version">The package version. This value is case-insensitive and need not be normalized.</param>
Task DeletePackageFileAsync(string id, string version);
}
}
5 changes: 0 additions & 5 deletions src/NuGetGallery/Services/IPackageFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ public interface IPackageFileService : ICorePackageFileService
/// </summary>
Task<ActionResult> CreateDownloadPackageActionResultAsync(Uri requestUrl, string unsafeId, string unsafeVersion);

/// <summary>
/// Deletes the nupkg from the file storage.
/// </summary>
Task DeletePackageFileAsync(string id, string version);

/// <summary>
/// Copies the contents of the package represented by the stream into the file storage backup location.
/// </summary>
Expand Down
16 changes: 0 additions & 16 deletions src/NuGetGallery/Services/PackageFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,6 @@ public Task<ActionResult> CreateDownloadPackageActionResultAsync(Uri requestUrl,
return _fileStorageService.CreateDownloadFileActionResultAsync(requestUrl, CoreConstants.PackagesFolderName, fileName);
}

public Task DeletePackageFileAsync(string id, string version)
{
if (String.IsNullOrWhiteSpace(id))
{
throw new ArgumentNullException(nameof(id));
}

if (String.IsNullOrWhiteSpace(version))
{
throw new ArgumentNullException(nameof(version));
}

var fileName = BuildFileName(id, version, CoreConstants.PackageFileSavePathTemplate, CoreConstants.NuGetPackageFileExtension);
return _fileStorageService.DeleteFileAsync(CoreConstants.PackagesFolderName, fileName);
}

public Task StorePackageFileInBackupLocationAsync(Package package, Stream packageFile)
{
if (package == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace NuGetGallery
public class CorePackageFileServiceFacts
{
private const string ValidationFolderName = "validation";
private const string PackagesFolderName = "packages";
private const string Id = "NuGet.Versioning";
private const string Version = "4.3.0.0-BETA+1";
private const string NormalizedVersion = "4.3.0-BETA";
Expand Down Expand Up @@ -310,7 +311,7 @@ public async Task WillDownloadTheFileViaTheFileStorageService()
}
}

public class TheDeletePackageFileMethod : FactsBase
public class TheDeleteValidationPackageFileMethod : FactsBase
{
[Fact]
public async Task WillThrowIfIdIsNull()
Expand Down Expand Up @@ -348,6 +349,44 @@ public async Task WillDeleteTheFileViaTheFileStorageService()
}
}

public class TheDeletePackageFileMethod : FactsBase
{
[Fact]
public async Task WillThrowIfIdIsNull()
{
string id = null;

var ex = await Assert.ThrowsAsync<ArgumentNullException>(
() => _service.DeletePackageFileAsync(id, Version));

Assert.Equal("id", ex.ParamName);
}

[Fact]
public async Task WillThrowIfVersionIsNull()
{
string version = null;

var ex = await Assert.ThrowsAsync<ArgumentNullException>(
() => _service.DeletePackageFileAsync(Id, version));

Assert.Equal("version", ex.ParamName);
}

[Fact]
public async Task WillDeleteTheFileViaTheFileStorageService()
{
await _service.DeletePackageFileAsync(Id, Version);

_fileStorageService.Verify(
x => x.DeleteFileAsync(PackagesFolderName, ValidationFileName),
Times.Once);
_fileStorageService.Verify(
x => x.DeleteFileAsync(It.IsAny<string>(), It.IsAny<string>()),
Times.Once);
}
}

public class TheGetValidationPackageReadUriAsyncMethod : FactsBase
{
[Fact]
Expand Down

0 comments on commit 6686259

Please sign in to comment.