Пример #1
0
        public void GetPackages_SkipsPackagesWithoutHashFile()
        {
            // Arrange
            var barPackage = new PackageBuilder
            {
                Id          = "Foo",
                Version     = new SemanticVersion("1.0.0-beta1-345"),
                Description = "Some description",
            };

            barPackage.Authors.Add("test author");
            barPackage.Files.Add(
                PackageUtility.CreateMockedPackageFile(@"lib\net45", "Foo.dll", "lib contents").Object);

            var fileSystem = new MockFileSystem();

            fileSystem.AddFile(Path.Combine(Path.Combine("Foo", "1.0.0", "Foo.1.0.0.nupkg"), ""));
            var barRoot = Path.Combine("Bar", "1.0.0-beta1-345");

            fileSystem.AddFile(Path.Combine(barRoot, "Bar.nuspec"),
                               @"<?xml version=""1.0""?><package><metadata><id>Bar</id><version>1.0.0.0-beta1-345</version><authors>None</authors><description>None</description></metadata></package>");
            fileSystem.AddFile(Path.Combine(barRoot, "Bar.1.0.0-beta1-345.nupkg.sha512"));
            fileSystem.AddFile(Path.Combine(barRoot, "Bar.1.0.0-beta1-345.nupkg"), GetPackageStream(barPackage));

            var repository = new ExpandedPackageRepository(fileSystem);

            // Act
            var packages = repository.GetPackages().ToList();

            // Assert
            var package = Assert.Single(packages);

            Assert.Equal("Bar", package.Id);
            Assert.Equal(new SemanticVersion("1.0.0-beta1-345"), package.Version);
        }
Пример #2
0
        public async Task <HashSet <ServerPackage> > GetAllAsync(bool enableDelisting, CancellationToken token)
        {
            var allPackages = new ConcurrentBag <ServerPackage>();

            var tasks = _repository
                        .GetPackages()
                        .Select(package => TryAddServerPackageAsync(allPackages, package, enableDelisting, token))
                        .ToList();

            await Task.WhenAll(tasks);

            // Only return unique packages.
            return(new HashSet <ServerPackage>(allPackages, IdAndVersionEqualityComparer.Instance));
        }
Пример #3
0
        /// <summary>
        /// ReadPackagesFromDisk loads all packages from disk and determines additional metadata such as the hash, IsAbsoluteLatestVersion, and IsLatestVersion.
        /// </summary>
        private HashSet <ServerPackage> ReadPackagesFromDisk()
        {
            _logger.Log(LogLevel.Info, "Start reading packages from disk...");
            MonitorFileSystem(false);

            try
            {
                var cachedPackages = new ConcurrentBag <ServerPackage>();

                bool enableDelisting = EnableDelisting;

                var packages = _expandedPackageRepository.GetPackages().ToList();

                Parallel.ForEach(packages, package =>
                {
                    // Create server package
                    var serverPackage = CreateServerPackage(package, enableDelisting);

                    // Add the package to the cache, it should not exist already
                    if (cachedPackages.Contains(serverPackage))
                    {
                        _logger.Log(LogLevel.Warning, "Duplicate package found - {0} {1}", package.Id, package.Version);
                    }
                    else
                    {
                        cachedPackages.Add(serverPackage);
                    }
                });

                _logger.Log(LogLevel.Info, "Finished reading packages from disk.");
                return(new HashSet <ServerPackage>(cachedPackages, PackageEqualityComparer.IdAndVersion));
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Error, "Error while reading packages from disk: {0} {1}", ex.Message, ex.StackTrace);
                throw;
            }
            finally
            {
                MonitorFileSystem(true);
            }
        }
        public async Task Remove_SupportsDisabledUnlisting()
        {
            // Arrange
            using (var directory = new TemporaryDirectory())
            {
                var fileSystem = new PhysicalFileSystem(directory);
                var repository = new ExpandedPackageRepository(fileSystem);
                var logger     = new Infrastructure.NullLogger();

                repository.AddPackage(CreatePackage(PackageId, PackageVersion));

                var target = new ServerPackageStore(fileSystem, repository, logger);

                // Act
                target.Remove(PackageId, PackageVersion, enableDelisting: false);

                // Assert
                Assert.Empty(await target.GetAllAsync(enableDelisting: false, token: Token));
                Assert.Empty(repository.GetPackages());
            }
        }
