Content changes are collected and published to the queue.
Inheritance: CmisSync.Lib.Queueing.ReportingSyncEventHandler
 public void IgnoresWrongEvent() {
     var storage = new Mock<IMetaDataStorage>();
     var queue = new Mock<ISyncEventQueue>();
     var session = new Mock<ISession>();
     var changes = new ContentChanges(session.Object, storage.Object, queue.Object);
     var startSyncEvent = new Mock<ISyncEvent>().Object;
     Assert.IsFalse(changes.Handle(startSyncEvent));
 }
        public void GivesCorrectContentChangeEvent() {
            ContentChangeEvent contentChangeEvent = null;
            var queue = new Mock<ISyncEventQueue>();
            queue.Setup(q => q.AddEvent(It.IsAny<ContentChangeEvent>())).Callback((ISyncEvent f) => {
                contentChangeEvent = f as ContentChangeEvent;
            });
            string id = "myId";

            Mock<IMetaDataStorage> storage = MockMetaDataStorageUtil.GetMetaStorageMockWithToken();
            var session = MockSessionUtil.PrepareSessionMockForSingleChange(DotCMIS.Enums.ChangeType.Created, id);
            var changes = new ContentChanges(session.Object, storage.Object, queue.Object, this.maxNumberOfContentChanges, this.isPropertyChangesSupported);

            var startSyncEvent = new StartNextSyncEvent(false);
            Assert.IsTrue(changes.Handle(startSyncEvent));

            queue.Verify(foo => foo.AddEvent(It.IsAny<ContentChangeEvent>()), Times.Once());
            Assert.That(contentChangeEvent.Type, Is.EqualTo(DotCMIS.Enums.ChangeType.Created));
            Assert.That(contentChangeEvent.ObjectId, Is.EqualTo(id));
        }
        public void IgnoreDuplicatedContentChangesEventTestDeleted() {
            var queue = new Mock<ISyncEventQueue>();

            Mock<IMetaDataStorage> storage = MockMetaDataStorageUtil.GetMetaStorageMockWithToken();

            Mock<ISession> session = MockSessionUtil.GetSessionMockReturning3Changesin2Batches(DotCMIS.Enums.ChangeType.Deleted, true);

            var startSyncEvent = new StartNextSyncEvent(false);
            var changes = new ContentChanges(session.Object, storage.Object, queue.Object, this.maxNumberOfContentChanges, this.isPropertyChangesSupported);

            Assert.IsTrue(changes.Handle(startSyncEvent));
            queue.Verify(foo => foo.AddEvent(It.IsAny<ContentChangeEvent>()), Times.Exactly(3));
        }
        public void ExecuteCrawlSyncOnNoLocalTokenAvailable() {
            var startSyncEvent = new StartNextSyncEvent(false);
            var session = new Mock<ISession>();
            session.SetupSessionDefaultValues();
            session.Setup(s => s.Binding.GetRepositoryService().GetRepositoryInfo(this.repoId, null).LatestChangeLogToken).Returns(this.changeLogToken);
            var storage = new Mock<IMetaDataStorage>();
            storage.Setup(db => db.ChangeLogToken).Returns((string)null);
            var queue = new Mock<ISyncEventQueue>();
            var changes = new ContentChanges(session.Object, storage.Object, queue.Object);

            Assert.IsTrue(changes.Handle(startSyncEvent));
            queue.Verify(q => q.AddEvent(It.Is<StartNextSyncEvent>(e => e.FullSyncRequested == true)), Times.Once());
        }
 public void ExtendCrawlSyncEvent() {
     var start = new StartNextSyncEvent(true);
     var repositoryService = new Mock<IRepositoryService>();
     repositoryService.Setup(r => r.GetRepositoryInfos(null)).Returns((IList<IRepositoryInfo>)null);
     repositoryService.Setup(r => r.GetRepositoryInfo(It.IsAny<string>(), It.IsAny<IExtensionsData>()).LatestChangeLogToken).Returns(this.latestChangeLogToken);
     var session = new Mock<ISession>();
     session.Setup(s => s.Binding.GetRepositoryService()).Returns(repositoryService.Object);
     session.Setup(s => s.RepositoryInfo.Id).Returns(this.repoId);
     var manager = new Mock<ISyncEventManager>().Object;
     var storage = new Mock<IMetaDataStorage>();
     storage.Setup(db => db.ChangeLogToken).Returns((string)null);
     var queue = new Mock<ISyncEventQueue>();
     var changes = new ContentChanges(session.Object, storage.Object, queue.Object);
     Assert.IsFalse(changes.Handle(start));
     Assert.AreEqual(this.latestChangeLogToken, start.LastTokenOnServer);
 }
 public void HandleStartSyncEventOnNoRemoteChange() {
     var startSyncEvent = new StartNextSyncEvent(false);
     var session = new Mock<ISession>();
     session.SetupSessionDefaultValues();
     session.Setup(s => s.Binding.GetRepositoryService().GetRepositoryInfo(this.repoId, null).LatestChangeLogToken).Returns(this.changeLogToken);
     var storage = new Mock<IMetaDataStorage>();
     storage.Setup(db => db.ChangeLogToken).Returns(this.changeLogToken);
     var queue = new Mock<ISyncEventQueue>();
     var changes = new ContentChanges(session.Object, storage.Object, queue.Object);
     Assert.IsTrue(changes.Handle(startSyncEvent));
 }
 public void HandleFullSyncCompletedEvent() {
     var startSyncEvent = new StartNextSyncEvent(false);
     startSyncEvent.LastTokenOnServer = this.changeLogToken;
     var completedEvent = new FullSyncCompletedEvent(startSyncEvent);
     var storage = new Mock<IMetaDataStorage>();
     storage.SetupProperty(db => db.ChangeLogToken);
     var queue = new Mock<ISyncEventQueue>();
     var session = new Mock<ISession>();
     var changes = new ContentChanges(session.Object, storage.Object, queue.Object);
     Assert.IsFalse(changes.Handle(completedEvent));
     storage.VerifySet(db => db.ChangeLogToken = this.changeLogToken);
     Assert.AreEqual(this.changeLogToken, storage.Object.ChangeLogToken);
 }
 public void RetrunFalseOnError() {
     // TODO: this might not be the best behavior, this test verifies the current implementation not the desired one
     var storage = new Mock<IMetaDataStorage>();
     var queue = new Mock<ISyncEventQueue>();
     var session = new Mock<ISession>();
     session.Setup(x => x.Binding).Throws(new Exception("SOME EXCEPTION"));
     var changes = new ContentChanges(session.Object, storage.Object, queue.Object);
     var wrongEvent = new Mock<ISyncEvent>().Object;
     Assert.IsFalse(changes.Handle(wrongEvent));
 }
