File event.
Inheritance: AbstractFolderEvent, IFilterableNameEvent, IFilterableRemotePathEvent, IFilterableRemoteObjectEvent, IFilterableLocalPathEvent
Example #1
0
        public void DoNotFilterValidLocalFileAddedEvents() {
            this.SetupMocks();
            IFileInfo file = Mock.Of<IFileInfo>(f => f.FullName == Path.Combine(Path.GetTempPath(), "file.txt"));
            var fileEvent = new FileEvent(file) { Local = MetaDataChangeType.CREATED };

            Assert.That(this.underTest.Handle(fileEvent), Is.False);
        }
        public void NoChangeDetectionForFile() {
            var lastModificationDate = DateTime.Now;
            var remoteObject = new Mock<IDocument>();
            var fileEvent = new FileEvent(remoteFile: remoteObject.Object);
            fileEvent.Remote = MetaDataChangeType.NONE;

            var underTest = new RemoteSituationDetection();

            Assert.AreEqual(SituationType.NOCHANGE, underTest.Analyse(this.storage.Object, fileEvent));
        }
 public void LinearRenames() {
     string objectId = Guid.NewGuid().ToString();
     var collection = new CrawlEventCollection();
     collection.mergableEvents = new Dictionary<string, Tuple<AbstractFolderEvent, AbstractFolderEvent>>();
     var doc1 = Mock.Of<IFileInfo>(d => d.Name == "C" && d.Uuid == Guid.NewGuid());
     var doc2 = Mock.Of<IDocument>(d => d.Name == "B" && d.Id == objectId);
     FileEvent event1 = new FileEvent(doc1, null);
     FileEvent event2 = new FileEvent(null, doc2);
     collection.mergableEvents.Add(objectId, new Tuple<AbstractFolderEvent, AbstractFolderEvent>(event1, event2));
     Assert.That(underTest.Detect(collection), Is.Empty);
 }
        public void DoNotFetchIfExtendedAttributeIsMissing() {
            var session = new Mock<ISession>();
            session.SetupSessionDefaultValues();
            IDocument remote = MockOfIDocumentUtil.CreateRemoteDocumentMock(null, Id, "name", (string)null).Object;
            session.Setup(s => s.GetObject(Id, It.IsAny<IOperationContext>())).Returns(remote);

            var storage = new Mock<IMetaDataStorage>();
            storage.AddLocalFile(Path, Id, Uuid);

            var fileEvent = new FileEvent(Mock.Of<IFileInfo>());
            var fetcher = new RemoteObjectFetcher(session.Object, storage.Object);
            fetcher.Handle(fileEvent);

            session.Verify(s => s.GetObject(It.IsAny<string>(), It.IsAny<IOperationContext>()), Times.Never());
        }
        public void FileRenamed() {
            string parentId = "parentId";
            var storage = new Mock<IMetaDataStorage>();
            Guid fileUuid = Guid.NewGuid();
            Guid parentUuid = Guid.NewGuid();
            var parentDirectoryInfo = Mock.Of<IDirectoryInfo>(d => d.Uuid == parentUuid);
            var fileInfo = Mock.Of<IFileInfo>(f => f.Exists == true && f.Uuid == fileUuid && f.Directory == parentDirectoryInfo);
            var fileEvent = new FileEvent(fileInfo) { Local = MetaDataChangeType.MOVED };
            var mappedFile = Mock.Of<IMappedObject>(o => o.Guid == fileUuid && o.ParentId == parentId);
            var mappedParent = Mock.Of<IMappedObject>(o => o.Guid == parentUuid);
            storage.Setup(s => s.GetObjectByGuid(fileUuid)).Returns(mappedFile);
            storage.Setup(s => s.GetObjectByRemoteId(parentId)).Returns(mappedParent);

            Assert.That(this.underTest.Analyse(storage.Object, fileEvent), Is.EqualTo(SituationType.RENAMED));
        }
        public void NoChangeDetectionForFileOnAddedEvent() {
            var lastModificationDate = DateTime.Now;
            var remoteObject = new Mock<IDocument>();
            var remotePaths = new List<string>();
            remotePaths.Add(this.remotePath);
            remoteObject.Setup(remote => remote.ChangeToken).Returns(this.remoteChangeToken);
            remoteObject.Setup(remote => remote.Id).Returns(this.objectId.Id);
            remoteObject.Setup(remote => remote.LastModificationDate).Returns(lastModificationDate);
            remoteObject.Setup(remote => remote.Paths).Returns(remotePaths);
            var file = Mock.Of<IMappedObject>(f =>
                                              f.LastRemoteWriteTimeUtc == lastModificationDate &&
                                              f.RemoteObjectId == this.objectId.Id &&
                                              f.LastChangeToken == this.remoteChangeToken &&
                                              f.Type == MappedObjectType.File);
            this.storage.AddMappedFile(file);
            var fileEvent = new FileEvent(remoteFile: remoteObject.Object) { Remote = MetaDataChangeType.CREATED };

            var underTest = new RemoteSituationDetection();

            Assert.AreEqual(SituationType.NOCHANGE, underTest.Analyse(this.storage.Object, fileEvent));
        }
        public void FileAddedDetection() {
            var fileInfo = Mock.Of<IFileInfo>(f => f.Exists == true);
            var fileEvent = new FileEvent(fileInfo) { Local = MetaDataChangeType.CREATED };

            Assert.That(this.underTest.Analyse(Mock.Of<IMetaDataStorage>(), fileEvent), Is.EqualTo(SituationType.ADDED));
        }
 public void NoChangeOnFile() {
     var fileEvent = new FileEvent(Mock.Of<IFileInfo>()) { Local = MetaDataChangeType.NONE };
     Assert.That(this.underTest.Analyse(Mock.Of<IMetaDataStorage>(), fileEvent), Is.EqualTo(SituationType.NOCHANGE));
 }
        /// <summary>
        /// Handles the FSEvents of files and creates FileEvents.
        /// </summary>
        /// <param name='e'>
        /// The FSEvent.
        /// </param>
        private void HandleFileEvents(IFSEvent e) {
            var movedEvent = e as IFSMovedEvent;
            if (movedEvent != null) {
                var oldfile = this.fsFactory.CreateFileInfo(movedEvent.OldPath);
                var newfile = this.fsFactory.CreateFileInfo(movedEvent.LocalPath);
                var newEvent = new FileMovedEvent(
                    oldfile,
                    newfile,
                    null,
                    null);
                Queue.AddEvent(newEvent);
            } else {
                var file = this.fsFactory.CreateFileInfo(e.LocalPath);
                var newEvent = new FileEvent(file, null);
                switch (e.Type) {
                case WatcherChangeTypes.Created:
                    newEvent.Local = MetaDataChangeType.CREATED;
                    newEvent.LocalContent = ContentChangeType.CREATED;
                    break;
                case WatcherChangeTypes.Changed:
                    newEvent.LocalContent = ContentChangeType.CHANGED;
                    break;
                case WatcherChangeTypes.Deleted:
                    newEvent.Local = MetaDataChangeType.DELETED;
                    newEvent.LocalContent = ContentChangeType.DELETED;
                    break;
                }

                Queue.AddEvent(newEvent);
            }
        }
        public void FileRenameDetectionOnChangeEvent() {
            string remoteId = "remoteId";
            string oldName = "old";
            string newName = "new";
            var remoteFile = new Mock<IDocument>();
            remoteFile.Setup(f => f.Name).Returns(newName);
            remoteFile.Setup(f => f.Id).Returns(remoteId);
            var mappedFile = Mock.Of<IMappedObject>(f =>
                f.RemoteObjectId == remoteId &&
                f.Name == oldName &&
                f.Type == MappedObjectType.File);
            this.storage.AddMappedFile(mappedFile);
            var folderEvent = new FileEvent(remoteFile: remoteFile.Object) { Remote = MetaDataChangeType.CHANGED };

            var underTest = new RemoteSituationDetection();

            Assert.AreEqual(SituationType.RENAMED, underTest.Analyse(this.storage.Object, folderEvent));
        }
 public void FileEventWithIDocument() {
     var session = new Mock<ISession>();
     var storage = new Mock<IMetaDataStorage>();
     var fetcher = new RemoteObjectFetcher(session.Object, storage.Object);
     var fileEvent = new FileEvent(new Mock<IFileInfo>().Object, new Mock<IDocument>().Object);
     fetcher.Handle(fileEvent);
     session.Verify(s => s.GetObject(It.IsAny<string>(), It.IsAny<IOperationContext>()), Times.Never());
 }
        public void FileEventWithoutObjectId() {
            var session = new Mock<ISession>();
            session.SetupSessionDefaultValues();
            IDocument remote = MockOfIDocumentUtil.CreateRemoteDocumentMock(null, Id, "name", (string)null).Object;
            session.Setup(s => s.GetObject(Id, It.IsAny<IOperationContext>())).Returns(remote);

            var storage = new Mock<IMetaDataStorage>();
            storage.AddLocalFile(Path, Id, Uuid);

            var fileInfoMock = new Mock<IFileInfo>();
            fileInfoMock.Setup(f => f.Uuid).Returns(Uuid);
            fileInfoMock.Setup(f => f.Exists).Returns(true);
            var fileEvent = new FileEvent(fileInfoMock.Object);
            var fetcher = new RemoteObjectFetcher(session.Object, storage.Object);

            Assert.That(fetcher.Handle(fileEvent), Is.False);
            Assert.That(fileEvent.RemoteFile, Is.Not.Null);
        }