Пример #5
0
        public void GetPackages_ReturnsAllPackagesInsideDirectory()
        {
            // Arrange
            var fooPackage = new PackageBuilder
            {
                Id          = "Foo",
                Version     = NuGetVersion.Parse("1.0.0"),
                Description = "Some description",
            };

            fooPackage.Authors.Add("test author");
            fooPackage.Files.Add(
                CreateMockedPackageFile(@"lib\net40", "Foo.dll", "lib contents").Object);

            var barPackage = new PackageBuilder
            {
                Id          = "Bar",
                Version     = NuGetVersion.Parse("1.0.0-beta1"),
                Description = "Some description",
            };

            barPackage.Authors.Add("test author");
            barPackage.Files.Add(
                CreateMockedPackageFile("", "README.md", "lib contents").Object);
            barPackage.Files.Add(
                CreateMockedPackageFile(@"content", "qwerty.js", "bar contents").Object);

            barPackage.Files.Add(
                CreateMockedPackageFile(@"lib\net451", "test.dll", "test-dll").Object);

            var fileSystem = new PhysicalFileSystem(tmpDir.Path);
            var fooRoot    = Path.Combine(fileSystem.Root, "foo", "1.0.0");

            fileSystem.AddFile(Path.Combine(fooRoot, "foo.nuspec"),
                               @"<?xml version=""1.0""?><package><metadata><id>Foo</id><version>1.0.0</version><authors>None</authors><description>None</description></metadata></package>");
            fileSystem.AddFile(Path.Combine(fooRoot, "foo.1.0.0.nupkg.sha512"), "Foo-sha");
            fileSystem.AddFile(Path.Combine(fooRoot, "foo.1.0.0.nupkg"), GetPackageStream(fooPackage));

            var barRoot = Path.Combine(fileSystem.Root, "bar", "1.0.0-beta1");

            fileSystem.AddFile(Path.Combine(barRoot, "bar.nuspec"),
                               @"<?xml version=""1.0""?><package><metadata><id>Bar</id><version>1.0.0.0-beta1</version><authors>None</authors><description>None</description></metadata></package>");
            fileSystem.AddFile(Path.Combine(barRoot, "bar.1.0.0-beta1.nupkg.sha512"), "bar-sha");
            fileSystem.AddFile(Path.Combine(barRoot, "bar.1.0.0-beta1.nupkg"), GetPackageStream(barPackage));

            var repository = new ExpandedPackageRepository(fileSystem);

            // Act
            var packages = repository.GetPackages().OrderBy(p => p.Identity.Id).ToList();

            // Assert
            Assert.Equal(2, packages.Count);

            var package = packages[1];

            Assert.Equal("foo", package.Identity.Id);
            Assert.Equal(SemanticVersion.Parse("1.0.0"), package.Identity.Version);
            using (var reader = package.GetReader()) {
                Assert.Equal("Foo", reader.GetIdentity().Id);
                Assert.Equal(package.Identity, reader.GetIdentity());
            }
        }
Пример #6
0
        public void GetPackages_ReturnsAllPackagesInsideDirectory()
        {
            // Arrange
            var fooPackage = new PackageBuilder
            {
                Id          = "Foo",
                Version     = new SemanticVersion("1.0.0"),
                Description = "Some description",
            };

            fooPackage.Authors.Add("test author");
            fooPackage.Files.Add(
                PackageUtility.CreateMockedPackageFile(@"lib\net40", "Foo.dll", "lib contents").Object);

            var barPackage = new PackageBuilder
            {
                Id          = "Bar",
                Version     = new SemanticVersion("1.0.0-beta1"),
                Description = "Some description",
            };

            barPackage.Authors.Add("test author");
            barPackage.Files.Add(
                PackageUtility.CreateMockedPackageFile("", "README.md", "lib contents").Object);
            barPackage.Files.Add(
                PackageUtility.CreateMockedPackageFile(@"content", "qwerty.js", "bar contents").Object);

            barPackage.Files.Add(
                PackageUtility.CreateMockedPackageFile(@"lib\net451", "test.dll", "test-dll").Object);

            var fileSystem = new MockFileSystem();
            var fooRoot    = Path.Combine("Foo", "1.0.0");

            fileSystem.AddFile(Path.Combine(fooRoot, "Foo.nuspec"),
                               @"<?xml version=""1.0""?><package><metadata><id>Foo</id><version>1.0.0</version><authors>None</authors><description>None</description></metadata></package>");
            fileSystem.AddFile(Path.Combine("Foo", "1.0.0", "Foo.1.0.0.nupkg.sha512"), "Foo-sha");
            fileSystem.AddFile(Path.Combine("Foo", "1.0.0", "Foo.1.0.0.nupkg"), GetPackageStream(fooPackage));

            var barRoot = Path.Combine("Bar", "1.0.0-beta1");

            fileSystem.AddFile(Path.Combine(barRoot, "Bar.nuspec"),
                               @"<?xml version=""1.0""?><package><metadata><id>Bar</id><version>1.0.0.0-beta1</version><authors>None</authors><description>None</description></metadata></package>");
            fileSystem.AddFile(Path.Combine("Bar", "1.0.0-beta1", "Bar.1.0.0-beta1.nupkg.sha512"), "bar-sha");
            fileSystem.AddFile(Path.Combine("Bar", "1.0.0-beta1", "Bar.1.0.0-beta1.nupkg"), GetPackageStream(barPackage));

            var repository = new ExpandedPackageRepository(fileSystem);

            // Act
            var packages = repository.GetPackages().ToList();

            // Assert
            Assert.Equal(2, packages.Count);

            var package = packages[0];

            Assert.Equal("Foo", package.Id);
            Assert.Equal(new SemanticVersion("1.0.0"), package.Version);
            var packageFile = Assert.Single(package.GetFiles());

            Assert.Equal(@"lib\net40\Foo.dll", packageFile.Path);
            Assert.Equal(".NETFramework,Version=v4.0", packageFile.TargetFramework.FullName);

            package = packages[1];
            Assert.Equal("Bar", package.Id);
            Assert.Equal(new SemanticVersion("1.0.0-beta1"), package.Version);

            var files = package.GetFiles().OrderBy(p => p.Path.Length).ToList();

            Assert.Equal(3, files.Count);
            Assert.Equal(@"README.md", files[0].Path);

            packageFile = files[1];
            Assert.Equal(@"content\qwerty.js", packageFile.Path);
            Assert.Null(packageFile.TargetFramework);

            packageFile = files[2];
            Assert.Equal(@"lib\net451\test.dll", packageFile.Path);
            Assert.Equal(".NETFramework,Version=v4.5.1", packageFile.TargetFramework.FullName);
        }