コード例 #1
0
        public void ShouldUpdatePackagePartOnlyWhenGivenUpdateLogAction() {
            PackageLogEntry entryToProcess = new PackageLogEntry { PackageId = "Pack1", PackageVersion = "V1", Action = PackageLogAction.Update };
            _mockedPackageService.Setup(ps => ps.Get(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>())).Returns(new PackagePart());

            _updater.ModifyExistingPackagePart(entryToProcess);

            _mockedIndexingTaskManager.Verify(itm => itm.CreateUpdateIndexTask(It.IsAny<ContentItem>()), Times.Once());
        }
コード例 #2
0
        public void ShouldDeletePackagePartForDeleteLogAction()
        {
            PackageLogEntry entryToProcess = new PackageLogEntry { Action = PackageLogAction.Delete };
            _mockedPackageLogEntryService.Setup(ples => ples.GetUnprocessedLogEntries()).Returns(new[] { entryToProcess });

            _packageSynchronizer.Synchronize();

            _mockedPackagePartDeleter.Verify(ppd => ppd.DeletePackage(entryToProcess), Times.Once(), "PackagePart should have been deleted.");
        }
コード例 #3
0
 private static Expression<Func<PublishedPackage, bool>> GetODataQuery(PackageLogEntry log) {
     Expression<Func<PublishedPackage, bool>> query;
     if (log.Action == PackageLogAction.Download) {
         query = pp => pp.Id == log.PackageId;
     } else {
         query = pp => pp.Id == log.PackageId && pp.Version == log.PackageVersion;
     }
     return query;
 }
コード例 #4
0
        public void ShouldPublishPackagePartWhenGivenRePublishLogAction()
        {
            PackageLogEntry log = new PackageLogEntry { PackageId = "Pack1", PackageVersion = "V1", Action = PackageLogAction.RePublish };
            var packagePart = GetPackagePart(log.PackageId, log.PackageVersion);
            _mockedPackageService.Setup(ps => ps.Get(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>())).Returns(packagePart);

            _updater.ModifyExistingPackagePart(log);

            _mockedPackagePartPublishingService.Verify(ppps => ppps.Publish(packagePart.PackageID, packagePart.PackageVersion), Times.Once());
        }
コード例 #5
0
        public void ShouldUpdatePackagePartAndExtendedInfoForUpdateOrRePublishLogAction(PackageLogAction packageLogAction)
        {
            PackageLogEntry entryToProcess = new PackageLogEntry { Action = packageLogAction };
            _mockedPackageLogEntryService.Setup(ples => ples.GetUnprocessedLogEntries()).Returns(new[] { entryToProcess });

            _packageSynchronizer.Synchronize();

            _mockedPackagePartUpdater.Verify(ppu => ppu.ModifyExistingPackagePart(entryToProcess, true), Times.Once(),
                "PackagePart and extended info should have been updated.");
        }
コード例 #6
0
 private void UpdatePackage(PackageLogEntry log, PublishedPackage publishedPackage, PackagePart packagePart) {
     if (log.Action == PackageLogAction.Update || log.Action == PackageLogAction.RePublish) {
         _packagePartMapper.MapPublishedPackageToPackagePart(publishedPackage, packagePart);
         _recommendedVersionUpdater.SetRecommendedVersionFlagsOfOtherPackagesWithSameId(packagePart);
     }
     else {
         packagePart.DownloadCount = publishedPackage.VersionDownloadCount;
         packagePart.TotalDownloadCount = publishedPackage.DownloadCount;
     }
 }
コード例 #7
0
 public void DeletePackage(PackageLogEntry log) {
     _packageService.Delete(log.PackageId, log.PackageVersion);
     _screenshotPartDeleter.DeleteScreenshotsForPackage(log.PackageId, log.PackageVersion);
     foreach (var publishedPackage in _oDataContext.Packages.Where(p => p.Id == log.PackageId)) {
         PackagePart packagePart = _packageService.Get(publishedPackage.Id, publishedPackage.Version, true);
         if (packagePart != null) {
             packagePart.TotalDownloadCount = publishedPackage.DownloadCount;
         } else {
             Logger.Information("Tried to update total download count for package {0}, version {1}, but did not find it in Orchard database.");
         }
     }
     Logger.Information("Deleted PackagePart '{0}', version {1} from Orchard database.", log.PackageId, log.PackageVersion);
 }
コード例 #8
0
ファイル: UnpublishTester.cs プロジェクト: NickAndersonX/xodb
        public void Setup() {
            _mockedContentManager = new Mock<IContentManager>();
            _mockedPackageService = new Mock<IPackageService>();

            _existingPackagePart = new PackagePart {
                Record = new PackagePartRecord { PackageID = "PackageId", PackageVersion = "1.3" },
                ContentItem = new ContentItem { VersionRecord = new ContentItemVersionRecord { Published = true} }
            };
            _log = new PackageLogEntry { PackageId = _existingPackagePart.PackageID, PackageVersion = _existingPackagePart.PackageVersion,
                Action = PackageLogAction.Unpublish };
            _mockedPackageService.Setup(ps => ps.Get(_existingPackagePart.PackageID, _existingPackagePart.PackageVersion, true))
                .Returns(_existingPackagePart);

            _publishingService = new Gallery.PackageSynchronization.PackagePartPublishingService(_mockedContentManager.Object, _mockedPackageService.Object);
        }
