Events Created By ContentChange Eventhandler
Inheritance: ISyncEvent
 public void IgnoreNotAccumulatedNonDeleteEvent() {
     var storage = new Mock<IMetaDataStorage>();
     var queue = new Mock<ISyncEventQueue>();
     var e = new ContentChangeEvent(DotCMIS.Enums.ChangeType.Created, Id);
     var transformer = new ContentChangeEventTransformer(queue.Object, storage.Object);
     Assert.Throws<InvalidOperationException>(() => transformer.Handle(e));
 }
        public void DoesNotFilterChangeEventsOfNotExistingObjects() {
            string remoteId = "remoteId";
            var filter = new IgnoreAlreadyHandledContentChangeEventsFilter(Mock.Of<IMetaDataStorage>(), Mock.Of<ISession>());
            var contentChangeEvent = new ContentChangeEvent(DotCMIS.Enums.ChangeType.Updated, remoteId);

            Assert.That(filter.Handle(contentChangeEvent), Is.False);
        }
        public void DocumentDeletionNotAccumulated() {
            var session = new Mock<ISession>();
            var contentChange = new ContentChangeEvent(DotCMIS.Enums.ChangeType.Deleted, Id);
            var accumulator = new ContentChangeEventAccumulator(session.Object, new Mock<ISyncEventQueue>().Object);

            accumulator.Handle(contentChange);
            Assert.That(contentChange.CmisObject, Is.Null);
            session.Verify(foo => foo.GetObject(It.IsAny<string>()), Times.Never());
        }
        public void DocumentCreationAccumulated() {
            var session = new Mock<ISession>();
            var remoteObject = new Mock<ICmisObject>();
            session.Setup(s => s.GetObject(It.IsAny<string>(), It.IsAny<IOperationContext>())).Returns(remoteObject.Object);
            var accumulator = new ContentChangeEventAccumulator(session.Object, new Mock<ISyncEventQueue>().Object);
            var contentChange = new ContentChangeEvent(DotCMIS.Enums.ChangeType.Created, Id);

            Assert.That(accumulator.Handle(contentChange), Is.False);
            Assert.That(contentChange.CmisObject, Is.EqualTo(remoteObject.Object));
        }
        public void CreatedEventForIgnoredObject() {
            this.SetUpMocks();
            var createdObject = MockOfIFolderUtil.CreateRemoteFolderMock(this.folderId, this.folderName, this.remotePath, Guid.NewGuid().ToString());
            createdObject.SetupIgnore("*");
            var createdEvent = new ContentChangeEvent(ChangeType.Created, this.folderId);
            this.session.Setup(s => s.GetObject(It.IsAny<string>(), It.IsAny<IOperationContext>())).Returns(createdObject.Object);
            createdEvent.UpdateObject(this.session.Object);
            this.matcher.Setup(m => m.CanCreateLocalPath(createdObject.Object)).Returns(true);
            this.matcher.Setup(m => m.CreateLocalPath(createdObject.Object)).Returns(this.localPath);

            Assert.That(this.underTest.Handle(createdEvent), Is.False);

            this.ignoreStorage.Verify(s => s.AddOrUpdateEntryAndDeleteAllChildrenFromStorage(It.Is<IIgnoredEntity>(e => e.LocalPath == this.localPath && e.ObjectId == this.folderId)));
            this.queue.VerifyThatNoEventIsAdded();
        }
        public void IgnoreEventsThatHaveBeenDeleted() {
            var queue = new Mock<ISyncEventQueue>();
            var session = new Mock<ISession>();
            session.Setup(s => s.GetObject(It.IsAny<string>(), It.IsAny<IOperationContext>())).Throws(new CmisObjectNotFoundException());
            var accumulator = new ContentChangeEventAccumulator(session.Object, queue.Object);
            var contentChange = new ContentChangeEvent(DotCMIS.Enums.ChangeType.Created, Id);

            Assert.That(accumulator.Handle(contentChange), Is.True);
            queue.Verify(q => q.AddEvent(It.IsAny<StartNextSyncEvent>()), Times.Never());
        }
        private ContentChangeEvent PrepareFolderEvent(DotCMIS.Enums.ChangeType type) {
            var e = new ContentChangeEvent(type, Id);
            var remoteObject = new Mock<IFolder>();
            var session = new Mock<ISession>();
            session.Setup(s => s.GetObject(It.IsAny<string>(), It.IsAny<IOperationContext>())).Returns(remoteObject.Object);

            e.UpdateObject(session.Object);
            return e;
        }
        public void FiltersChangeEventsIfChangeLogTokenIsEqualToLocalObject() {
            string remoteId = "remoteId";
            string changeToken = "Token";
            string parentId = "parentId";
            var session = new Mock<ISession>();
            var storage = new Mock<IMetaDataStorage>();
            var filter = new IgnoreAlreadyHandledContentChangeEventsFilter(storage.Object, session.Object);
            var mappedObject = Mock.Of<IMappedObject>(
                o =>
                o.LastChangeToken == changeToken &&
                o.RemoteObjectId == remoteId &&
                o.ParentId == parentId);
            storage.Setup(s => s.GetObjectByRemoteId(It.Is<string>(id => id == remoteId))).Returns(mappedObject);
            var remoteObject = Mock.Of<IFolder>(
                o =>
                o.ChangeToken == changeToken &&
                o.ParentId == parentId);
            session.Setup(s => s.GetObject(It.Is<string>(id => id == remoteId), It.IsAny<IOperationContext>())).Returns(remoteObject);
            var contentChangeEvent = new ContentChangeEvent(DotCMIS.Enums.ChangeType.Updated, remoteId);

            Assert.That(filter.Handle(contentChangeEvent), Is.True);
        }
        public void ChangedEventForUnchangedIgnoredStateObject() {
            this.SetUpMocks();
            var changedObject = MockOfIFolderUtil.CreateRemoteFolderMock(this.folderId, this.folderName, this.remotePath, Guid.NewGuid().ToString());
            var changeEvent = new ContentChangeEvent(ChangeType.Updated, this.folderId);
            this.session.Setup(s => s.GetObject(It.IsAny<string>(), It.IsAny<IOperationContext>())).Returns(changedObject.Object);
            changeEvent.UpdateObject(this.session.Object);

            Assert.That(this.underTest.Handle(changeEvent), Is.False);

            this.ignoreStorage.Verify(s => s.AddOrUpdateEntryAndDeleteAllChildrenFromStorage(It.IsAny<IIgnoredEntity>()), Times.Never());
            this.queue.VerifyThatNoEventIsAdded();
        }
        private void HandleAsIFolder(ContentChangeEvent contentChangeEvent) {
            IFolder folder = contentChangeEvent.CmisObject as IFolder;

            IMappedObject dir = this.storage.GetObjectByRemoteId(folder.Id);
            IDirectoryInfo dirInfo = (dir == null) ? null : this.fsFactory.CreateDirectoryInfo(this.storage.GetLocalPath(dir));
            var folderEvent = new FolderEvent(dirInfo, folder, this);
            switch(contentChangeEvent.Type)
            {
            case DotCMIS.Enums.ChangeType.Created:
                Logger.Debug("Created Folder Event");
                folderEvent.Remote = MetaDataChangeType.CREATED;
                break;
            case DotCMIS.Enums.ChangeType.Updated:
                folderEvent.Remote = MetaDataChangeType.CHANGED;
                break;
            case DotCMIS.Enums.ChangeType.Security:
                folderEvent.Remote = MetaDataChangeType.CHANGED;
                break;
            }

            Queue.AddEvent(folderEvent);
        }
        private void HandleAsIDocument(ContentChangeEvent contentChangeEvent) {
            IDocument doc = contentChangeEvent.CmisObject as IDocument;
            switch(contentChangeEvent.Type)
            {
            case DotCMIS.Enums.ChangeType.Created:
            {
                var fileEvent = new FileEvent(null, doc) { Remote = MetaDataChangeType.CREATED };
                fileEvent.RemoteContent = doc.ContentStreamId == null ? ContentChangeType.NONE : ContentChangeType.CREATED;
                Queue.AddEvent(fileEvent);
                break;
            }

            case DotCMIS.Enums.ChangeType.Security:
            {
                IMappedObject file = this.storage.GetObjectByRemoteId(doc.Id);
                var fileInfo = (file == null) ? null : this.fsFactory.CreateFileInfo(this.storage.GetLocalPath(file));
                var fileEvent = new FileEvent(fileInfo, doc);
                if (fileInfo != null) {
                    fileEvent.Remote = MetaDataChangeType.CHANGED;
                } else {
                    fileEvent.Remote = MetaDataChangeType.CREATED;
                    if (file != null) {
                        byte[] hash = doc.ContentStreamHash(file.ChecksumAlgorithmName);
                        if (hash == null || !hash.Equals(file.LastChecksum)) {
                            fileEvent.RemoteContent = ContentChangeType.CHANGED;
                        } else {
                            fileEvent.RemoteContent = ContentChangeType.NONE;
                        }
                    } else {
                        fileEvent.RemoteContent = ContentChangeType.CREATED;
                    }
                }

                Queue.AddEvent(fileEvent);
                break;
            }

            case DotCMIS.Enums.ChangeType.Updated:
            {
                IMappedObject file = this.storage.GetObjectByRemoteId(doc.Id);
                var fileInfo = (file == null) ? null : this.fsFactory.CreateFileInfo(this.storage.GetLocalPath(file));
                var fileEvent = new FileEvent(fileInfo, doc);
                if (fileInfo != null) {
                    fileEvent.Remote = MetaDataChangeType.CHANGED;
                    if (file != null) {
                        byte[] hash = doc.ContentStreamHash(file.ChecksumAlgorithmName);
                        if (hash == null || !hash.SequenceEqual(file.LastChecksum)) {
                            Logger.Debug(string.Format("SavedChecksum: {0} RemoteChecksum: {1}", Utils.ToHexString(file.LastChecksum), Utils.ToHexString(hash)));
                            fileEvent.RemoteContent = ContentChangeType.CHANGED;
                        } else {
                            fileEvent.RemoteContent = ContentChangeType.NONE;
                        }
                    } else {
                        fileEvent.Remote = MetaDataChangeType.CREATED;
                        fileEvent.RemoteContent = ContentChangeType.CREATED;
                    }
                } else {
                    fileEvent.Remote = MetaDataChangeType.CREATED;
                    fileEvent.RemoteContent = ContentChangeType.CREATED;
                }

                Queue.AddEvent(fileEvent);
                break;
            }
            }
        }
        private void HandleDeletion(ContentChangeEvent contentChangeEvent) {
            Logger.Debug(contentChangeEvent.ObjectId);
            IMappedObject savedObject = this.storage.GetObjectByRemoteId(contentChangeEvent.ObjectId);
            if (savedObject != null) {
                IMappedObject obj = savedObject as IMappedObject;
                if (obj != null) {
                    if (obj.Type == MappedObjectType.Folder) {
                        var dirInfo = this.fsFactory.CreateDirectoryInfo(this.storage.GetLocalPath(obj));
                        Queue.AddEvent(new FolderEvent(dirInfo, null, this) { Remote = MetaDataChangeType.DELETED });
                        return;
                    } else {
                        var fileInfo = this.fsFactory.CreateFileInfo(this.storage.GetLocalPath(obj));
                        Queue.AddEvent(new FileEvent(fileInfo, null) { Remote = MetaDataChangeType.DELETED });
                        return;
                    }
                }
            }

            Logger.Debug("nothing found in local storage; it has never been synced");
        }
