public async Task SetCurrentPackageAsync_SortsVersions_ByNuGetVersionDesc()
        {
            // Arrange
            NuGetVersion installedVersion = NuGetVersion.Parse("1.0.0");

            var testVersions = new List <VersionInfoContextInfo>()
            {
                new VersionInfoContextInfo(new NuGetVersion("2.10.1-dev-01248")),
                new VersionInfoContextInfo(new NuGetVersion("2.10.1-dev-01249")),
                new VersionInfoContextInfo(new NuGetVersion("2.10.1-dev-01256")),
                new VersionInfoContextInfo(new NuGetVersion("2.10.1-dev-01265")),
                new VersionInfoContextInfo(new NuGetVersion("2.10.0-dev-01187")),
                new VersionInfoContextInfo(new NuGetVersion("2.10.0-dev-01191")),
                new VersionInfoContextInfo(new NuGetVersion("2.10.0-dev-01211")),
                new VersionInfoContextInfo(new NuGetVersion("2.10.0")),
            };

            var searchService = new Mock <IReconnectingNuGetSearchService>();

            searchService.Setup(ss => ss.GetPackageVersionsAsync(It.IsAny <PackageIdentity>(), It.IsAny <IReadOnlyCollection <PackageSourceContextInfo> >(), It.IsAny <bool>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(testVersions);

            var vm = new PackageItemViewModel(searchService.Object)
            {
                Id = "package",
                InstalledVersion = installedVersion,
                Version          = installedVersion,
            };

            // Act

            await _testInstance.SetCurrentPackageAsync(
                vm,
                ItemFilter.All,
                () => vm);

            // Assert
            var expectedAdditionalInfo = string.Empty;

            // Remove any added `null` separators, and any Additional Info entries (eg, "Latest Prerelease", "Latest Stable").
            List <DisplayVersion> actualVersions = _testInstance.Versions
                                                   .Where(v => v != null && v.AdditionalInfo == expectedAdditionalInfo).ToList();

            var expectedVersions = new List <DisplayVersion>()
            {
                new DisplayVersion(version: new NuGetVersion("2.10.1-dev-01265"), additionalInfo: expectedAdditionalInfo),
                new DisplayVersion(version: new NuGetVersion("2.10.1-dev-01256"), additionalInfo: expectedAdditionalInfo),
                new DisplayVersion(version: new NuGetVersion("2.10.1-dev-01249"), additionalInfo: expectedAdditionalInfo),
                new DisplayVersion(version: new NuGetVersion("2.10.1-dev-01248"), additionalInfo: expectedAdditionalInfo),
                new DisplayVersion(version: new NuGetVersion("2.10.0"), additionalInfo: expectedAdditionalInfo),
                new DisplayVersion(version: new NuGetVersion("2.10.0-dev-01211"), additionalInfo: expectedAdditionalInfo),
                new DisplayVersion(version: new NuGetVersion("2.10.0-dev-01191"), additionalInfo: expectedAdditionalInfo),
                new DisplayVersion(version: new NuGetVersion("2.10.0-dev-01187"), additionalInfo: expectedAdditionalInfo),
            };

            Assert.Equal(expectedVersions, actualVersions);
        }
Exemplo n.º 2
0
        public LocalPackageSolutionDetailControlModelTests(GlobalServiceProvider sp, LocalPackageSearchMetadataFixture testData)
            : base(sp, testData)
        {
            var solMgr                = new Mock <INuGetSolutionManagerService>();
            var serviceBroker         = new Mock <IServiceBroker>();
            var projectManagerService = new Mock <INuGetProjectManagerService>();

            projectManagerService.Setup(x => x.GetProjectsAsync(It.IsAny <CancellationToken>())).ReturnsAsync(new List <IProjectContextInfo>());

#pragma warning disable ISB001 // Dispose of proxies
            serviceBroker.Setup(x => x.GetProxyAsync <INuGetProjectManagerService>(It.Is <ServiceJsonRpcDescriptor>(d => d.Moniker == NuGetServices.ProjectManagerService.Moniker), It.IsAny <ServiceActivationOptions>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(projectManagerService.Object);
#pragma warning restore ISB001 // Dispose of proxies

            NuGetUIThreadHelper.JoinableTaskFactory.Run(async() =>
            {
                _testInstance = await PackageSolutionDetailControlModel.CreateAsync(
                    solutionManager: solMgr.Object,
                    projects: new List <IProjectContextInfo>(),
                    serviceBroker: serviceBroker.Object,
                    CancellationToken.None);
            });

            _testInstance.SetCurrentPackageAsync(
                _testViewModel,
                ItemFilter.All,
                () => null).Wait();
        }
Exemplo n.º 3
0
        public async Task SetCurrentPackageAsync_SortsVersions_ByNuGetVersionDesc()
        {
            // Arrange
            NuGetVersion installedVersion = NuGetVersion.Parse("1.0.0");

            var testVersions = new List <VersionInfoContextInfo>()
            {
                new VersionInfoContextInfo(new NuGetVersion("2.10.1-dev-01248")),
                new VersionInfoContextInfo(new NuGetVersion("2.10.1-dev-01249")),
                new VersionInfoContextInfo(new NuGetVersion("2.10.1-dev-01256")),
                new VersionInfoContextInfo(new NuGetVersion("2.10.1-dev-01265")),
                new VersionInfoContextInfo(new NuGetVersion("2.10.0-dev-01187")),
                new VersionInfoContextInfo(new NuGetVersion("2.10.0-dev-01191")),
                new VersionInfoContextInfo(new NuGetVersion("2.10.0-dev-01211")),
                new VersionInfoContextInfo(new NuGetVersion("2.10.0")),
            };

            var vm = new PackageItemListViewModel()
            {
                InstalledVersion = installedVersion,
                Version          = installedVersion,
                Versions         = new Lazy <Task <IReadOnlyCollection <VersionInfoContextInfo> > >(() => Task.FromResult <IReadOnlyCollection <VersionInfoContextInfo> >(testVersions)),
            };

            // Act

            await _testInstance.SetCurrentPackageAsync(
                vm,
                ItemFilter.All,
                () => vm);

            // Assert
            var expectedAdditionalInfo = string.Empty;

            // Remove any added `null` separators, and any Additional Info entries (eg, "Latest Prerelease", "Latest Stable").
            List <DisplayVersion> actualVersions = _testInstance.Versions
                                                   .Where(v => v != null && v.AdditionalInfo == expectedAdditionalInfo).ToList();

            var expectedVersions = new List <DisplayVersion>()
            {
                new DisplayVersion(version: new NuGetVersion("2.10.1-dev-01265"), additionalInfo: expectedAdditionalInfo),
                new DisplayVersion(version: new NuGetVersion("2.10.1-dev-01256"), additionalInfo: expectedAdditionalInfo),
                new DisplayVersion(version: new NuGetVersion("2.10.1-dev-01249"), additionalInfo: expectedAdditionalInfo),
                new DisplayVersion(version: new NuGetVersion("2.10.1-dev-01248"), additionalInfo: expectedAdditionalInfo),
                new DisplayVersion(version: new NuGetVersion("2.10.0"), additionalInfo: expectedAdditionalInfo),
                new DisplayVersion(version: new NuGetVersion("2.10.0-dev-01211"), additionalInfo: expectedAdditionalInfo),
                new DisplayVersion(version: new NuGetVersion("2.10.0-dev-01191"), additionalInfo: expectedAdditionalInfo),
                new DisplayVersion(version: new NuGetVersion("2.10.0-dev-01187"), additionalInfo: expectedAdditionalInfo),
            };

            Assert.Equal(expectedVersions, actualVersions);
        }
        public V3PackageSolutionDetailControlModelTests(GlobalServiceProvider sp, V3PackageSearchMetadataFixture testData)
            : base(sp, testData)
        {
            var packageSearchMetadata = new List <PackageSearchMetadataContextInfo>()
            {
                PackageSearchMetadataContextInfo.Create(_testData.TestData)
            };

            var mockSearchService = new Mock <INuGetSearchService>();

            mockSearchService.Setup(x =>
                                    x.GetPackageMetadataListAsync(
                                        It.IsAny <string>(),
                                        It.IsAny <IReadOnlyCollection <PackageSourceContextInfo> >(),
                                        It.IsAny <bool>(),
                                        It.IsAny <bool>(),
                                        It.IsAny <CancellationToken>()))
            .Returns(new ValueTask <IReadOnlyCollection <PackageSearchMetadataContextInfo> >(packageSearchMetadata));

            mockSearchService.Setup(x =>
                                    x.GetDeprecationMetadataAsync(
                                        It.IsAny <PackageIdentity>(),
                                        It.IsAny <IReadOnlyCollection <PackageSourceContextInfo> >(),
                                        It.IsAny <bool>(),
                                        It.IsAny <CancellationToken>()))
            .Returns(null);

            mockSearchService.Setup(x => x.GetPackageMetadataAsync(
                                        It.IsAny <PackageIdentity>(),
                                        It.IsAny <IReadOnlyCollection <PackageSourceContextInfo> >(),
                                        It.IsAny <bool>(),
                                        It.IsAny <CancellationToken>()))
            .Returns(new ValueTask <(PackageSearchMetadataContextInfo, PackageDeprecationMetadataContextInfo)>((packageSearchMetadata[0], null)));

            var solMgr                = new Mock <INuGetSolutionManagerService>();
            var serviceBroker         = new Mock <IServiceBroker>();
            var projectManagerService = new Mock <INuGetProjectManagerService>();

            projectManagerService.Setup(x => x.GetProjectsAsync(It.IsAny <CancellationToken>())).ReturnsAsync(new List <IProjectContextInfo>());

#pragma warning disable ISB001 // Dispose of proxies
            serviceBroker.Setup(x => x.GetProxyAsync <INuGetProjectManagerService>(It.Is <ServiceJsonRpcDescriptor>(d => d.Moniker == NuGetServices.ProjectManagerService.Moniker), It.IsAny <ServiceActivationOptions>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(projectManagerService.Object);
            serviceBroker.Setup(
                x => x.GetProxyAsync <INuGetSearchService>(
                    NuGetServices.SearchService,
                    It.IsAny <ServiceActivationOptions>(),
                    It.IsAny <CancellationToken>()))
            .Returns(new ValueTask <INuGetSearchService>(mockSearchService.Object));
#pragma warning restore ISB001 // Dispose of proxies

            NuGetUIThreadHelper.JoinableTaskFactory.Run(async() =>
            {
                _testInstance = await PackageSolutionDetailControlModel.CreateAsync(
                    solutionManager: solMgr.Object,
                    projects: new List <IProjectContextInfo>(),
                    serviceBroker: serviceBroker.Object,
                    CancellationToken.None);

                await _testInstance.SetCurrentPackageAsync(
                    _testViewModel,
                    ItemFilter.All,
                    () => null);
            });
        }