Example #13
0
 public void EqualityNull() {
     var localFile = Mock.Of<IFileInfo>();
     var fe = new FileEvent(localFile);
     Assert.That(fe.RemoteFile, Is.Null);
     Assert.That(fe, Is.Not.EqualTo(null));
 }
Example #14
0
 public void ConstructorTakesRemoteFile() {
     var file = Mock.Of<IDocument>();
     var ev = new FileEvent(null, file);
     Assert.That(ev.RemoteFile, Is.EqualTo(file));
 }
Example #15
0
 public void ConstructorTakesIFileInfoInstance() {
     var file = Mock.Of<IFileInfo>();
     var ev = new FileEvent(file);
     Assert.That(ev.LocalFile, Is.EqualTo(file));
 }
Example #16
0
 public void RemotePathRequestFailsReturnsNull() {
     var remoteFile = new Mock<IDocument>();
     remoteFile.Setup(r => r.Paths).Throws(new DotCMIS.Exceptions.CmisRuntimeException());
     var fileEvent = new FileEvent(remoteFile: remoteFile.Object);
     Assert.That(fileEvent.RemotePath, Is.Null);
 }
Example #17
0
 public void RemotePathIsNullIfRemoteObjectDoesNotContainAPath() {
     var fileEvent = new FileEvent(remoteFile: Mock.Of<IDocument>());
     Assert.That(fileEvent.RemotePath, Is.Null);
 }