コード例 #9
0
 public void ModifyExistingPackagePart(PackageLogEntry log, bool updateExtendedPackageInfo) {
     foreach (var publishedPackage in _oDataContext.Packages.Where(GetODataQuery(log))) {
         var packagePart = _packageService.Get(publishedPackage.Id, publishedPackage.Version);
         if (packagePart != null) {
             UpdatePackage(log, publishedPackage, packagePart);
             if (updateExtendedPackageInfo) {
                 _packagePartExtendedInfoUpdater.UpdateExtendedPackageInfo(publishedPackage, packagePart);
             }
             if (log.Action == PackageLogAction.RePublish) {
                 _packagePartPublishingService.Publish(packagePart.PackageID, packagePart.PackageVersion);
             }
             _indexingTaskManager.CreateUpdateIndexTask(packagePart.ContentItem);
             Logger.Information("Updated PackagePart '{0}', version {1}. Extended info updated: {2}", log.PackageId, log.PackageVersion,
                 updateExtendedPackageInfo);
         }
     }
 }
コード例 #10
0
ファイル: PackageLogEntryCreator.cs プロジェクト: dioptre/nkd
 public void Create(string packageId, string packageVersion, PackageLogAction action)
 {
     if (string.IsNullOrWhiteSpace(packageId))
     {
         throw new ArgumentNullException("packageId");
     }
     if (string.IsNullOrWhiteSpace(packageVersion))
     {
         throw new ArgumentNullException("packageVersion");
     }
     var packageLogEntry = new PackageLogEntry
     {
         PackageId = packageId,
         PackageVersion = packageVersion,
         DateLogged = _dateTime.UtcNow,
         Action = action
     };
     _packageLogEntryRepository.Create(packageLogEntry);
 }
コード例 #11
0
        public void CreateNewPackagePart(PackageLogEntry log) {
            PublishedPackage publishedPackage = _oDataContext.Packages.Where(pp => pp.Id == log.PackageId && pp.Version == log.PackageVersion)
                .ToList().FirstOrDefault();
            if (publishedPackage == null) {
                Logger.Information("Package '{0}', version {1} was not created since it was not found on the Feed.", log.PackageId, log.PackageVersion);
                return;
            }
            if (_packageService.PackageExists(log.PackageId, log.PackageVersion, VersionOptions.AllVersions)) {
                Logger.Information("Package '{0}', version {1} was not created since it already exists in the gallery.", log.PackageId, log.PackageVersion);
                return;
            }
            PackagePart packagePart = _orchardServices.ContentManager.New<PackagePart>("Package");
            _packagePartMapper.MapPublishedPackageToPackagePart(publishedPackage, packagePart);
            _orchardServices.ContentManager.Create(packagePart, VersionOptions.Published);

            _packagePartExtendedInfoUpdater.UpdateExtendedPackageInfo(publishedPackage, packagePart);
            _recommendedVersionUpdater.SetRecommendedVersionFlagsOfOtherPackagesWithSameId(packagePart);
            Logger.Information("Created PackagePart '{0}', version {1}.", log.PackageId, log.PackageVersion);
        }
コード例 #12
0
        public void ShouldNotMapPackagePartWhenGivenDownloadLogAction() {
            PackageLogEntry entryToProcess = new PackageLogEntry { PackageId = "Pack1", PackageVersion = "V1", Action = PackageLogAction.Download };
            _mockedPackageService.Setup(ps => ps.Get(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>())).Returns(GetPackagePart());

            _updater.ModifyExistingPackagePart(entryToProcess);

            _mockedPackagePartMapper.Verify(ppm => ppm.MapPublishedPackageToPackagePart(It.IsAny<PublishedPackage>(), It.IsAny<PackagePart>()),
                Times.Never());
        }
コード例 #13
0
        public void ShouldUpdatePackagePartOnlyForDownloadLogAction()
        {
            PackageLogEntry entryToProcess = new PackageLogEntry { Action = PackageLogAction.Download };
            _mockedPackageLogEntryService.Setup(ples => ples.GetUnprocessedLogEntries()).Returns(new[] { entryToProcess });

            _packageSynchronizer.Synchronize();

// ReSharper disable RedundantArgumentDefaultValue
            _mockedPackagePartUpdater.Verify(ppu => ppu.ModifyExistingPackagePart(entryToProcess, false), Times.Once(),
                "PackagePart should have been updated and extended info should not have been updated.");
// ReSharper restore RedundantArgumentDefaultValue
        }