Esempio n. 9
0
        private ObservableHandler RunQueue(Mock<ISession> session, Mock<IMetaDataStorage> storage) {
            var manager = new SyncEventManager();

            var observer = new ObservableHandler();
            manager.AddEventHandler(observer);

            SingleStepEventQueue queue = new SingleStepEventQueue(manager);

            var changes = new ContentChanges(session.Object, storage.Object, queue, this.maxNumberOfContentChanges, this.isPropertyChangesSupported);
            manager.AddEventHandler(changes);

            var transformer = new ContentChangeEventTransformer(queue, storage.Object);
            manager.AddEventHandler(transformer);

            var accumulator = new ContentChangeEventAccumulator(session.Object, queue);
            manager.AddEventHandler(accumulator);

            queue.RunStartSyncEvent();

            return observer;
        }
Esempio n. 10
0
        private SingleStepEventQueue CreateQueue(Mock<ISession> session, IMetaDataStorage storage, ObservableHandler observer, IFileSystemInfoFactory fsFactory = null) {
            var manager = new SyncEventManager();
            SingleStepEventQueue queue = new SingleStepEventQueue(manager);

            manager.AddEventHandler(observer);

            var connectionScheduler = new ConnectionScheduler(new RepoInfo(), queue, Mock.Of<ISessionFactory>(), Mock.Of<IAuthenticationProvider>());
            manager.AddEventHandler(connectionScheduler);

            var changes = new ContentChanges(session.Object, storage, queue, this.maxNumberOfContentChanges, this.isPropertyChangesSupported);
            manager.AddEventHandler(changes);

            var transformer = new ContentChangeEventTransformer(queue, storage, fsFactory);
            manager.AddEventHandler(transformer);

            var ccaccumulator = new ContentChangeEventAccumulator(session.Object, queue);
            manager.AddEventHandler(ccaccumulator);

            var remoteFetcher = new RemoteObjectFetcher(session.Object, storage);
            manager.AddEventHandler(remoteFetcher);

            var localFetcher = new LocalObjectFetcher(storage.Matcher, fsFactory);
            manager.AddEventHandler(localFetcher);

            var watcher = new Strategy.WatcherConsumer(queue);
            manager.AddEventHandler(watcher);

            var localDetection = new LocalSituationDetection();
            var remoteDetection = new RemoteSituationDetection();
            var transmissionManager = new TransmissionManager();
            var activityAggregator = new ActivityListenerAggregator(Mock.Of<IActivityListener>(), transmissionManager);

            var ignoreFolderFilter = new IgnoredFoldersFilter();
            var ignoreFolderNameFilter = new IgnoredFolderNameFilter();
            var ignoreFileNamesFilter = new IgnoredFileNamesFilter();
            var invalidFolderNameFilter = new InvalidFolderNameFilter();
            var filterAggregator = new FilterAggregator(ignoreFileNamesFilter, ignoreFolderNameFilter, invalidFolderNameFilter, ignoreFolderFilter);

            var syncMechanism = new SyncMechanism(localDetection, remoteDetection, queue, session.Object, storage, Mock.Of<IFileTransmissionStorage>(), activityAggregator, filterAggregator);
            manager.AddEventHandler(syncMechanism);

            var remoteFolder = MockSessionUtil.CreateCmisFolder();
            remoteFolder.Setup(r => r.Path).Returns(this.remoteRoot);
            var localFolder = new Mock<IDirectoryInfo>();
            localFolder.Setup(f => f.FullName).Returns(this.localRoot);
            var generator = new CrawlEventGenerator(storage, fsFactory);
            var ignoreStorage = new IgnoredEntitiesStorage(new IgnoredEntitiesCollection(), storage);
            var treeBuilder = new DescendantsTreeBuilder(storage, remoteFolder.Object, localFolder.Object, filterAggregator, ignoreStorage);
            var notifier = new CrawlEventNotifier(queue);
            var crawler = new DescendantsCrawler(queue, treeBuilder, generator, notifier, Mock.Of<IActivityListener>());
            manager.AddEventHandler(crawler);

            var permissionDenied = new GenericHandleDublicatedEventsFilter<PermissionDeniedEvent, ConfigChangedEvent>();
            manager.AddEventHandler(permissionDenied);

            var alreadyAddedFilter = new IgnoreAlreadyHandledFsEventsFilter(storage, fsFactory);
            manager.AddEventHandler(alreadyAddedFilter);

            var ignoreContentChangesFilter = new IgnoreAlreadyHandledContentChangeEventsFilter(storage, session.Object);
            manager.AddEventHandler(ignoreContentChangesFilter);

            var delayRetryAndNextSyncEventHandler = new DelayRetryAndNextSyncEventHandler(queue);
            manager.AddEventHandler(delayRetryAndNextSyncEventHandler);

            /* This is not implemented yet
            var failedOperationsFilder = new FailedOperationsFilter(queue);
            manager.AddEventHandler(failedOperationsFilder);
            */

            var reportingFilter = new ReportingFilter(queue, ignoreFolderFilter, ignoreFileNamesFilter, ignoreFolderNameFilter, invalidFolderNameFilter, new SymlinkFilter());
            manager.AddEventHandler(reportingFilter);

            var debugHandler = new DebugLoggingHandler();
            manager.AddEventHandler(debugHandler);

            var movedOrRenamed = new RemoteObjectMovedOrRenamedAccumulator(queue, storage, fsFactory);
            manager.AddEventHandler(movedOrRenamed);

            return queue;
        }