Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/NuGet.CatalogReader/FeedReader/PackageEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,18 @@ public Task<FileInfo> DownloadNuspecAsync(string outputDirectory, DownloadMode m
/// </summary>
protected async Task<FileInfo> DownloadNuspecAsync(string outputDirectory, DownloadMode mode, DateTimeOffset date, CancellationToken token)
{
using (var stream = await GetNupkgAsync(token))
var reader = await GetNuspecAsync(token);

if (reader == null)
{
var path = new FileInfo(Path.Combine(outputDirectory, $"{FileBaseName}.nuspec".ToLowerInvariant()));
throw new InvalidOperationException($"Nuspec not found: {NuspecUri}");
}

await CatalogReaderUtility.DownloadFileAsync(stream, path, date, mode, token);
var path = new FileInfo(Path.Combine(outputDirectory, $"{FileBaseName}.nuspec".ToLowerInvariant()));

return path;
}
File.WriteAllText(path.FullName, reader.Xml.ToString());

return path;
}

/// <summary>
Expand Down
19 changes: 19 additions & 0 deletions test/NuGet.CatalogReader.Tests/CatalogReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,25 @@ public async Task VerifySingleEntriesWhenReadingACatalogAsync()
}
}

[Fact]
public async Task VerifyDownloadNuspec()
{
// Arrange
await VerifyDownloadMode(
async (downloadFolder, entry) =>
{
// Act
var fileInfo = await entry.DownloadNuspecAsync(
downloadFolder,
DownloadMode.Force,
CancellationToken.None);

// Assert
var reader = new NuspecReader(fileInfo.FullName);
Assert.Equal("a", reader.GetId());
});
}

[Fact]
public async Task VerifyDownloadModeSkipIfExists_DoesNotExist()
{
Expand Down