Пример #1
0
        public void TheRegistrationIndexResponseIsSortedByVersion()
        {
            // Arrange
            var packageId = "BaGet.Test";
            var authors   = new string[] { "test" };

            var packages = new List <Package>
            {
                GetTestPackage(packageId, "3.1.0"),
                GetTestPackage(packageId, "10.0.5"),
                GetTestPackage(packageId, "3.2.0"),
                GetTestPackage(packageId, "3.1.0-pre"),
                GetTestPackage(packageId, "1.0.0-beta1"),
                GetTestPackage(packageId, "1.0.0"),
            };

            var registration = new PackageRegistration(packageId, packages);

            var registrationBuilder = new RegistrationBuilder(_urlGenerator.Object);

            // Act
            var response = registrationBuilder.BuildIndex(registration);

            // Assert
            Assert.Equal(packages.Count, response.Pages[0].ItemsOrNull.Count);
            var index = 0;

            foreach (var package in packages.OrderBy(p => p.Version))
            {
                Assert.Equal(package.Version.ToFullString(), response.Pages[0].ItemsOrNull[index++].PackageMetadata.Version);
            }
        }
Пример #2
0
        public async Task BuildAsync(string packageId, CancellationToken cancellationToken = default)
        {
            var packages = await _packages.FindAsync(packageId, includeUnlisted : true);

            if (!packages.Any())
            {
                _logger.LogError("Could not index package {PackageId} because it does not exist", packageId);
                return;
            }

            var packageRegistration = new PackageRegistration(
                packageId,
                packages);

            // Update the package metadata resource.
            _logger.LogInformation(
                "Updating the package metadata resource for {PackageId}...",
                packageId);

            var index = _registrationBuilder.BuildIndex(packageRegistration);

            await UploadRegistrationIndexAsync(packageId, index, cancellationToken);

            // Update the search service.
            _logger.LogInformation(
                "Updating the search service for {PackageId}...",
                packageId);

            var actions = _actionBuilder.UpdatePackage(packageRegistration);

            await _search.IndexAsync(actions, cancellationToken);

            _logger.LogInformation("Indexed package {PackageId}", packageId);
        }