コード例 #14
0
        public void ShouldCallRecommendedVersionUpdaterForPackageUpdateAction() {
            PackageLogEntry entryToProcess = new PackageLogEntry { PackageId = "Pack1", PackageVersion = "V1", Action = PackageLogAction.Update };
            var existingPackage = new PackagePart();
            _mockedPackageService.Setup(ps => ps.Get(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>())).Returns(existingPackage);

            _mockedODataContext.SetupGet(oc => oc.Packages).Returns(
                new[] {
                    new PublishedPackage { Id = "Pack1", Version = "V1" },
                }.AsQueryable());

            _updater.ModifyExistingPackagePart(entryToProcess);

            _mockedRecommendedVersionUpdater.Verify(rvu => rvu.SetRecommendedVersionFlagsOfOtherPackagesWithSameId(existingPackage), Times.Once());
        }
コード例 #15
0
        public void ShouldNotCallRecommendedVersionUpdaterForPackageDownloadAction()
        {
            const PackageLogAction packageLogAction = PackageLogAction.Download;
            PackageLogEntry entryToProcess = new PackageLogEntry { PackageId = "Pack1", PackageVersion = "V1", Action = packageLogAction };
            _mockedPackageService.Setup(ps => ps.Get(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>())).Returns(GetPackagePart());

            _mockedODataContext.SetupGet(oc => oc.Packages).Returns(
                new[] {
                    new PublishedPackage { Id = "Pack1", Version = "V1", IsLatestVersion = true },
                }.AsQueryable());

            _updater.ModifyExistingPackagePart(entryToProcess);

            _mockedRecommendedVersionUpdater.Verify(rvu => rvu.SetRecommendedVersionFlagsOfOtherPackagesWithSameId(It.IsAny<PackagePart>()), Times.Never());
        }
コード例 #16
0
        public void LastPackageLogIdOfSettingsPartShouldBeSetToLastProcessedLogId()
        {
            PackageLogEntry entry = new PackageLogEntry { Action = PackageLogAction.Download };
            PackageLogEntry entryWithExpectedId = new PackageLogEntry { Id=45, Action = PackageLogAction.Download };
            _mockedPackageLogEntryService.Setup(ples => ples.GetUnprocessedLogEntries()).Returns(new[] { entry, entry, entryWithExpectedId });

            _packageSynchronizer.Synchronize();

            Assert.AreEqual(entryWithExpectedId.Id, _gallerySettingsPart.LastPackageLogId, "LastPackageLogId was not updated correctly.");
        }
コード例 #17
0
        public void ShouldUnpublishPackagePartForUnpublishLogAction() {
            PackageLogEntry log = new PackageLogEntry {Action = PackageLogAction.Unpublish};
            _mockedPackageLogEntryService.Setup(ples => ples.GetUnprocessedLogEntries()).Returns(new[] { log });

            _packageSynchronizer.Synchronize();

            _mockedPackagePartUnpublisher.Verify(ppu => ppu.Unpublish(log.PackageId, log.PackageVersion), Times.Once());
        }
コード例 #18
0
        public void ShouldMapDownloadCountForAllPackagesWithSameIdWhenGivenDownloadLogAction()
        {
            PackageLogEntry entryToProcess = new PackageLogEntry { PackageId = "Pack3", PackageVersion = "V2", Action = PackageLogAction.Download };
            var package1 = new PackagePart { Record = new PackagePartRecord() };
            var package2 = new PackagePart { Record = new PackagePartRecord() };
            var package3 = new PackagePart { Record = new PackagePartRecord() };

            _mockedPackageService.Setup(ps => ps.Get("Pack3", "V1", It.IsAny<bool>())).Returns(package1);
            _mockedPackageService.Setup(ps => ps.Get("Pack3", "V2", It.IsAny<bool>())).Returns(package2);
            _mockedPackageService.Setup(ps => ps.Get("Pack3", "V3", It.IsAny<bool>())).Returns(package3);

            _updater.ModifyExistingPackagePart(entryToProcess);

            Assert.AreEqual(5, package1.DownloadCount);
            Assert.AreEqual(6, package2.DownloadCount);
            Assert.AreEqual(7, package3.DownloadCount);
        }
コード例 #19
0
        public void ShouldUpdateAllPackagePartsWithSameIdWhenGivenDownloadLogAction()
        {
            PackageLogEntry entryToProcess = new PackageLogEntry { PackageId = "Pack3", PackageVersion = "V2", Action = PackageLogAction.Download };
            _mockedPackageService.Setup(ps => ps.Get(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>())).Returns(GetPackagePart());

            _updater.ModifyExistingPackagePart(entryToProcess);

            _mockedIndexingTaskManager.Verify(itm => itm.CreateUpdateIndexTask(It.IsAny<ContentItem>()), Times.Exactly(3));
        }