Ejemplo n.º 1
0
        public async Task TestPowerShellAutocompleteResourceForPackageVersions(string SourceUrl)
        {
            SourceRepository       repo     = GetSourceRepository(SourceUrl);
            PSAutoCompleteResource resource = await repo.GetResource <PSAutoCompleteResource>();

            //Check if we are able to obtain a resource
            Assert.True(resource != null);
            // Check if non zero version count is returned. *TODOS : Use a standard test packages whose version count will be fixed
            IEnumerable <NuGetVersion> versions = await resource.VersionStartsWith("Nuget.core", "1", true, CancellationToken.None);

            Assert.True(versions.Count() == 13);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get IPowerShellPackage from the remote package source
        /// </summary>
        /// <param name="autoCompleteResource"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        private IPowerShellPackage GetIPowerShellPackageFromRemoteSource(PSAutoCompleteResource autoCompleteResource, string id)
        {
            IEnumerable <NuGetVersion> versions = Enumerable.Empty <NuGetVersion>();

            try
            {
                Task <IEnumerable <NuGetVersion> > versionTask = autoCompleteResource.VersionStartsWith(id, Version, IncludePrerelease.IsPresent, CancellationToken.None);
                versions = versionTask.Result;
            }
            catch (Exception) { }

            IPowerShellPackage package = new PowerShellPackage();

            package.Id = id;
            if (AllVersions.IsPresent)
            {
                if (versions != null && versions.Any())
                {
                    package.Versions = versions.OrderByDescending(v => v);
                    LegacyNuGet.SemanticVersion sVersion;
                    LegacyNuGet.SemanticVersion.TryParse(package.Versions.FirstOrDefault().ToNormalizedString(), out sVersion);
                    package.Version = sVersion;
                }
            }
            else
            {
                NuGetVersion nVersion = null;
                if (versions != null && versions.Any())
                {
                    nVersion = versions.OrderByDescending(v => v).FirstOrDefault();
                }

                if (nVersion != null)
                {
                    package.Versions = new List <NuGetVersion>()
                    {
                        nVersion
                    };
                    LegacyNuGet.SemanticVersion sVersion;
                    LegacyNuGet.SemanticVersion.TryParse(nVersion.ToNormalizedString(), out sVersion);
                    package.Version = sVersion;
                }
            }
            return(package);
        }