示例#1
0
 private void UnsetRecommendedVersion(Package package, PublishedPackage publishedPackage)
 {
     package.IsLatestVersion = false;
     publishedPackage.IsLatestVersion = false;
     _packageRepository.Update(package);
     _publishedPackageRepository.Update(publishedPackage);
 }
示例#2
0
 private static void VerifyPackageIsInPublishedState(Package package, PublishedPackage publishedPackage)
 {
     if (package.Published == Constants.UnpublishedDate || publishedPackage == null || publishedPackage.Published == Constants.UnpublishedDate)
     {
         throw new InvalidOperationException("Cannot Unpublish a Package that is not currently Published.");
     }
 }
示例#3
0
 private void Unpublish(Package package, PublishedPackage publishedPackage)
 {
     package.Published = Constants.UnpublishedDate;
     publishedPackage.Published = Constants.UnpublishedDate;
     _packageRepository.Update(package);
     _publishedPackageRepository.Update(publishedPackage);
 }
 public string CreateUri(PublishedPackage package)
 {
     if (package == null)
     {
         throw new ArgumentNullException("package");
     }
     return _configSettings.ReportAbuseUriTemplate.Replace(PackageUriTemplateToken.PackageId, package.Id)
         .Replace(PackageUriTemplateToken.PackageVersion, package.Version);
 }
示例#5
0
        public void ShouldCreateAPackageLogEntryForCreateWhenPackageHasNotBeenPublished()
        {
            var publishedPackageToCreate = new PublishedPackage();
            _mockedMapper.Setup(m => m.Map<Package, PublishedPackage>(_existingPackage)).Returns(publishedPackageToCreate);

            _packagePublisher.PublishPackage("newKey", EXISTING_PACKAGE_ID, EXISTING_PACKAGE_VERSION, LOG_ACTION);

            _mockedPackageLogEntryCreator.Verify(c => c.Create(EXISTING_PACKAGE_ID, EXISTING_PACKAGE_VERSION, PackageLogAction.Create), Times.Once(),
                "PackageLogEntryCreator's Create() should have been called exactly once for a Create action with the expected package ID and version.");
        }
示例#6
0
        public void ShouldIncrementDownloadCountForPackageHostedExternally()
        {
            PublishedPackage externalPackage = new PublishedPackage { Id = "Id", Version = "Version", ExternalPackageUrl = "http://foo.com/" };
            _mockedPublishedPackageRepository.SetupGet(ppr => ppr.Collection).Returns(new[] { externalPackage }.AsQueryable());

            _packageController.Download(externalPackage.Id, externalPackage.Version);

            _mockedIncrementer.Verify(i => i.Increment(externalPackage.Id, externalPackage.Version), Times.Once(),
                "Incrementer should have been called exactly once.");
        }
示例#7
0
        public void ShouldIncrementDownloadCountForPackageHostedByServer()
        {
            PublishedPackage internalPackage = new PublishedPackage {Id = "Id", Version = "Version", ExternalPackageUrl = null};
            _mockedPublishedPackageRepository.SetupGet(ppr => ppr.Collection).Returns(new[] { internalPackage}.AsQueryable());
            _mockedPackageFileGetter.Setup(pfg => pfg.GetPackageStream(It.IsAny<string>(), It.IsAny<string>())).Returns(Stream.Null);

            _packageController.Download(internalPackage.Id, internalPackage.Version);

            _mockedIncrementer.Verify(i => i.Increment(internalPackage.Id, internalPackage.Version), Times.Once(),
                "Incrementer should have been called exactly once.");
        }
示例#8
0
        public void ShouldRedirectToExpectedUrlWhenPackageIsHostedExternally()
        {
            PublishedPackage externalPackage = new PublishedPackage { Id = "Id", Version = "Version", ExternalPackageUrl = "http://foo.com/" };
            _mockedPublishedPackageRepository.SetupGet(ppr => ppr.Collection).Returns(new[] { externalPackage }.AsQueryable());

            ActionResult actionResult = _packageController.Download(externalPackage.Id, externalPackage.Version);

            Assert.IsInstanceOf<RedirectResult>(actionResult, "RedirectResult should have been returned.");
            Assert.AreEqual(externalPackage.ExternalPackageUrl, ((RedirectResult)actionResult).Url,
                "Expected redirect URL was not returned in RedirectResult.");
        }
        public void ShouldNotUpdateDownloadCountForNonMatchingPublishedPackage()
        {
            const int expectedDownloadCount = 83;
            var publishedPackageToIgnore = new PublishedPackage { DownloadCount = expectedDownloadCount};
            IQueryable<PublishedPackage> publishedPackages = new[] { publishedPackageToIgnore }.AsQueryable();
            MockedPublishedPackageRepository.SetupGet(ppr => ppr.Collection).Returns(publishedPackages);
            SetupEmptyPackageDataAggregateCollection();

            Updater.IncrementDownloadForPackage(Guid.NewGuid().ToString());

            Assert.AreEqual(expectedDownloadCount, publishedPackageToIgnore.DownloadCount, "DownloadCount for PublishedPackage was not updated.");
        }
