コード例 #1
0
        public void PackageFolderReader_Basic()
        {
            using (var packageFile = TestPackagesCore.GetLegacyTestPackage())
            {
                using (var zip = new ZipArchive(File.OpenRead(packageFile)))
                    using (var zipReader = new PackageArchiveReader(zip))
                    {
                        var folder = Path.Combine(Path.GetDirectoryName(packageFile), Guid.NewGuid().ToString());

                        using (var zipFile = new ZipArchive(File.OpenRead(packageFile)))
                        {
                            zipFile.ExtractAll(folder);

                            var folderReader = new PackageFolderReader(folder);

                            Assert.Equal(zipReader.GetIdentity(), folderReader.GetIdentity(), new PackageIdentityComparer());

                            Assert.Equal(zipReader.GetLibItems().Count(), folderReader.GetLibItems().Count());

                            Assert.Equal(zipReader.GetReferenceItems().Count(), folderReader.GetReferenceItems().Count());

                            Assert.Equal(zipReader.GetReferenceItems().First().Items.First(), folderReader.GetReferenceItems().First().Items.First());
                        }
                    }
            }
        }
コード例 #2
0
        public void PackageFolderReader_Basic()
        {
            using (var packageFile = TestPackagesCore.GetLegacyTestPackage())
            {
                using (var zip = new ZipArchive(File.OpenRead(packageFile)))
                    using (var zipReader = new PackageArchiveReader(zip))
                        using (var testDirectory = TestDirectory.Create())
                            using (var zipFile = new ZipArchive(File.OpenRead(packageFile)))
                            {
                                zipFile.ExtractAll(testDirectory);

                                using (var folderReader = new PackageFolderReader(testDirectory))
                                {
                                    Assert.Equal(zipReader.GetIdentity(), folderReader.GetIdentity(), new PackageIdentityComparer());

                                    Assert.Equal(zipReader.GetLibItems().Count(), folderReader.GetLibItems().Count());
                                    var referenceItems = zipReader.GetReferenceItems();
                                    var folderItems    = folderReader.GetReferenceItems();

                                    Assert.Equal(referenceItems.Count(), folderItems.Count());

                                    Assert.Equal(referenceItems.First().Items.First(), folderItems.First().Items.First());
                                }
                            }
            }
        }
コード例 #3
0
        public void PackageReader_NoReferences()
        {
            using (var packageFile = TestPackagesCore.GetLegacyTestPackage())
            {
                var zip = TestPackagesCore.GetZip(packageFile);

                using (PackageArchiveReader reader = new PackageArchiveReader(zip))
                {
                    var groups = reader.GetReferenceItems().ToArray();

                    Assert.Equal(3, groups.Count());

                    Assert.Equal(4, groups.SelectMany(e => e.Items).Count());
                }
            }
        }
コード例 #4
0
        public void PackageReader_SupportedFrameworks()
        {
            using (var packageFile = TestPackagesCore.GetLegacyTestPackage())
            {
                var zip = TestPackagesCore.GetZip(packageFile);

                using (PackageArchiveReader reader = new PackageArchiveReader(zip))
                {
                    string[] frameworks = reader.GetSupportedFrameworks().Select(f => f.DotNetFrameworkName).ToArray();

                    Assert.Equal("Any,Version=v0.0", frameworks[0]);
                    Assert.Equal(".NETFramework,Version=v4.0", frameworks[1]);
                    Assert.Equal(".NETFramework,Version=v4.5", frameworks[2]);
                    Assert.Equal(3, frameworks.Length);
                }
            }
        }
