Ejemplo n.º 1
0
        public void ContentChangeIndicatesFolderMove()
        {
            // Moves /a/b to /b
            string rootFolderId = "rootId";
            string folderAName  = "a";
            string folderAId    = "aid";
            string folderBName  = "b";
            string folderBId    = "bid";

            string lastChangeToken = "changeToken";

            Mock <IFileSystemInfoFactory> fsFactory = new Mock <IFileSystemInfoFactory>();
            var folderBInfo = fsFactory.AddDirectory(Path.Combine(this.localRoot, folderAName, folderBName));

            Mock <ISession> session = MockSessionUtil.GetSessionMockReturningFolderChange(DotCMIS.Enums.ChangeType.Updated, folderBId, folderBName, this.remoteRoot + "/" + folderBName, rootFolderId, lastChangeToken);

            var storage = this.GetInitializedStorage();

            storage.ChangeLogToken = "oldtoken";
            var mappedRootObject = new MappedObject("/", rootFolderId, MappedObjectType.Folder, null, storage.ChangeLogToken);

            storage.SaveMappedObject(mappedRootObject);
            var mappedAObject = new MappedObject(folderAName, folderAId, MappedObjectType.Folder, rootFolderId, storage.ChangeLogToken);

            storage.SaveMappedObject(mappedAObject);
            var mappedBObject = new MappedObject(folderBName, folderBId, MappedObjectType.Folder, folderAId, storage.ChangeLogToken);

            storage.SaveMappedObject(mappedBObject);

            var queue = this.CreateQueue(session, storage, fsFactory.Object);

            queue.RunStartSyncEvent();

            folderBInfo.Verify(d => d.MoveTo(Path.Combine(this.localRoot, folderBName)), Times.Once());
        }
Ejemplo n.º 2
0
        public static Mock <IDirectoryInfo> AddDirectory(this Mock <IFileSystemInfoFactory> fsFactory, string path, Guid guid, bool exists = true)
        {
            var dir = fsFactory.AddDirectory(path, exists);

            dir.Setup(d => d.GetExtendedAttribute(MappedObject.ExtendedAttributeKey)).Returns(guid.ToString());
            dir.Setup(d => d.Uuid).Returns(guid);
            return(dir);
        }
Ejemplo n.º 3
0
        public static void AddDirectoryWithParents(this Mock <IFileSystemInfoFactory> fsFactory, string path)
        {
            if (path.Length > 0)
            {
                fsFactory.AddDirectory(path);
            }

            int lastSeperator = path.LastIndexOf(Path.DirectorySeparatorChar.ToString());

            if (lastSeperator > 0)
            {
                fsFactory.AddDirectoryWithParents(path.Substring(lastSeperator));
            }
        }
        public void FilterHandlesAlreadyExistingFolderEntries() {
            string path = "path";
            var storage = new Mock<IMetaDataStorage>();
            var fsFactory = new Mock<IFileSystemInfoFactory>();
            var filter = new IgnoreAlreadyHandledFsEventsFilter(storage.Object, fsFactory.Object);
            var fsEvent = new Mock<IFSEvent>();
            fsEvent.Setup(e => e.IsDirectory).Returns(true);
            fsEvent.Setup(e => e.LocalPath).Returns(path);
            fsEvent.Setup(e => e.Type).Returns(WatcherChangeTypes.Created);
            fsFactory.AddDirectory(path);
            storage.Setup(s => s.GetObjectByLocalPath(It.Is<IFileSystemInfo>(p => p.FullName.Equals(path)))).Returns(Mock.Of<IMappedObject>());

            Assert.That(filter.Handle(fsEvent.Object), Is.True);
        }
Ejemplo n.º 5
0
        public void FilterHandlesAlreadyExistingFolderEntries()
        {
            string path      = "path";
            var    storage   = new Mock <IMetaDataStorage>();
            var    fsFactory = new Mock <IFileSystemInfoFactory>();
            var    filter    = new IgnoreAlreadyHandledFsEventsFilter(storage.Object, fsFactory.Object);
            var    fsEvent   = new Mock <IFSEvent>();

            fsEvent.Setup(e => e.IsDirectory).Returns(true);
            fsEvent.Setup(e => e.LocalPath).Returns(path);
            fsEvent.Setup(e => e.Type).Returns(WatcherChangeTypes.Created);
            fsFactory.AddDirectory(path);
            storage.Setup(s => s.GetObjectByLocalPath(It.Is <IFileSystemInfo>(p => p.FullName.Equals(path)))).Returns(Mock.Of <IMappedObject>());

            Assert.That(filter.Handle(fsEvent.Object), Is.True);
        }
