public override async Task <DownloadResourceResult> GetDownloadResourceResultAsync( PackageIdentity identity, ISettings settings, ILogger logger, CancellationToken token) { if (identity == null) { throw new ArgumentNullException(nameof(identity)); } if (settings == null) { throw new ArgumentNullException(nameof(settings)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } var uri = await GetDownloadUrl(identity, logger, token); if (uri != null) { return(await GetDownloadResultUtility.GetDownloadResultAsync(_client, identity, uri, settings, logger, token)); } return(new DownloadResourceResult(DownloadResourceResultStatus.NotFound)); }
public async Task GetDownloadResultUtility_WithTwoOfTheSameDownloads_DoesNotCollide() { // Arrange var uri = new Uri("http://fake/content.nupkg"); var expectedContent = "TestContent"; var identity = new PackageIdentity("PackageA", NuGetVersion.Parse("1.0.0-Beta")); var testHttpSource = new TestHttpSource( new PackageSource("http://fake"), new Dictionary <string, string> { { uri.ToString(), expectedContent } }); var logger = new TestLogger(); var token = CancellationToken.None; using (var cacheContext = new SourceCacheContext()) using (var downloadDirectory = TestDirectory.Create()) using (var globalPackagesFolder = TestDirectory.Create()) { var downloadContext = new PackageDownloadContext( cacheContext, downloadDirectory, directDownload: true); // Act using (var resultA = await GetDownloadResultUtility.GetDownloadResultAsync( testHttpSource, identity, uri, downloadContext, globalPackagesFolder, logger, token)) using (var resultB = await GetDownloadResultUtility.GetDownloadResultAsync( testHttpSource, identity, uri, downloadContext, globalPackagesFolder, logger, token)) { // Assert var files = Directory.EnumerateFileSystemEntries(downloadDirectory).ToArray(); Assert.Equal(2, files.Length); Assert.EndsWith(".nugetdirectdownload", Path.GetFileName(files[0])); Assert.EndsWith(".nugetdirectdownload", Path.GetFileName(files[1])); var actualContentA = new StreamReader(resultA.PackageStream).ReadToEnd(); Assert.Equal(expectedContent, actualContentA); var actualContentB = new StreamReader(resultB.PackageStream).ReadToEnd(); Assert.Equal(expectedContent, actualContentB); } Assert.Equal(0, Directory.EnumerateFileSystemEntries(downloadDirectory).Count()); Assert.Equal(0, Directory.EnumerateFileSystemEntries(globalPackagesFolder).Count()); } }
public async Task GetDownloadResultUtility_WithSingleDirectDownload_ReturnsTemporaryDownloadResult() { // Arrange var uri = new Uri("http://fake/content.nupkg"); var expectedContent = "TestContent"; var identity = new PackageIdentity("PackageA", NuGetVersion.Parse("1.0.0-Beta")); var testHttpSource = new TestHttpSource( new PackageSource("http://fake"), new Dictionary <string, string> { { uri.ToString(), expectedContent } }); var logger = new TestLogger(); var token = CancellationToken.None; using (var cacheContext = new SourceCacheContext()) using (var downloadDirectory = TestDirectory.Create()) using (var globalPackagesFolder = TestDirectory.Create()) { var downloadContext = new PackageDownloadContext( cacheContext, downloadDirectory, directDownload: true); // Act using (var result = await GetDownloadResultUtility.GetDownloadResultAsync( testHttpSource, identity, uri, downloadContext, globalPackagesFolder, logger, token)) { // Assert Assert.Null(result.PackageReader); Assert.Equal(DownloadResourceResultStatus.Available, result.Status); Assert.NotNull(result.PackageStream); Assert.True(result.PackageStream.CanSeek); Assert.True(result.PackageStream.CanRead); Assert.Equal(0, result.PackageStream.Position); var files = Directory.EnumerateFileSystemEntries(downloadDirectory).ToArray(); Assert.Equal(1, files.Length); Assert.EndsWith(".nugetdirectdownload", Path.GetFileName(files[0])); Assert.Equal(0, Directory.EnumerateFileSystemEntries(globalPackagesFolder).Count()); var actualContent = new StreamReader(result.PackageStream).ReadToEnd(); Assert.Equal(expectedContent, actualContent); } Assert.Equal(0, Directory.EnumerateFileSystemEntries(downloadDirectory).Count()); Assert.Equal(0, Directory.EnumerateFileSystemEntries(globalPackagesFolder).Count()); } }