コード例 #5
0
        public async Task Test_ExtractionDoesNotExtractFiles_IfPackageSaveModeDoesNotIncludeFiles()
        {
            // Arrange
            var packageIdentity = new PackageIdentity("packageA", new NuGetVersion("2.0.3"));

            using (var packageFileInfo = TestPackagesCore.GetLegacyTestPackage())
                using (var packagesDirectory = TestDirectory.Create())
                {
                    var pathResolver             = new VersionFolderPathResolver(packagesDirectory);
                    var packageExtractionContext = new PackageExtractionContext(
                        packageSaveMode: PackageSaveMode.Nuspec | PackageSaveMode.Nupkg,
                        xmlDocFileSaveMode: XmlDocFileSaveMode.None,
                        logger: NullLogger.Instance,
                        signedPackageVerifier: null,
                        signedPackageVerifierSettings: null);

                    var versionFolderPathResolver = new VersionFolderPathResolver(packagesDirectory);

                    // Act
                    using (var packageDownloader = new LocalPackageArchiveDownloader(
                               null,
                               packageFileInfo,
                               packageIdentity,
                               NullLogger.Instance))
                    {
                        await PackageExtractor.InstallFromSourceAsync(
                            packageIdentity,
                            packageDownloader,
                            versionFolderPathResolver,
                            packageExtractionContext,
                            CancellationToken.None);
                    }

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

                    AssertDirectoryExists(packageVersionDirectory);
                    AssertFileExists(packageVersionDirectory, pathResolver.GetPackageFileName(packageIdentity.Id, packageIdentity.Version));
                    AssertFileExists(packageVersionDirectory, pathResolver.GetManifestFileName(packageIdentity.Id, packageIdentity.Version));
                    AssertFileExists(packageVersionDirectory, "packagea.2.0.3.nupkg.sha512");

                    Assert.False(File.Exists(Path.Combine(packageVersionDirectory, "lib", "test.dll")));
                }
        }
コード例 #6
0
        public async Task Test_ExtractPackage()
        {
            // Arrange
            var packageIdentity = new PackageIdentity("packageA", new NuGetVersion("2.0.3"));

            using (var packageFileInfo = TestPackagesCore.GetLegacyTestPackage())
                using (var packagesDirectory = TestDirectory.Create())
                {
                    var pathResolver             = new VersionFolderPathResolver(packagesDirectory);
                    var packageExtractionContext = new PackageExtractionContext(
                        packageSaveMode: PackageSaveMode.Defaultv3,
                        xmlDocFileSaveMode: XmlDocFileSaveMode.None,
                        clientPolicyContext: null,
                        logger: NullLogger.Instance);

                    var versionFolderPathResolver = new VersionFolderPathResolver(packagesDirectory);

                    // Act
                    using (var packageDownloader = new LocalPackageArchiveDownloader(
                               null,
                               packageFileInfo,
                               packageIdentity,
                               NullLogger.Instance))
                    {
                        await PackageExtractor.InstallFromSourceAsync(
                            packageIdentity,
                            packageDownloader,
                            versionFolderPathResolver,
                            packageExtractionContext,
                            CancellationToken.None);
                    }

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

                    AssertDirectoryExists(packageVersionDirectory);
                    AssertFileExists(packageVersionDirectory, pathResolver.GetPackageFileName(packageIdentity.Id, packageIdentity.Version));
                    AssertFileExists(packageVersionDirectory, pathResolver.GetManifestFileName(packageIdentity.Id, packageIdentity.Version));
                    AssertFileExists(packageVersionDirectory, "packagea.2.0.3.nupkg.sha512");

                    AssertFileExists(packageVersionDirectory, "lib", "test.dll");
                }
        }
コード例 #7
0
        public async Task Test_ExtractionDoesNotExtractFiles_IfPackageSaveModeDoesNotIncludeFiles()
        {
            // Arrange
            var package = new PackageIdentity("packageA", new NuGetVersion("2.0.3"));

            using (var packageFileInfo = TestPackagesCore.GetLegacyTestPackage())
                using (var packagesDirectory = TestDirectory.Create())
                {
                    var pathResolver             = new VersionFolderPathResolver(packagesDirectory);
                    var versionFolderPathContext = new VersionFolderPathContext(
                        package,
                        packagesDirectory,
                        NullLogger.Instance,
                        packageSaveMode: PackageSaveMode.Nupkg | PackageSaveMode.Nuspec,
                        xmlDocFileSaveMode: XmlDocFileSaveMode.None);

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

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

                    AssertDirectoryExists(packageVersionDirectory);
                    AssertFileExists(packageVersionDirectory, pathResolver.GetPackageFileName(package.Id, package.Version));
                    AssertFileExists(packageVersionDirectory, pathResolver.GetManifestFileName(package.Id, package.Version));
                    AssertFileExists(packageVersionDirectory, "packagea.2.0.3.nupkg.sha512");

                    Assert.False(File.Exists(Path.Combine(packageVersionDirectory, "lib", "test.dll")));
                }
        }