public void FileDeletedEventWithoutObjectId()
        {
            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.FullName).Returns(Path);
            var fileEvent = new FileEvent(fileInfoMock.Object)
            {
                Local = MetaDataChangeType.DELETED
            };
            var fetcher = new RemoteObjectFetcher(session.Object, storage.Object);

            Assert.That(fetcher.Handle(fileEvent), Is.False);
            Assert.That(fileEvent.RemoteFile, Is.Not.Null);
        }
Exemplo n.º 2
0
        public static Mock <IMappedObject> AddLocalFile(this Mock <IMetaDataStorage> db, string path, string id)
        {
            var file = Mock.Of <IFileInfo>(f =>
                                           f.Name == Path.GetFileName(path) &&
                                           f.FullName == path &&
                                           f.Exists == true);

            return(db.AddLocalFile(file, id));
        }
Exemplo n.º 3
0
        public void RemoteDeletionChangeTest()
        {
            Mock <IMetaDataStorage> storage = MockMetaDataStorageUtil.GetMetaStorageMockWithToken();
            var file = Mock.Of <IFileInfo>(f => f.FullName == "path");

            storage.AddLocalFile(file, DefaultId);

            Mock <ISession>   session  = MockSessionUtil.GetSessionMockReturningDocumentChange(DotCMIS.Enums.ChangeType.Deleted, DefaultId, null);
            ObservableHandler observer = this.RunQueue(session, storage);

            observer.AssertGotSingleFileEvent(MetaDataChangeType.DELETED, ContentChangeType.NONE);
        }
Exemplo n.º 4
0
        public void RemoteSecurityChangeOfExistingFile()
        {
            Mock <IMetaDataStorage> storage = MockMetaDataStorageUtil.GetMetaStorageMockWithToken();
            var path = Mock.Of <IFileInfo>(f => f.FullName == "path");

            storage.AddLocalFile(path, DefaultId);

            Mock <ISession>   session  = MockSessionUtil.GetSessionMockReturningDocumentChange(DotCMIS.Enums.ChangeType.Security, DefaultId);
            ObservableHandler observer = this.RunQueue(session, storage);

            storage.Verify(s => s.GetObjectByRemoteId(DefaultId), Times.Once());

            observer.AssertGotSingleFileEvent(MetaDataChangeType.CHANGED, ContentChangeType.NONE);
        }
        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());
        }
Exemplo n.º 6
0
        public void FilterDeletesFsEventsIfLocalFileSystemContainsTheElementOfTheStorage()
        {
            string path      = "path";
            Guid   guid      = Guid.NewGuid();
            var    storage   = new Mock <IMetaDataStorage>();
            var    fsFactory = new Mock <IFileSystemInfoFactory>();

            fsFactory.AddFile(path, guid, true);
            storage.AddLocalFile(path, "id", guid);
            var filter  = new IgnoreAlreadyHandledFsEventsFilter(storage.Object, fsFactory.Object);
            var fsEvent = Mock.Of <IFSEvent>(
                e =>
                e.LocalPath == path &&
                e.Type == WatcherChangeTypes.Deleted &&
                e.IsDirectory == false);

            Assert.That(filter.Handle(fsEvent), Is.True);
        }
        public void RemoteDeletionChangeTest()
        {
            var storage = new Mock <IMetaDataStorage>();

            storage.AddLocalFile("path", Id);
            FileEvent fileEvent = null;
            var       queue     = new Mock <ISyncEventQueue>();

            queue.Setup(h => h.AddEvent(It.IsAny <FileEvent>()))
            .Callback <ISyncEvent>(e => fileEvent = e as FileEvent);

            var transformer        = new ContentChangeEventTransformer(queue.Object, storage.Object);
            var contentChangeEvent = this.PrepareEvent(DotCMIS.Enums.ChangeType.Deleted, false);

            Assert.That(transformer.Handle(contentChangeEvent), Is.True);
            queue.Verify(q => q.AddEvent(It.IsAny <FileEvent>()), Times.Once());
            Assert.That(fileEvent.Remote, Is.EqualTo(MetaDataChangeType.DELETED));
            Assert.That(fileEvent.RemoteContent, Is.EqualTo(ContentChangeType.NONE));
        }
        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 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);
        }
        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);
        }
        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);
        }
        public void FilterDeletesFsEventsIfLocalFileSystemContainsTheElementOfTheStorage() {
            string path = "path";
            Guid guid = Guid.NewGuid();
            var storage = new Mock<IMetaDataStorage>();
            var fsFactory = new Mock<IFileSystemInfoFactory>();
            fsFactory.AddFile(path, guid, true);
            storage.AddLocalFile(path, "id", guid);
            var filter = new IgnoreAlreadyHandledFsEventsFilter(storage.Object, fsFactory.Object);
            var fsEvent = Mock.Of<IFSEvent>(
                e =>
                e.LocalPath == path &&
                e.Type == WatcherChangeTypes.Deleted &&
                e.IsDirectory== false);

            Assert.That(filter.Handle(fsEvent), Is.True);
        }
        public void RemoteDeletionChangeTest() {
            var storage = new Mock<IMetaDataStorage>();
            storage.AddLocalFile("path", Id);
            FileEvent fileEvent = null;
            var queue = new Mock<ISyncEventQueue>();
            queue.Setup(h => h.AddEvent(It.IsAny<FileEvent>()))
                    .Callback<ISyncEvent>(e => fileEvent = e as FileEvent);

            var transformer = new ContentChangeEventTransformer(queue.Object, storage.Object);
            var contentChangeEvent = this.PrepareEvent(DotCMIS.Enums.ChangeType.Deleted, false);

            Assert.That(transformer.Handle(contentChangeEvent), Is.True);
            queue.Verify(q => q.AddEvent(It.IsAny<FileEvent>()), Times.Once());
            Assert.That(fileEvent.Remote, Is.EqualTo(MetaDataChangeType.DELETED));
            Assert.That(fileEvent.RemoteContent, Is.EqualTo(ContentChangeType.NONE));
        }