Ejemplo n.º 1
0
        public static Mock <IMappedObject> AddLocalFolder(this Mock <IMetaDataStorage> db, string path, string id)
        {
            var folder = Mock.Of <IDirectoryInfo>(d =>
                                                  d.FullName == path &&
                                                  d.Name == Path.GetDirectoryName(path));

            return(db.AddLocalFolder(folder, id));
        }
        public void RemoteFolderSecurity()
        {
            var storage = new Mock <IMetaDataStorage>();

            storage.AddLocalFolder("path", Id);
            FolderEvent folderEvent = null;
            var         queue       = new Mock <ISyncEventQueue>();

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

            var transformer        = new ContentChangeEventTransformer(queue.Object, storage.Object);
            var contentChangeEvent = this.PrepareFolderEvent(DotCMIS.Enums.ChangeType.Security);

            Assert.That(transformer.Handle(contentChangeEvent), Is.True);
            queue.Verify(q => q.AddEvent(It.IsAny <FolderEvent>()), Times.Once());
            Assert.That(folderEvent.Remote, Is.EqualTo(MetaDataChangeType.CHANGED));
        }
        public void FolderEventForRemovedFolder()
        {
            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.AddLocalFolder(Path, Id);

            var dirMock = new Mock <IDirectoryInfo>();

            dirMock.Setup(d => d.GetExtendedAttribute(MappedObject.ExtendedAttributeKey)).Returns(Uuid.ToString());

            var folderEvent = new FolderEvent(dirMock.Object);

            var fetcher = new RemoteObjectFetcher(session.Object, storage.Object);

            Assert.That(fetcher.Handle(folderEvent), Is.False);
            Assert.That(folderEvent.RemoteFolder, Is.Null);
        }
        public void OperationContextDoesNotUsesTheSessionCache()
        {
            var session = new Mock <ISession>();

            session.SetupSessionDefaultValues();
            IFolder remote = MockOfIFolderUtil.CreateRemoteFolderMock(Id, "name", "/name").Object;

            session.Setup(s => s.GetObject(Id, It.IsAny <IOperationContext>())).Returns(remote);

            var storage = new Mock <IMetaDataStorage>();

            storage.AddLocalFolder(Path, Id, Uuid);

            var dirMock = new Mock <IDirectoryInfo>();

            dirMock.Setup(d => d.Exists).Returns(true);
            dirMock.Setup(d => d.GetExtendedAttribute(MappedObject.ExtendedAttributeKey)).Returns(Uuid.ToString());
            var folderEvent = new FolderEvent(dirMock.Object);
            var fetcher     = new RemoteObjectFetcher(session.Object, storage.Object);

            Assert.That(fetcher.Handle(folderEvent), Is.False);
            session.VerifyThatCachingIsDisabled();
        }
        public void CrawlRequestedEventWithNewRemoteFolder()
        {
            var session = new Mock <ISession>();

            session.SetupSessionDefaultValues();
            IFolder remote = MockOfIFolderUtil.CreateRemoteFolderMock(Id, "name", "/name").Object;

            session.Setup(s => s.GetObject(Id, It.IsAny <IOperationContext>())).Returns(remote);

            var storage = new Mock <IMetaDataStorage>();

            storage.AddLocalFolder(Path, Id, Uuid);

            var dirMock = new Mock <IDirectoryInfo>();

            dirMock.Setup(d => d.Exists).Returns(true);
            dirMock.Setup(d => d.Uuid).Returns(Uuid);
            var crawlEvent = new CrawlRequestEvent(localFolder: dirMock.Object, remoteFolder: null);

            var fetcher = new RemoteObjectFetcher(session.Object, storage.Object);

            Assert.That(fetcher.Handle(crawlEvent), Is.False);
            Assert.That(crawlEvent.RemoteFolder, Is.EqualTo(remote));
        }
        public void FolderEventWithoutObjectIdAndExtendedAttributeExceptionOnUuidRequest()
        {
            var session = new Mock <ISession>();

            session.SetupSessionDefaultValues();
            IFolder remote = MockOfIFolderUtil.CreateRemoteFolderMock(Id, "name", "/name").Object;

            session.Setup(s => s.GetObject(Id, It.IsAny <IOperationContext>())).Returns(remote);

            var storage = new Mock <IMetaDataStorage>();

            storage.AddLocalFolder(Path, Id, Uuid);

            var dirMock = new Mock <IDirectoryInfo>();

            dirMock.Setup(d => d.Exists).Returns(true);
            dirMock.Setup(d => d.Uuid).Throws <ExtendedAttributeException>();

            var folderEvent = new FolderEvent(dirMock.Object);
            var fetcher     = new RemoteObjectFetcher(session.Object, storage.Object);

            Assert.That(fetcher.Handle(folderEvent), Is.False);
            Assert.That(folderEvent.RemoteFolder, Is.Null);
        }
        public void OperationContextDoesNotUsesTheSessionCache() {
            var session = new Mock<ISession>();
            session.SetupSessionDefaultValues();
            IFolder remote = MockOfIFolderUtil.CreateRemoteFolderMock(Id, "name", "/name").Object;
            session.Setup(s => s.GetObject(Id, It.IsAny<IOperationContext>())).Returns(remote);

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

            var dirMock = new Mock<IDirectoryInfo>();
            dirMock.Setup(d => d.Exists).Returns(true);
            dirMock.Setup(d => d.GetExtendedAttribute(MappedObject.ExtendedAttributeKey)).Returns(Uuid.ToString());
            var folderEvent = new FolderEvent(dirMock.Object);
            var fetcher = new RemoteObjectFetcher(session.Object, storage.Object);

            Assert.That(fetcher.Handle(folderEvent), Is.False);
            session.VerifyThatCachingIsDisabled();
        }
        public void CrawlRequestedEventWithNewRemoteFolder() {
            var session = new Mock<ISession>();
            session.SetupSessionDefaultValues();
            IFolder remote = MockOfIFolderUtil.CreateRemoteFolderMock(Id, "name", "/name").Object;
            session.Setup(s => s.GetObject(Id, It.IsAny<IOperationContext>())).Returns(remote);

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

            var dirMock = new Mock<IDirectoryInfo>();
            dirMock.Setup(d => d.Exists).Returns(true);
            dirMock.Setup(d => d.Uuid).Returns(Uuid);
            var crawlEvent = new CrawlRequestEvent(localFolder: dirMock.Object, remoteFolder: null);

            var fetcher = new RemoteObjectFetcher(session.Object, storage.Object);
            Assert.That(fetcher.Handle(crawlEvent), Is.False);
            Assert.That(crawlEvent.RemoteFolder, Is.EqualTo(remote));
        }
        public void FolderEventForRemovedFolder() {
            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.AddLocalFolder(Path, Id);

            var dirMock = new Mock<IDirectoryInfo>();
            dirMock.Setup(d => d.GetExtendedAttribute(MappedObject.ExtendedAttributeKey)).Returns(Uuid.ToString());

            var folderEvent = new FolderEvent(dirMock.Object);

            var fetcher = new RemoteObjectFetcher(session.Object, storage.Object);
            Assert.That(fetcher.Handle(folderEvent), Is.False);
            Assert.That(folderEvent.RemoteFolder, Is.Null);
        }
        public void FolderEventWithoutObjectIdAndExtendedAttributeExceptionOnUuidRequest() {
            var session = new Mock<ISession>();
            session.SetupSessionDefaultValues();
            IFolder remote = MockOfIFolderUtil.CreateRemoteFolderMock(Id, "name", "/name").Object;
            session.Setup(s => s.GetObject(Id, It.IsAny<IOperationContext>())).Returns(remote);

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

            var dirMock = new Mock<IDirectoryInfo>();
            dirMock.Setup(d => d.Exists).Returns(true);
            dirMock.Setup(d => d.Uuid).Throws<ExtendedAttributeException>();

            var folderEvent = new FolderEvent(dirMock.Object);
            var fetcher = new RemoteObjectFetcher(session.Object, storage.Object);

            Assert.That(fetcher.Handle(folderEvent), Is.False);
            Assert.That(folderEvent.RemoteFolder, Is.Null);
        }
        public void RemoteFolderSecurity() {
            var storage = new Mock<IMetaDataStorage>();
            storage.AddLocalFolder("path", Id);
            FolderEvent folderEvent = null;
            var queue = new Mock<ISyncEventQueue>();
            queue.Setup(h => h.AddEvent(It.IsAny<FolderEvent>()))
                    .Callback<ISyncEvent>(e => folderEvent = e as FolderEvent);

            var transformer = new ContentChangeEventTransformer(queue.Object, storage.Object);
            var contentChangeEvent = this.PrepareFolderEvent(DotCMIS.Enums.ChangeType.Security);

            Assert.That(transformer.Handle(contentChangeEvent), Is.True);
            queue.Verify(q => q.AddEvent(It.IsAny<FolderEvent>()), Times.Once());
            Assert.That(folderEvent.Remote, Is.EqualTo(MetaDataChangeType.CHANGED));
        }