Example #18
0
 public void RemotePathIsNullIfNoRemoteFileIsSet() {
     var fileEvent = new FileEvent(localFile: Mock.Of<IFileInfo>());
     Assert.That(fileEvent.RemotePath, Is.Null);
 }
        public void FileContentChanged() {
            var fileInfo = Mock.Of<IFileInfo>(f => f.Exists == true);
            var fileEvent = new FileEvent(fileInfo) { Local = MetaDataChangeType.NONE, LocalContent = ContentChangeType.CHANGED };

            Assert.That(this.underTest.Analyse(Mock.Of<IMetaDataStorage>(), fileEvent), Is.EqualTo(SituationType.CHANGED));
        }
Example #20
0
 public void EqualitySame() {
     var remoteFile = Mock.Of<IDocument>();
     var fe = new FileEvent(null, remoteFile);
     Assert.That(fe.LocalFile, Is.Null);
     Assert.That(fe, Is.EqualTo(fe));
 }
        public void FileRemoved() {
            var fileInfo = Mock.Of<IFileInfo>(f => f.Exists == false);
            var fileEvent = new FileEvent(fileInfo) { Local = MetaDataChangeType.DELETED };

            Assert.That(this.underTest.Analyse(Mock.Of<IMetaDataStorage>(), fileEvent), Is.EqualTo(SituationType.REMOVED));
        }
 public void DoesNotHandleNonRetryEvent() {
     var underTest = new DelayRetryAndNextSyncEventHandler(Mock.Of<ISyncEventQueue>());
     var fileEvent = new FileEvent(Mock.Of<IFileInfo>()) { RetryCount = 0 };
     Assert.False(underTest.Handle(fileEvent));
 }
        public void FileMovedWithoutStorageEntry() {
            var fileInfo = Mock.Of<IFileInfo>(f => f.Exists == true);
            var fileEvent = new FileEvent(fileInfo) { Local = MetaDataChangeType.MOVED };

            Assert.That(this.underTest.Analyse(Mock.Of<IMetaDataStorage>(), fileEvent), Is.EqualTo(SituationType.MOVED));
        }
        public void FileMovedDetectionOnChangeEvent() {
            string fileName = "old";
            string oldLocalPath = Path.Combine(Path.GetTempPath(), fileName);
            string remoteId = "remoteId";
            string oldParentId = "oldParentId";
            string newParentId = "newParentId";
            var remoteFile = new Mock<IDocument>();
            remoteFile.Setup(f => f.Name).Returns(fileName);
            remoteFile.SetupPath("/new/" + fileName);
            remoteFile.Setup(f => f.Id).Returns(remoteId);
            remoteFile.SetupParent(Mock.Of<IFolder>(p => p.Id == newParentId));
            var mappedParentFolder = Mock.Of<IMappedObject>(p =>
                p.RemoteObjectId == oldParentId &&
                p.Type == MappedObjectType.Folder);
            var mappedFile = this.storage.AddLocalFile(oldLocalPath, remoteId);
            mappedFile.Setup(f => f.Name).Returns(fileName);
            mappedFile.Setup(f => f.ParentId).Returns(mappedParentFolder.RemoteObjectId);
            var fileEvent = new FileEvent(remoteFile: remoteFile.Object) { Remote = MetaDataChangeType.CHANGED };

            var underTest = new RemoteSituationDetection();

            Assert.AreEqual(SituationType.MOVED, underTest.Analyse(this.storage.Object, fileEvent));
        }
        public void FileEventForRemovedFile() {
            var session = new Mock<ISession>();
            session.SetupSessionDefaultValues();
            session.Setup(s => s.GetObject(Id, It.IsAny<IOperationContext>())).Throws(new CmisObjectNotFoundException());

            var storage = new Mock<IMetaDataStorage>();
            storage.AddLocalFile(Path, Id);

            var fileInfoMock = new Mock<IFileInfo>();
            fileInfoMock.Setup(f => f.GetExtendedAttribute(It.IsAny<string>())).Returns(Uuid.ToString());
            var fileEvent = new FileEvent(fileInfoMock.Object);

            var fetcher = new RemoteObjectFetcher(session.Object, storage.Object);
            Assert.That(fetcher.Handle(fileEvent), Is.False);
            Assert.That(fileEvent.RemoteFile, Is.Null);
        }