Ejemplo n.º 13
0
        public void DoNotTouchDeletedContentChangeEvents() {
            this.SetupMocks();
            var contentChangeEvent = new ContentChangeEvent(DotCMIS.Enums.ChangeType.Deleted, Guid.NewGuid().ToString());

            Assert.That(this.underTest.Handle(contentChangeEvent), Is.False);

            this.queue.VerifyThatNoEventIsAdded();
        }
Ejemplo n.º 14
0
        public void TransformContentChangeEventFromChangeToDeleteIfTargetIsInsideAnIgnoredFolder() {
            this.SetupMocks();
            var objectId = Guid.NewGuid().ToString();
            var folderObject = Mock.Of<IFolder>(f => f.Id == objectId);
            var contentChangeEvent = new ContentChangeEvent(DotCMIS.Enums.ChangeType.Updated, objectId);
            var session = new Mock<ISession>();
            session.Setup(s => s.GetObject(objectId, It.IsAny<IOperationContext>())).Returns(folderObject);
            contentChangeEvent.UpdateObject(session.Object);
            this.ignores.Setup(i => i.IsIgnored(folderObject)).Returns(IgnoredState.INHERITED);

            Assert.That(this.underTest.Handle(contentChangeEvent), Is.True);

            this.queue.VerifyThatNoOtherEventIsAddedThan<ContentChangeEvent>();
            this.queue.Verify(q => q.AddEvent(It.Is<ContentChangeEvent>(e => e.ObjectId == objectId && e.Type == DotCMIS.Enums.ChangeType.Deleted)));
        }
        public void FilterHandlesDeletedEventsOfNonLocalExistingObjects() {
            var filter = new IgnoreAlreadyHandledContentChangeEventsFilter(Mock.Of<IMetaDataStorage>(), Mock.Of<ISession>());
            var contentChangeEvent = new ContentChangeEvent(DotCMIS.Enums.ChangeType.Deleted, "remoteId");

            Assert.That(filter.Handle(contentChangeEvent), Is.True);
        }
        public void ChangeEventForFormerIgnoredObjectAndNowNotIgnoredObject() {
            this.SetUpMocks();
            var changedObject = MockOfIFolderUtil.CreateRemoteFolderMock(this.folderId, this.folderName, this.remotePath, Guid.NewGuid().ToString());
            var changeEvent = new ContentChangeEvent(ChangeType.Updated, this.folderId);
            this.session.Setup(s => s.GetObject(It.IsAny<string>(), It.IsAny<IOperationContext>())).Returns(changedObject.Object);
            this.ignoreStorage.Setup(i => i.IsIgnoredId(this.folderId)).Returns(IgnoredState.IGNORED);
            changeEvent.UpdateObject(this.session.Object);

            Assert.That(this.underTest.Handle(changeEvent), Is.False);

            this.ignoreStorage.Verify(s => s.AddOrUpdateEntryAndDeleteAllChildrenFromStorage(It.IsAny<IIgnoredEntity>()), Times.Never());
            this.ignoreStorage.Verify(s => s.Remove(this.folderId));
            this.queue.Verify(q => q.AddEvent(It.Is<StartNextSyncEvent>(e => e.FullSyncRequested == true)), Times.Once());
            this.queue.VerifyThatNoOtherEventIsAddedThan<StartNextSyncEvent>();
        }
        public void FilterIgnoresDeletedEventsOfLocalExistingObjects() {
            string remoteId = "remoteId";
            var storage = new Mock<IMetaDataStorage>();
            storage.Setup(s => s.GetObjectByRemoteId(It.Is<string>(id => id == remoteId))).Returns(Mock.Of<IMappedObject>());
            var filter = new IgnoreAlreadyHandledContentChangeEventsFilter(storage.Object, Mock.Of<ISession>());
            var contentChangeEvent = new ContentChangeEvent(DotCMIS.Enums.ChangeType.Deleted, remoteId);

            Assert.That(filter.Handle(contentChangeEvent), Is.False);
        }
        public void DeleteEventForANotIgnoredObject() {
            this.SetUpMocks();
            var deleteEvent = new ContentChangeEvent(ChangeType.Deleted, this.folderId);

            Assert.That(this.underTest.Handle(deleteEvent), Is.False);

            this.ignoreStorage.Verify(i => i.Remove(It.IsAny<string>()), Times.Never());
            this.queue.VerifyThatNoEventIsAdded();
        }
        public void FilterIgnoresFileChangedEventsIfChangeLogTokenIsEqualButParentIdIsDifferent() {
            string remoteId = "remoteId";
            string changeToken = "Token";
            var session = new Mock<ISession>();
            var storage = new Mock<IMetaDataStorage>();
            var filter = new IgnoreAlreadyHandledContentChangeEventsFilter(storage.Object, session.Object);
            var mappedObject = Mock.Of<IMappedObject>(
                o =>
                o.LastChangeToken == changeToken &&
                o.RemoteObjectId == remoteId &&
                o.ParentId == "oldParent");
            storage.Setup(s => s.GetObjectByRemoteId(It.Is<string>(id => id == remoteId))).Returns(mappedObject);
            var remoteDocument = Mock.Of<IDocument>(
                o =>
                o.ChangeToken == changeToken);
            Mock.Get(remoteDocument).SetupParent(Mock.Of<IFolder>(f => f.Id == "newParent"));
            session.Setup(s => s.GetObject(It.Is<string>(id => id == remoteId), It.IsAny<IOperationContext>())).Returns(remoteDocument);
            var contentChangeEvent = new ContentChangeEvent(DotCMIS.Enums.ChangeType.Updated, remoteId);

            Assert.That(filter.Handle(contentChangeEvent), Is.False);
        }
        public void DeleteEventForAFormerIgnoredObject() {
            this.SetUpMocks();
            this.ignoreStorage.Setup(i => i.IsIgnoredId(this.folderId)).Returns(IgnoredState.IGNORED);
            var deleteEvent = new ContentChangeEvent(ChangeType.Deleted, this.folderId);

            Assert.That(this.underTest.Handle(deleteEvent), Is.False);

            this.ignoreStorage.Verify(i => i.Remove(this.folderId), Times.Once());
            this.queue.Verify(q => q.AddEvent(It.Is<StartNextSyncEvent>(e => e.FullSyncRequested == true)));
            this.queue.VerifyThatNoOtherEventIsAddedThan<StartNextSyncEvent>();
        }
        public void DoesNotFilterChangeEventsOfExistingButDifferentObjects() {
            string remoteId = "remoteId";
            string oldToken = "oldToken";
            string newToken = "newToken";
            var session = new Mock<ISession>();
            var storage = new Mock<IMetaDataStorage>();
            var filter = new IgnoreAlreadyHandledContentChangeEventsFilter(storage.Object, session.Object);
            var mappedObject = Mock.Of<IMappedObject>(
                o =>
                o.LastChangeToken == oldToken &&
                o.RemoteObjectId == remoteId);
            storage.Setup(s => s.GetObjectByRemoteId(It.Is<string>(id => id == remoteId))).Returns(mappedObject);
            var remoteObject = Mock.Of<ICmisObject>(
                o =>
                o.ChangeToken == newToken);
            session.Setup(s => s.GetObject(It.Is<string>(id => id == remoteId), It.IsAny<IOperationContext>())).Returns(remoteObject);
            var contentChangeEvent = new ContentChangeEvent(DotCMIS.Enums.ChangeType.Updated, remoteId);

            Assert.That(filter.Handle(contentChangeEvent), Is.False);
        }
        private ContentChangeEvent PrepareEvent(DotCMIS.Enums.ChangeType type, bool hasContentStream, byte[] contentHash = null) {
            var e = new ContentChangeEvent(type, Id);
            var remoteObject = MockOfIDocumentUtil.CreateRemoteDocumentMock(hasContentStream ? "streamId" : null, Id, "name", (string)null);
            if (contentHash != null) {
                remoteObject.SetupContentStreamHash(contentHash);
            }

            var session = new Mock<ISession>();
            session.Setup(s => s.GetObject(It.IsAny<string>(), It.IsAny<IOperationContext>())).Returns(remoteObject.Object);

            e.UpdateObject(session.Object);
            return e;
        }