public async Task GetPackageHashAsync_ThrowsIfDisposed()
        {
            using (var test = LocalPackageArchiveDownloaderTest.Create())
            {
                test.Downloader.Dispose();

                var exception = await Assert.ThrowsAsync <ObjectDisposedException>(
                    () => test.Downloader.GetPackageHashAsync(
                        hashAlgorithm: "SHA512",
                        cancellationToken: CancellationToken.None));

                Assert.Equal(nameof(LocalPackageArchiveDownloader), exception.ObjectName);
            }
        }
        public async Task CopyNupkgFileToAsync_ThrowsIfDisposed()
        {
            using (var test = LocalPackageArchiveDownloaderTest.Create())
            {
                test.Downloader.Dispose();

                var exception = await Assert.ThrowsAsync <ObjectDisposedException>(
                    () => test.Downloader.CopyNupkgFileToAsync(
                        destinationFilePath: "a",
                        cancellationToken: CancellationToken.None));

                Assert.Equal(nameof(LocalPackageArchiveDownloader), exception.ObjectName);
            }
        }
        public async Task CopyNupkgFileToAsync_ReturnsTrueOnSuccess()
        {
            using (var test = LocalPackageArchiveDownloaderTest.Create())
            {
                var destinationFilePath = Path.Combine(test.TestDirectory.Path, "copied.nupkg");

                var wasCopied = await test.Downloader.CopyNupkgFileToAsync(
                    destinationFilePath,
                    CancellationToken.None);

                Assert.True(wasCopied);

                var sourceBytes      = File.ReadAllBytes(test.SourcePackageFile.FullName);
                var destinationBytes = File.ReadAllBytes(destinationFilePath);

                Assert.Equal(sourceBytes, destinationBytes);
            }
        }
Beispiel #4
0
        public async Task CopyNupkgFileToAsync_ReturnsFalseIfExceptionHandled()
        {
            using (var test = LocalPackageArchiveDownloaderTest.Create())
            {
                var destinationFilePath = Path.Combine(test.TestDirectory.Path, "a");

                // Locking the destination file path will cause the copy operation to throw.
                using (var fileLock = new FileStream(
                           destinationFilePath,
                           FileMode.Create,
                           FileAccess.Write,
                           FileShare.None))
                {
                    test.Downloader.SetExceptionHandler(exception => Task.FromResult(true));

                    var wasCopied = await test.Downloader.CopyNupkgFileToAsync(
                        destinationFilePath,
                        CancellationToken.None);

                    Assert.False(wasCopied);
                }
            }
        }