示例#10
0
        public string CreateUri(PublishedPackage package)
        {
            if (package == null)
            {
                throw new ArgumentNullException("package");
            }
            string packageTypeSlug = GallerySlugifyPackageType(package.PackageType);

            return _configSettings.GalleryDetailsUriTemplate.Replace(PackageUriTemplateToken.PackageTypeSlug, packageTypeSlug)
                .Replace(PackageUriTemplateToken.PackageId, package.Id)
                .Replace(PackageUriTemplateToken.PackageVersion, package.Version);
        }
示例#11
0
        public void ShouldReturnFileStreamWhenPackageIsHostedOnServer()
        {
            Stream expectedStream = Stream.Null;
            PublishedPackage internalPackage = new PublishedPackage { Id = "Id", Version = "Version", ExternalPackageUrl = null };
            _mockedPublishedPackageRepository.SetupGet(ppr => ppr.Collection).Returns(new[] { internalPackage }.AsQueryable());
            _mockedPackageFileGetter.Setup(pfg => pfg.GetPackageStream(It.IsAny<string>(), It.IsAny<string>())).Returns(expectedStream);

            ActionResult actionResult = _packageController.Download(internalPackage.Id, internalPackage.Version);

            Assert.IsInstanceOf<FileStreamResult>(actionResult, "FileStreamResult should have been returned.");
            Assert.AreEqual(expectedStream, ((FileStreamResult)actionResult).FileStream, "Expected FileStream was not returned in FileStreamResult.");
        }
示例#12
0
        public void ShouldCallLatestVersionUpdaterWhenPackageToPublishIsLatestVersionAndAnotherPackageWithSameIdAlreadyIsTheLastestVersion()
        {
            var publishedPackageToCreate = new PublishedPackage { Id = EXISTING_PACKAGE_ID, IsLatestVersion = true };
            _mockedMapper.Setup(m => m.Map<Package, PublishedPackage>(_existingPackage)).Returns(publishedPackageToCreate);
            _mockedPublishedPackageRepository.SetupGet(ppr => ppr.Collection).Returns(new[]
            {
                new PublishedPackage { Id = EXISTING_PACKAGE_ID, Version = "1.5.6.2", IsLatestVersion = true},
                new PublishedPackage { Id = EXISTING_PACKAGE_ID, Version = "1.6.6.2", IsLatestVersion = false}
            }.AsQueryable());

            _packagePublisher.PublishPackage("newKey", EXISTING_PACKAGE_ID, EXISTING_PACKAGE_VERSION, LOG_ACTION);

            _mockedLatestVersionUpdater.Verify(lvu => lvu.SetLatestVersionFlagsOfOtherVersionablesWithSameId(publishedPackageToCreate), Times.Once(),
                "LatestVersionUpdater should have been called.");
        }
示例#13
0
        public void ShouldCreateAPackageLogEntryUsingSuppliedLogActionWhenPackageHasAlreadyBeenPublished()
        {
            var publishedPackageToCreate = new PublishedPackage { Id = EXISTING_PACKAGE_ID, Version = EXISTING_PACKAGE_VERSION };
            _mockedMapper.Setup(m => m.Map<Package, PublishedPackage>(_existingPackage)).Returns(publishedPackageToCreate);
            _mockedPublishedPackageRepository.SetupGet(r => r.Collection).Returns(new[] {publishedPackageToCreate}.AsQueryable());

            _packagePublisher.PublishPackage("newKey", EXISTING_PACKAGE_ID, EXISTING_PACKAGE_VERSION, LOG_ACTION);

            _mockedPackageLogEntryCreator.Verify(c => c.Create(EXISTING_PACKAGE_ID, EXISTING_PACKAGE_VERSION, LOG_ACTION), Times.Once(),
                "PackageLogEntryCreator's Create() should have been called exactly once for an Update action with the expected package ID and version.");
        }
示例#14
0
        public void ShouldSetIsLatestVersionToTrueWhenNoOtherPublishedPackageWithSameIdIsTheLatestVersion()
        {
            var publishedPackageToCreate = new PublishedPackage { IsLatestVersion = false };
            _mockedMapper.Setup(m => m.Map<Package, PublishedPackage>(_existingPackage)).Returns(publishedPackageToCreate);
            _mockedPublishedPackageRepository.SetupGet(ppr => ppr.Collection).Returns(new[]
            {
                new PublishedPackage { Id = EXISTING_PACKAGE_ID, Version = "1.5.6.2", IsLatestVersion = false},
                new PublishedPackage { Id = EXISTING_PACKAGE_ID, Version = "1.6.6.2", IsLatestVersion = false}
            }.AsQueryable());

            _packagePublisher.PublishPackage("newKey", EXISTING_PACKAGE_ID, EXISTING_PACKAGE_VERSION, LOG_ACTION);

            Assert.IsTrue(publishedPackageToCreate.IsLatestVersion, "IsLatestVersion should have been set to true for the package to publish.");
        }