Ejemplo n.º 6
0
        public void ContentChangeIndicatesFolderCreation()
        {
            string rootFolderName  = "/";
            string rootFolderId    = "root";
            string folderName      = "folder";
            string parentId        = "root";
            string lastChangeToken = "changeToken";
            Mock <IFileSystemInfoFactory> fsFactory = new Mock <IFileSystemInfoFactory>();
            var dirInfo = fsFactory.AddDirectory(Path.Combine(this.localRoot, folderName));

            string          id      = "1";
            Mock <ISession> session = MockSessionUtil.GetSessionMockReturningFolderChange(DotCMIS.Enums.ChangeType.Created, id, folderName, this.remoteRoot + "/" + folderName, parentId, lastChangeToken);

            session.SetupTypeSystem();
            var storage = this.GetInitializedStorage();

            storage.ChangeLogToken = "oldtoken";
            storage.SaveMappedObject(new MappedObject(rootFolderName, rootFolderId, MappedObjectType.Folder, null, "oldtoken"));
            var queue = this.CreateQueue(session, storage, fsFactory.Object);
            var fsFolderCreatedEvent = new Mock <IFSEvent>();

            fsFolderCreatedEvent.Setup(f => f.IsDirectory).Returns(true);
            fsFolderCreatedEvent.Setup(f => f.LocalPath).Returns(Path.Combine(this.localRoot, folderName));
            fsFolderCreatedEvent.Setup(f => f.Type).Returns(WatcherChangeTypes.Created);
            dirInfo.Setup(d => d.Create()).Callback(delegate { queue.AddEvent(fsFolderCreatedEvent.Object); });

            queue.RunStartSyncEvent();

            dirInfo.Verify(d => d.Create(), Times.Once());
            var mappedObject = storage.GetObjectByRemoteId(id);

            Assert.That(mappedObject, Is.Not.Null);
            Assert.That(mappedObject.RemoteObjectId, Is.EqualTo(id), "RemoteObjectId incorrect");
            Assert.That(mappedObject.Name, Is.EqualTo(folderName), "Name incorrect");
            Assert.That(mappedObject.ParentId, Is.EqualTo(parentId), "ParentId incorrect");
            Assert.That(mappedObject.LastChangeToken, Is.EqualTo(lastChangeToken), "LastChangeToken incorrect");
            Assert.That(mappedObject.Type, Is.EqualTo(MappedObjectType.Folder), "Type incorrect");
        }
Ejemplo n.º 7
0
        public void ContentChangeIndicatesFolderMove() {
            // Moves /a/b to /b
            string rootFolderId = "rootId";
            string folderAName = "a";
            string folderAId = "aid";
            string folderBName = "b";
            string folderBId = "bid";

            string lastChangeToken = "changeToken";

            Mock<IFileSystemInfoFactory> fsFactory = new Mock<IFileSystemInfoFactory>();
            var folderBInfo = fsFactory.AddDirectory(Path.Combine(this.localRoot, folderAName, folderBName));

            Mock<ISession> session = MockSessionUtil.GetSessionMockReturningFolderChange(DotCMIS.Enums.ChangeType.Updated, folderBId, folderBName, this.remoteRoot + "/" + folderBName, rootFolderId, lastChangeToken);
            session.SetupTypeSystem();

            var storage = this.GetInitializedStorage();
            storage.ChangeLogToken = "oldtoken";
            var mappedRootObject = new MappedObject("/", rootFolderId, MappedObjectType.Folder, null, storage.ChangeLogToken);
            storage.SaveMappedObject(mappedRootObject);
            var mappedAObject = new MappedObject(folderAName, folderAId, MappedObjectType.Folder, rootFolderId, storage.ChangeLogToken);
            storage.SaveMappedObject(mappedAObject);
            var mappedBObject = new MappedObject(folderBName, folderBId, MappedObjectType.Folder, folderAId, storage.ChangeLogToken);
            storage.SaveMappedObject(mappedBObject);

            var queue = this.CreateQueue(session, storage, fsFactory.Object);

            queue.RunStartSyncEvent();

            folderBInfo.Verify(d => d.MoveTo(Path.Combine(this.localRoot, folderBName)), Times.Once());
        }
Ejemplo n.º 8
0
        public void ContentChangeIndicatesFolderCreation() {
            string rootFolderName = "/";
            string rootFolderId = "root";
            string folderName = "folder";
            string parentId = "root";
            string lastChangeToken = "changeToken";
            Mock<IFileSystemInfoFactory> fsFactory = new Mock<IFileSystemInfoFactory>();
            var dirInfo = fsFactory.AddDirectory(Path.Combine(this.localRoot, folderName));

            string id = "1";
            Mock<ISession> session = MockSessionUtil.GetSessionMockReturningFolderChange(DotCMIS.Enums.ChangeType.Created, id, folderName, this.remoteRoot + "/" + folderName, parentId, lastChangeToken);
            session.SetupTypeSystem();
            var storage = this.GetInitializedStorage();
            storage.ChangeLogToken = "oldtoken";
            storage.SaveMappedObject(new MappedObject(rootFolderName, rootFolderId, MappedObjectType.Folder, null, "oldtoken"));
            var queue = this.CreateQueue(session, storage, fsFactory.Object);
            var fsFolderCreatedEvent = new Mock<IFSEvent>();
            fsFolderCreatedEvent.Setup(f => f.IsDirectory).Returns(true);
            fsFolderCreatedEvent.Setup(f => f.LocalPath).Returns(Path.Combine(this.localRoot, folderName));
            fsFolderCreatedEvent.Setup(f => f.Type).Returns(WatcherChangeTypes.Created);
            dirInfo.Setup(d => d.Create()).Callback(delegate { queue.AddEvent(fsFolderCreatedEvent.Object); });

            queue.RunStartSyncEvent();

            dirInfo.Verify(d => d.Create(), Times.Once());
            var mappedObject = storage.GetObjectByRemoteId(id);
            Assert.That(mappedObject, Is.Not.Null);
            Assert.That(mappedObject.RemoteObjectId, Is.EqualTo(id), "RemoteObjectId incorrect");
            Assert.That(mappedObject.Name, Is.EqualTo(folderName), "Name incorrect");
            Assert.That(mappedObject.ParentId, Is.EqualTo(parentId), "ParentId incorrect");
            Assert.That(mappedObject.LastChangeToken, Is.EqualTo(lastChangeToken), "LastChangeToken incorrect");
            Assert.That(mappedObject.Type, Is.EqualTo(MappedObjectType.Folder), "Type incorrect");
        }