Example #26
0
 public void RemotePathIsEqualToFirstRemoteObjectPath() {
     string remotePath = "/path";
     var remoteFile = new Mock<IDocument>();
     remoteFile.SetupPath(remotePath, "/bla", "/blubb");
     var fileEvent = new FileEvent(remoteFile: remoteFile.Object);
     Assert.That(fileEvent.RemotePath, Is.EqualTo(remotePath));
 }
Example #27
0
 public void ToStringDoesNotCallPathsBecauseThisIsDamnExpensive() {
     var remoteFile = Mock.Of<IDocument>();
     var fe = new FileEvent(null, remoteFile);
     fe.ToString();
     Mock.Get(remoteFile).VerifyGet(f => f.Paths, Times.Never());
 }
        public void FileEventIsNotChangedIfSavedObjectIsEqualChangeToken() {
            var mappedFile = new MappedObject("name", "remoteId", MappedObjectType.File, "parentId", "changeToken");
            this.storage.AddMappedFile(mappedFile);
            var remoteObject = Mock.Of<IDocument>(o => o.Id == "remoteId" && o.ChangeToken == "changeToken");
            var fileEvent = new FileEvent(remoteFile: remoteObject);
            fileEvent.Remote = MetaDataChangeType.NONE;

            var underTest = new RemoteSituationDetection();

            Assert.That(underTest.Analyse(this.storage.Object, fileEvent), Is.EqualTo(SituationType.NOCHANGE));
            Assert.That(fileEvent.Remote, Is.EqualTo(MetaDataChangeType.NONE));
        }
        public void RetryEventsAreSavedAndReinsertedAfterNonFullSyncRequested() {
            var queue = new Mock<ISyncEventQueue>();
            var underTest = new DelayRetryAndNextSyncEventHandler(queue.Object);
            queue.Setup(q => q.IsEmpty).Returns(true);

            var syncEvent1 = new FileEvent(Mock.Of<IFileInfo>()) { RetryCount = 1 };
            var syncEvent2 = new FileEvent(Mock.Of<IFileInfo>()) { RetryCount = 1 };

            Assert.True(underTest.Handle(syncEvent1));
            Assert.True(underTest.Handle(syncEvent2));
            queue.Verify(q => q.AddEvent(syncEvent1), Times.Never());
            queue.Verify(q => q.AddEvent(syncEvent2), Times.Never());

            Assert.True(underTest.Handle(new StartNextSyncEvent(false)));

            queue.Verify(q => q.AddEvent(syncEvent1), Times.Once());
            queue.Verify(q => q.AddEvent(syncEvent2), Times.Once());
        }
Example #30
0
 public void AbstractFolderEventHasPathAttribute() {
     var localFile = new Mock<IFileInfo>();
     AbstractFolderEvent fe = new FileEvent(localFile.Object);
     Assert.That(fe.RemotePath, Is.Null);
 }