Example #1
0
        private async Task <LucenePackage> SimulateUpdatePackage(LucenePackage currentPackage)
        {
            var date             = new DateTimeOffset(2015, 1, 29, 0, 0, 0, TimeSpan.Zero);
            var modifiedPackages = new[] { "A.1.0.nupkg" };

            currentPackage.Published = date;

            InsertPackage(currentPackage);

            var newPackage = MakeSamplePackage("A", "1.0");

            newPackage.Published = date.AddDays(1);
            loader.Setup(l => l.LoadFromFileSystem(modifiedPackages[0])).Returns(newPackage);

            LucenePackage updatedPackage = null;

            session.Setup(s => s.Add(KeyConstraint.Unique, It.IsAny <LucenePackage>()))
            .Callback <KeyConstraint, LucenePackage[]>((c, p) => { updatedPackage = p.FirstOrDefault(); })
            .Verifiable();

            session.Setup(s => s.Commit()).Verifiable();

            await
            indexer.SynchronizeIndexWithFileSystemAsync(new IndexDifferences(Empty, Empty, modifiedPackages),
                                                        CancellationToken.None);

            session.VerifyAll();
            return(updatedPackage);
        }
        public DataServicePackage(LucenePackage package)
        {
            #region Converted Properties
            Version = package.Version.ToString();
            Authors = String.Join(",", package.Authors);
            Owners = String.Join(",", package.Owners);
            IconUrl = UriToString(package.IconUrl);
            LicenseUrl = UriToString(package.LicenseUrl);
            ProjectUrl = UriToString(package.ProjectUrl);
            Dependencies = String.Join("|", package.Dependencies);
            #endregion

            #region Basic Properties
            Id = package.Id;
            Title = package.Title;
            RequireLicenseAcceptance = package.RequireLicenseAcceptance;
            Description = package.Description;
            Summary = package.Summary;
            ReleaseNotes = package.ReleaseNotes;
            Tags = package.Tags;
            PackageHash = package.PackageHash;
            PackageHashAlgorithm = package.PackageHashAlgorithm;
            PackageSize = package.PackageSize;
            LastUpdated = package.LastUpdated.UtcDateTime;
            Published = package.Published.GetValueOrDefault().UtcDateTime;
            Created = package.Created.UtcDateTime;
            IsAbsoluteLatestVersion = package.IsAbsoluteLatestVersion;
            IsLatestVersion = package.IsLatestVersion;
            IsPrerelease = package.IsPrerelease;
            Listed = package.Listed;
            DownloadCount = package.DownloadCount;
            VersionDownloadCount = package.VersionDownloadCount;
            #endregion
        }
        private void SetupPackageIsModified(string filename)
        {
            var lucenePackage = new LucenePackage(fileSystem.Object);

            loader.Setup(ld => ld.LoadFromIndex(@".\" + filename)).Returns((LucenePackage)null).Verifiable();
            loader.Setup(ld => ld.LoadFromFileSystem(@".\" + filename)).Returns(lucenePackage).Verifiable();
            indexer.Setup(idx => idx.AddPackageAsync(lucenePackage, CancellationToken.None)).Returns(Task.FromResult <object>(null)).Verifiable();
        }
        public void GetPackageIdAndVersionNotFound()
        {
            package = null;

            var result = DownloadPackage(HttpMethod.Head, "SomePackage", SampleVersion.SemanticVersion);

            Assert.That(result.StatusCode, Is.EqualTo(HttpStatusCode.NotFound));
        }
        public void GetPackageIdNotFound()
        {
            package = null;

            var result = DownloadPackage(HttpMethod.Head, "SomePackage", null);

            Assert.That(result.StatusCode, Is.EqualTo(HttpStatusCode.NotFound));
        }
Example #6
0
        protected void InsertPackage(LucenePackage p)
        {
            p.Path = Path.Combine(packagePathResolver.Object.GetPackageDirectory(p),
                                  packagePathResolver.Object.GetPackageFileName(p));

            using (var s = provider.OpenSession(() => new LucenePackage(fileSystem.Object)))
            {
                s.Add(p);
            }
        }
Example #7
0
        protected void InsertPackage(LucenePackage p)
        {
            p.Path = Path.Combine(packagePathResolver.Object.GetPackageDirectory(p),
                                  packagePathResolver.Object.GetPackageFileName(p));

            using (var s = provider.OpenSession(() => new LucenePackage(fileSystem.Object)))
            {
                s.Add(p);
            }
        }
        public void SearchSortsByScore()
        {
            var packages = new LucenePackage[0];

            repo.Setup(r => r.Search("foo", new string[0], false)).Returns(packages.AsQueryable());

            var query = service.Search("foo", "", includePrerelease: false);

            AssertOrderingBy(query, "result => result.Score()");
        }
        public void Search()
        {
            var packages = new LucenePackage[0];
            repo.Setup(r => r.Search("foo", new string[0], false)).Returns(packages.AsQueryable()).Verifiable();
            var queryOptions = SetUpRequestWithOptions("/api/odata/Search()?$orderby=Id");

            controller.Search("foo", "", includePrerelease: false, options: queryOptions);

            repo.VerifyAll();
        }
        private void SetupPackageIsNotModified(string filename)
        {
            var lucenePackage = new LucenePackage(fileSystem.Object)
            {
                Published = null
            };

            loader.Setup(ld => ld.LoadFromIndex(@".\" + filename)).Returns(lucenePackage).Verifiable();
            loader.Setup(ld => ld.LoadFromFileSystem(@".\" + filename)).Returns(lucenePackage).Verifiable();
            indexer.Setup(idx => idx.AddPackageAsync(lucenePackage, CancellationToken.None)).Verifiable();
        }
        public void SearchNoSortWhenSpecifiedInQueryString()
        {
            service.FakeRequestUri = new Uri("http://localhost/packages?$orderby=DownloadCount");
            var packages = new LucenePackage[0];

            repo.Setup(r => r.Search("foo", new string[0], false)).Returns(packages.AsQueryable());

            var query = service.Search("foo", "", includePrerelease: false);

            AssertOrderingBy(query);
        }
Example #12
0
        public void SetUp()
        {
            completeTask = new Task(() => { });
            completeTask.RunSynchronously();

            package = CreatePackage(SampleVersion);

            SetUpRequest(RouteNames.Symbols.Upload, HttpMethod.Put, "api/symbols");

            url = new UrlHelper(request);
        }
        public void Search()
        {
            var packages = new LucenePackage[0];

            repo.Setup(r => r.Search("foo", new string[0], false)).Returns(packages.AsQueryable()).Verifiable();
            var queryOptions = SetUpRequestWithOptions("/api/odata/Search()?$orderby=Id");

            controller.Search("foo", "", includePrerelease: false, options: queryOptions);

            repo.VerifyAll();
        }
        public void SetUp()
        {
            packages = new List <LucenePackage>();

            completeTask = new Task(() => { });
            completeTask.RunSynchronously();

            package = CreatePackage(SampleVersion);

            SetUpRequest(RouteNames.Packages.Search, HttpMethod.Get, "api/packages");
        }
        public async Task PackageDeleted_HandlesException()
        {
            var exception = new Exception("RemovePackage: mock error");
            var lucenePackage = new LucenePackage(fileSystem.Object);

            loader.Setup(ld => ld.LoadFromIndex(@".\Sample.1.0.nupkg")).Returns(lucenePackage);
            indexer.Setup(idx => idx.RemovePackage(lucenePackage)).Throws(exception);
            log.Setup(l => l.Error(exception));

            await watcher.OnPackageDeleted("Sample.1.0.nupkg");

            loader.Verify();
            indexer.Verify();
        }
        public async Task PackageDeleted_HandlesException()
        {
            var exception     = new Exception("RemovePackage: mock error");
            var lucenePackage = new LucenePackage(fileSystem.Object);

            loader.Setup(ld => ld.LoadFromIndex(@"Sample.1.0.nupkg")).Returns(lucenePackage);
            indexer.Setup(idx => idx.RemovePackageAsync(lucenePackage, CancellationToken.None)).Throws(exception);
            log.Setup(l => l.Error(exception)).Verifiable();

            await watcher.OnPackageDeleted("Sample.1.0.nupkg");

            loader.Verify();
            indexer.Verify();
            log.Verify();
        }
Example #17
0
        protected LucenePackage MakeSamplePackage(string id, string version)
        {
            var p = new LucenePackage(path => new MemoryStream())
                        {
                            Id = id,
                            Version = version != null ? new StrictSemanticVersion(version) : null,
                            DownloadCount = -1,
                            VersionDownloadCount = -1
                        };

            if (p.Id != null && version != null)
            {
                p.Path = Path.Combine(packagePathResolver.Object.GetPackageDirectory(p),
                                      packagePathResolver.Object.GetPackageFileName(p));
            }

            return p;
        }
        private HttpResponseMessage EvaluateCacheHeaders(PackageSpec packageSpec, LucenePackage package)
        {
            if (package == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound,
                                                   string.Format("Package {0} version {1} not found.", packageSpec.Id,
                                                                 packageSpec.Version)));
            }

            var etagMatch        = Request.Headers.IfMatch.Any(etag => !etag.IsWeak && etag.Tag == '"' + package.PackageHash + '"');
            var notModifiedSince = Request.Headers.IfModifiedSince.HasValue &&
                                   Request.Headers.IfModifiedSince >= package.LastUpdated;

            if (etagMatch || notModifiedSince)
            {
                return(Request.CreateResponse(HttpStatusCode.NotModified));
            }

            return(null);
        }
Example #19
0
        public ODataPackage(LucenePackage package)
        {
            #region Converted Properties
            Version           = package.Version.ToString();
            NormalizedVersion = package.NormalizedVersion;

            Authors      = String.Join(",", package.Authors);
            Owners       = String.Join(",", package.Owners);
            IconUrl      = UriToString(package.IconUrl);
            LicenseUrl   = UriToString(package.LicenseUrl);
            ProjectUrl   = UriToString(package.ProjectUrl);
            Dependencies = String.Join("|", package.Dependencies);
            #endregion

            #region Basic Properties
            Id           = package.Id;
            Title        = package.Title;
            DisplayTitle = package.DisplayTitle;

            RequireLicenseAcceptance = package.RequireLicenseAcceptance;
            Description             = package.Description;
            Summary                 = package.Summary;
            ReleaseNotes            = package.ReleaseNotes;
            Language                = package.Language;
            Tags                    = package.Tags;
            PackageHash             = package.PackageHash;
            PackageHashAlgorithm    = package.PackageHashAlgorithm;
            PackageSize             = package.PackageSize;
            LastUpdated             = package.LastUpdated.UtcDateTime;
            Published               = package.Published.GetValueOrDefault().UtcDateTime;
            Created                 = package.Created.UtcDateTime;
            IsAbsoluteLatestVersion = package.IsAbsoluteLatestVersion;
            IsLatestVersion         = package.IsLatestVersion;
            IsPrerelease            = package.IsPrerelease;
            Listed                  = package.Listed;
            DownloadCount           = package.DownloadCount;
            VersionDownloadCount    = package.VersionDownloadCount;
            DevelopmentDependency   = package.DevelopmentDependency;
            Score                   = package.Score;
            #endregion
        }
Example #20
0
 public ApiV2Package(LucenePackage package)
 {
     Id = package.Id;
     Version = package.Version.ToString();
     Title = package.Title;
     Authors = String.Join(",", package.Authors);
     Owners = String.Join(",", package.Owners);
     if (package.IconUrl != null)
     {
         IconUrl = package.IconUrl.GetComponents(UriComponents.HttpRequestUrl, UriFormat.Unescaped);
     }
     if (package.LicenseUrl != null)
     {
         LicenseUrl = package.LicenseUrl.GetComponents(UriComponents.HttpRequestUrl, UriFormat.Unescaped);
     }
     if (package.ProjectUrl != null)
     {
         ProjectUrl = package.ProjectUrl.GetComponents(UriComponents.HttpRequestUrl, UriFormat.Unescaped);
     }
     RequireLicenseAcceptance = package.RequireLicenseAcceptance;
     Description = package.Description;
     Summary = package.Summary;
     ReleaseNotes = package.ReleaseNotes;
     Tags = package.Tags;
     Dependencies = String.Join("|", package.DependencySets.SelectMany(ConvertDependencySetToStrings));
     PackageHash = package.PackageHash;
     PackageHashAlgorithm = "SHA512";
     PackageSize = package.PackageSize;
     LastUpdated = package.LastUpdated.UtcDateTime;
     Published = package.Published.GetValueOrDefault().UtcDateTime;
     Created = package.Created.UtcDateTime;
     IsAbsoluteLatestVersion = package.IsAbsoluteLatestVersion;
     IsLatestVersion = package.IsLatestVersion;
     IsPrerelease = package.IsPrerelease;
     Listed = package.Listed;
     DownloadCount = package.DownloadCount;
     VersionDownloadCount = package.VersionDownloadCount;
     Path = package.Path;
 }
 public Task AddPackageAsync(LucenePackage makeSamplePackage)
 {
     return(AddPackageAsync(makeSamplePackage, CancellationToken.None));
 }
 public void SetUp()
 {
     package = new LucenePackage(_ => new MemoryStream());
 }
        private async Task<LucenePackage> SimulateUpdatePackage(LucenePackage currentPackage)
        {
            var date = new DateTimeOffset(2015, 1, 29, 0, 0, 0, TimeSpan.Zero);
            var modifiedPackages = new[] { "A.1.0.nupkg" };
            currentPackage.Published = date;

            InsertPackage(currentPackage);

            var newPackage = MakeSamplePackage("A", "1.0");
            newPackage.Published = date.AddDays(1);
            loader.Setup(l => l.LoadFromFileSystem(modifiedPackages[0])).Returns(newPackage);

            LucenePackage updatedPackage = null;

            session.Setup(s => s.Add(KeyConstraint.Unique, It.IsAny<LucenePackage>()))
                .Callback<KeyConstraint, LucenePackage[]>((c, p) => { updatedPackage = p.FirstOrDefault(); })
                .Verifiable();

            session.Setup(s => s.Commit()).Verifiable();

            await
                indexer.SynchronizeIndexWithFileSystemAsync(new IndexDifferences(Empty, Empty, modifiedPackages),
                    CancellationToken.None);

            session.VerifyAll();
            return updatedPackage;
        }
 private void SetupDeletePackage(string filename)
 {
     var lucenePackage = new LucenePackage(fileSystem.Object);
     loader.Setup(ld => ld.LoadFromIndex(@".\" + filename)).Returns(lucenePackage).Verifiable();
     indexer.Setup(idx => idx.RemovePackageAsync(lucenePackage, CancellationToken.None)).Returns(Task.FromResult<object>(null)).Verifiable();
 }
        private HttpResponseMessage EvaluateCacheHeaders(PackageSpec packageSpec, LucenePackage package)
        {
            if (package == null)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound,
                                                     string.Format("Package {0} version {1} not found.", packageSpec.Id,
                                                                   packageSpec.Version));
            }

            var etagMatch = Request.Headers.IfMatch.Any(etag => !etag.IsWeak && etag.Tag == '"' + package.PackageHash + '"');
            var notModifiedSince = Request.Headers.IfModifiedSince.HasValue &&
                                   Request.Headers.IfModifiedSince >= package.LastUpdated;

            if (etagMatch || notModifiedSince)
            {
                return Request.CreateResponse(HttpStatusCode.NotModified);
            }

            return null;
        }
 private string GetPackageInfoUrl(LucenePackage pkg)
 {
     return(Url.Link(RouteNames.Packages.Info, new { id = pkg.Id, version = pkg.Version }));
 }
 public Task AddPackageAsync(LucenePackage makeSamplePackage)
 {
     return AddPackageAsync(makeSamplePackage, CancellationToken.None);
 }
 public PackageVersionSummary(LucenePackage package, Link link)
     : this(package.Id, package.Title, package.Version, package.LastUpdated, package.VersionDownloadCount, link)
 {
 }
 public PackageVersionSummary(LucenePackage package, Link link)
     : this(package.Id, package.Title, package.Version, package.LastUpdated, package.VersionDownloadCount, link)
 {
     
 }
Example #30
0
 public void SetUp()
 {
     package = new LucenePackage(_ => new MemoryStream());
 }
        private void SetupPackageIsNotModified(string filename)
        {
            var lucenePackage = new LucenePackage(fileSystem.Object) { Published = null };

            loader.Setup(ld => ld.LoadFromIndex(@".\" + filename)).Returns(lucenePackage).Verifiable();
            loader.Setup(ld => ld.LoadFromFileSystem(@".\" + filename)).Returns(lucenePackage).Verifiable();
            indexer.Setup(idx => idx.AddPackageAsync(lucenePackage, CancellationToken.None)).Verifiable();
        }
 private string GetPackageInfoUrl(LucenePackage pkg)
 {
     return Url.Link(RouteNames.Packages.Info, new { id = pkg.Id, version = pkg.Version });
 }
 private void SetupPackageIsModified(string filename)
 {
     var lucenePackage = new LucenePackage(fileSystem.Object);
     loader.Setup(ld => ld.LoadFromIndex(@".\" + filename)).Returns((LucenePackage)null).Verifiable();
     loader.Setup(ld => ld.LoadFromFileSystem(@".\" + filename)).Returns(lucenePackage).Verifiable();
     indexer.Setup(idx => idx.AddPackage(lucenePackage)).Returns(Task.FromResult<object>(null)).Verifiable();
 }