Esempio n. 1
0
        public async Task GetPackagesWithUpdatesAsync_WithMultipleProjects_RetrievesSingleUpdate3()
        {
            // Arrange
            var testPackageIdentity = new PackageCollectionItem("FakePackage", NuGetVersion.Parse("1.0.0"), null);
            var serviceBroker       = new Mock <IServiceBroker>();
            Mock <INuGetProjectManagerService> projectManagerService = SetupProjectManagerService(serviceBroker);

            // Only one project needs to be updated
            // projectA: 2.0.1 => None
            // projectB: 1.0.0 => 1.0.1
            IProjectContextInfo projectA = SetupProject(projectManagerService, "FakePackage", "2.0.1");
            IProjectContextInfo projectB = SetupProject(projectManagerService, "FakePackage", "1.0.0", "[1,2)");

            SetupRemotePackageMetadata("FakePackage", "0.0.1", "1.0.0", "2.0.1", "2.0.0", "1.0.1");

            var _target = new UpdatePackageFeed(
                serviceBroker.Object,
                new[] { testPackageIdentity },
                _metadataProvider,
                new[] { projectA, projectB },
                optionalCachedUpdates: null,
                NullLogger.Instance);

            // Act
            IEnumerable <IPackageSearchMetadata> packages = await _target.GetPackagesWithUpdatesAsync(
                searchText : "fake",
                new SearchFilter(includePrerelease : false),
                CancellationToken.None);

            // Assert
            // Should retrieve a single update item with the lowest version and full list of available versions
            Assert.Single(packages);
            IPackageSearchMetadata updateCandidate = packages.Single();

            Assert.Equal("1.0.1", updateCandidate.Identity.Version.ToString());

            IEnumerable <VersionInfo> actualVersions = await updateCandidate.GetVersionsAsync();

            Assert.NotEmpty(actualVersions);
            Assert.Equal(
                new[] { "2.0.1", "2.0.0", "1.0.1", "1.0.0", "0.0.1" },
                actualVersions.Select(v => v.Version.ToString()).ToArray());
        }