public Task <IReadOnlyList <string> > Execute(
            string id,
            bool?includePrerelease = false,
            string semVerLevel     = null)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                throw new ArgumentNullException(nameof(id));
            }

            // default filters
            var query = _packageRepository.GetAll()
                        .Include(p => p.PackageRegistration)
                        .Where(p => p.PackageRegistration.Id == id)
                        .Where(p => p.PackageStatusKey == PackageStatus.Available && p.Listed)
                        .Where(SemVerLevelKey.IsPackageCompliantWithSemVerLevelPredicate(semVerLevel));

            // prerelease filter
            if (!includePrerelease.HasValue || !includePrerelease.Value)
            {
                query = query.Where(p => !p.IsPrerelease);
            }

            var versions = query.Select(p => p.Version).ToList();

            // return the result of the query
            return(Task.FromResult <IReadOnlyList <string> >(versions));
        }
            private static void AssertPackageIsComplianceWithSemVerLevel(int?packageSemVerLevelKey, string semVerLevel, bool shouldBeCompliant)
            {
                var package = new Package {
                    SemVerLevelKey = packageSemVerLevelKey
                };
                var compiledFunction = SemVerLevelKey.IsPackageCompliantWithSemVerLevelPredicate(semVerLevel).Compile();

                Assert.Equal(shouldBeCompliant, compiledFunction(package));
            }
        public Task <IReadOnlyList <string> > Execute(
            string partialId,
            bool?includePrerelease = false,
            bool?includeTestData   = false, // ignored on this implementation
            string semVerLevel     = null)
        {
            var query = _packageRepository.GetAll()
                        .Include(p => p.PackageRegistration)
                        .Where(p => p.PackageStatusKey == PackageStatus.Available && p.Listed)
                        .Where(SemVerLevelKey.IsPackageCompliantWithSemVerLevelPredicate(semVerLevel));

            // prerelease filter
            if (!includePrerelease.HasValue || !includePrerelease.Value)
            {
                query = query.Where(p => !p.IsPrerelease);
            }

            var ids = new List <string>();

            // filters added for partialId
            if (!string.IsNullOrWhiteSpace(partialId))
            {
                ids = query.Where(p => p.PackageRegistration.Id.StartsWith(partialId))
                      .GroupBy(p => p.PackageRegistration.Id)
                      .Select(group => group.Key)
                      .OrderBy(id => id)
                      .Take(MaxResults)
                      .ToList();
            }
            else
            {
                ids = query
                      .Select(p => p.PackageRegistration)
                      .Distinct()
                      .OrderByDescending(pr => pr.DownloadCount)
                      .Select(pr => pr.Id)
                      .Take(MaxResults)
                      .ToList();
            }

            return(Task.FromResult <IReadOnlyList <string> >(ids));
        }