コード例 #1
0
        public async Task Test_ExtractionIgnoresNupkgHashFile()
        {
            // Arrange
            var package = new PackageIdentity("packageA", new NuGetVersion("2.0.3"));

            using (var packagesDirectory = TestFileSystemUtility.CreateRandomTestFolder())
            {
                var pathResolver    = new VersionFolderPathResolver(packagesDirectory);
                var packageFileInfo = await TestPackages.GetPackageWithSHA512AtRoot(
                    packagesDirectory,
                    package.Id,
                    package.Version.ToNormalizedString());

                var versionFolderPathContext = new VersionFolderPathContext(
                    package,
                    packagesDirectory,
                    NullLogger.Instance,
                    packageSaveMode: PackageSaveMode.Defaultv3,
                    xmlDocFileSaveMode: XmlDocFileSaveMode.None);

                // Act
                using (var packageFileStream = packageFileInfo.OpenRead())
                {
                    await PackageExtractor.InstallFromSourceAsync(
                        stream => packageFileStream.CopyToAsync(stream),
                        versionFolderPathContext,
                        CancellationToken.None);
                }

                // Assert
                var packageVersionDirectory = pathResolver.GetInstallPath(package.Id, package.Version);

                AssertDirectoryExists(packageVersionDirectory);
                AssertFileExists(packageVersionDirectory, pathResolver.GetPackageFilePath(package.Id, package.Version));
                AssertFileExists(packageVersionDirectory, pathResolver.GetManifestFileName(package.Id, package.Version));
                AssertFileExists(packageVersionDirectory, "lib", "net45", "A.dll");

                var hashPath     = pathResolver.GetHashPath(package.Id, package.Version);
                var hashFileInfo = new FileInfo(hashPath);
                Assert.True(File.Exists(hashFileInfo.FullName));
                Assert.NotEqual(0, hashFileInfo.Length);

                var bsha512Path     = Path.Combine(packageVersionDirectory, "lib", "net45", "B.sha512");
                var bsha512FileInfo = new FileInfo(bsha512Path);
                Assert.True(File.Exists(bsha512FileInfo.FullName));
                Assert.Equal(0, bsha512FileInfo.Length);

                var csha512Path     = Path.Combine(packageVersionDirectory, "C.sha512");
                var csha512FileInfo = new FileInfo(csha512Path);
                Assert.True(File.Exists(csha512FileInfo.FullName));
                Assert.Equal(0, csha512FileInfo.Length);
            }
        }