示例#15
0
        public void ShouldReturnBothPackagesWhenNeitherExistOnFeed()
        {
            const string packageId = "Package";
            var packages = new[] { new Package { Id = packageId, Version = "1.5.35" }, new Package { Id = packageId, Version = "5.88.8" } };
            var publishedPackages = new PublishedPackage[0];
            _mockedPackageRepository.SetupGet(pr => pr.Collection).Returns(packages.AsQueryable());
            _mockedPublishedPackageRepository.SetupGet(ppr => ppr.Collection).Returns(publishedPackages.AsQueryable());

            IEnumerable<Package> unfinishedPackages = _unfinishedPackageGetter.GetUnfinishedPackages(Guid.NewGuid().ToString(), new[] { packageId });

            Assert.AreEqual(2, unfinishedPackages.Count(), "Only one Package should have been returned.");
            CollectionAssert.AreEquivalent(packages, unfinishedPackages, "Expected Packages were not returned.");
        }
        public void ShouldUpdateDownloadCountOfMatchingPublishedPackage()
        {
            PublishedPackage publishedPackageToUpdate = new PublishedPackage { Id = Guid.NewGuid().ToString(), DownloadCount = 38};
            IQueryable<PublishedPackage> publishedPackages = new[] { publishedPackageToUpdate, new PublishedPackage()}.AsQueryable();
            var aggregate = new PackageDataAggregate { PackageId = publishedPackageToUpdate.Id, DownloadCount = 5 };
            int expectedDownloadCount = aggregate.DownloadCount + 1;
            MockedPackageDataAggregateRepository.SetupGet(pdar => pdar.Collection).Returns(new[] { aggregate }.AsQueryable());
            MockedPublishedPackageRepository.SetupGet(ppr => ppr.Collection).Returns(publishedPackages);

            Updater.IncrementDownloadForPackage(publishedPackageToUpdate.Id);

            Assert.AreEqual(expectedDownloadCount, publishedPackageToUpdate.DownloadCount, "DownloadCount for PublishedPackage was not updated.");
        }
示例#17
0
        public void ShouldThrowWhenPublishedPackageWithGivenIdAndVersionDoesNotExist()
        {
            IQueryable<PublishedPackage> publishedPackages = new PublishedPackage[0].AsQueryable();
            _mockedPublishedPackageRepository.SetupGet(ppr => ppr.Collection).Returns(publishedPackages);

            TestDelegate methodThatShouldThrow = () => _packageController.Download("Id", "Version");

            Assert.Throws<PackageFileDoesNotExistException>(methodThatShouldThrow, "Exception should have been thrown.");
        }
示例#18
0
        public void ShouldReturnEmptyListWhenRequestIdsMatchNoExistingUnfinishedPackages()
        {
            var packages = new[] { new Package { Id = "Package", Version = "1.5.35" }, new Package { Id = "AnotherPackage", Version = "5.88.8" } };
            var publishedPackages = new PublishedPackage[0];
            _mockedPackageRepository.SetupGet(pr => pr.Collection).Returns(packages.AsQueryable());
            _mockedPublishedPackageRepository.SetupGet(ppr => ppr.Collection).Returns(publishedPackages.AsQueryable());

            var unfinishedPackages = _unfinishedPackageGetter.GetUnfinishedPackages(Guid.NewGuid().ToString(), new[] { "Foo", "Bar"});

            CollectionAssert.IsEmpty(unfinishedPackages, "No packages should have been returned.");
        }
示例#19
0
        public void ShouldNotCallLatestVersionUpdaterWhenPackageToPublishIsNotLatestVersion()
        {
            var publishedPackageToCreate = new PublishedPackage { IsLatestVersion = false };
            _mockedMapper.Setup(m => m.Map<Package, PublishedPackage>(_existingPackage)).Returns(publishedPackageToCreate);

            _packagePublisher.PublishPackage("newKey", EXISTING_PACKAGE_ID, EXISTING_PACKAGE_VERSION, LOG_ACTION);

            _mockedLatestVersionUpdater.Verify(lvu => lvu.SetLatestVersionFlagsOfOtherVersionablesWithSameId(It.IsAny<PublishedPackage>()), Times.Never(),
                "LatestVersionUpdater should not have been called.");
        }
示例#20
0
        public void ShouldSaveMappedPublishedPackage()
        {
            var publishedPackageToCreate = new PublishedPackage();
            _mockedMapper.Setup(m => m.Map<Package, PublishedPackage>(_existingPackage)).Returns(publishedPackageToCreate);

            _packagePublisher.PublishPackage("newKey", EXISTING_PACKAGE_ID, EXISTING_PACKAGE_VERSION, LOG_ACTION);

            _mockedPublishedPackageRepository.Verify(ppr => ppr.Create(publishedPackageToCreate), Times.Once(),
                "Mapped PublishedPackage should have been created.");
        }
示例#21
0
 public void SetUp()
 {
     _mockedConfigSettings = new Mock<IConfigSettings>();
     _creator = new Infrastructure.Impl.PackageReportAbuseUriCreator(_mockedConfigSettings.Object);
     _testPackage = new PublishedPackage { Id = "TestId", Version = "TestVersion" };
 }