Beispiel #1
0
        public void ContentChangeIndicatesFolderRenameOfExistingFolder()
        {
            var    storage         = this.GetInitializedStorage();
            string name            = "a";
            string newName         = "b";
            string parentId        = "parentId";
            string path            = Path.Combine(this.localRoot, name);
            string newPath         = Path.Combine(this.localRoot, newName);
            string id              = "1";
            string lastChangeToken = "changeToken";
            Guid   guid            = Guid.NewGuid();
            Mock <IFileSystemInfoFactory> fsFactory = new Mock <IFileSystemInfoFactory>();
            var dirInfo = new Mock <IDirectoryInfo>();

            dirInfo.Setup(d => d.Exists).Returns(true);
            dirInfo.Setup(d => d.FullName).Returns(path);
            dirInfo.Setup(d => d.Parent).Returns(Mock.Of <IDirectoryInfo>(r => r.FullName == this.localRoot));
            fsFactory.AddIDirectoryInfo(dirInfo.Object);
            var mappedRootObject = new MappedObject("/", parentId, MappedObjectType.Folder, null, storage.ChangeLogToken);

            storage.SaveMappedObject(mappedRootObject);
            var mappedObject = new MappedObject(name, id, MappedObjectType.Folder, parentId, null)
            {
                Guid = guid
            };

            storage.SaveMappedObject(mappedObject);
            storage.ChangeLogToken = "oldChangeToken";
            Console.WriteLine(storage.ToFindString());

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

            session.SetupTypeSystem();

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

            dirInfo.Setup(d => d.MoveTo(It.IsAny <string>()))
            .Callback(() => {
                queue.AddEvent(Mock.Of <IFSMovedEvent>(fs => fs.IsDirectory == true && fs.OldPath == path && fs.LocalPath == newPath && fs.Type == WatcherChangeTypes.Renamed));
                var newDirInfo = new Mock <IDirectoryInfo>();
                newDirInfo.Setup(d => d.Exists).Returns(true);
                newDirInfo.Setup(d => d.FullName).Returns(newPath);
                newDirInfo.Setup(d => d.Uuid).Returns(guid);
                newDirInfo.Setup(d => d.Parent).Returns(Mock.Of <IDirectoryInfo>(r => r.FullName == this.localRoot));
                fsFactory.AddIDirectoryInfo(newDirInfo.Object);
            });

            queue.RunStartSyncEvent();
            dirInfo.Verify(d => d.MoveTo(It.Is <string>(p => p.Equals(newPath))), Times.Once());
            Assert.That(storage.GetObjectByRemoteId(id), Is.Not.Null);
            Assert.That(storage.GetObjectByRemoteId(id).Name, Is.EqualTo(newName));
            Assert.That(storage.GetObjectByLocalPath(Mock.Of <IDirectoryInfo>(d => d.FullName == path)), Is.Null);
            Assert.That(storage.GetObjectByLocalPath(Mock.Of <IDirectoryInfo>(d => d.FullName == newPath)), Is.Not.Null);
        }
Beispiel #2
0
        public void ContentChangeIndicatesFolderDeletionOfExistingFolder()
        {
            var    storage = this.GetInitializedStorage();
            var    name    = "a";
            string path    = Path.Combine(this.localRoot, name);
            string id      = "1";
            Mock <IFileSystemInfoFactory> fsFactory = new Mock <IFileSystemInfoFactory>();
            var dirInfo = new Mock <IDirectoryInfo>();

            dirInfo.Setup(d => d.Exists).Returns(true);
            dirInfo.Setup(d => d.FullName).Returns(path);
            fsFactory.AddIDirectoryInfo(dirInfo.Object);
            var mappedObject = new MappedObject(name, id, MappedObjectType.Folder, null, null);

            storage.SaveMappedObject(mappedObject);
            storage.ChangeLogToken = "oldtoken";

            Mock <ISession> session = MockSessionUtil.GetSessionMockReturningFolderChange(DotCMIS.Enums.ChangeType.Deleted, id);

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

            queue.RunStartSyncEvent();
            dirInfo.Verify(d => d.Delete(false), Times.Once());
            Assert.That(storage.GetObjectByRemoteId(id), Is.Null);
        }
Beispiel #3
0
        public static Mock <IDirectoryInfo> AddDirectory(this Mock <IFileSystemInfoFactory> fsFactory, string path, bool exists = true)
        {
            if (path.EndsWith("/"))
            {
                throw new ArgumentException("FileName gives last tuple of path not ending on / so path should not end with /");
            }

            Mock <IDirectoryInfo> dir = new Mock <IDirectoryInfo>();

            dir.Setup(d => d.FullName).Returns(path);
            dir.Setup(d => d.Name).Returns(Path.GetFileName(path));
            dir.Setup(d => d.Exists).Returns(exists);
            fsFactory.AddIDirectoryInfo(dir.Object);
            return(dir);
        }
Beispiel #4
0
        public void FilterHandlesAlreadyMovedFolderEntries()
        {
            string path      = "path";
            string oldPath   = "oldpath";
            Guid   guid      = Guid.NewGuid();
            var    storage   = new Mock <IMetaDataStorage>();
            var    fsFactory = new Mock <IFileSystemInfoFactory>(MockBehavior.Strict);
            var    moveEvent = Mock.Of <IFSMovedEvent>(e => e.LocalPath == path && e.OldPath == oldPath && e.Type == WatcherChangeTypes.Renamed && e.IsDirectory == true);
            var    dirInfo   = Mock.Of <IDirectoryInfo>(d => d.FullName == path && d.Exists == true && d.Uuid == guid);

            fsFactory.AddIDirectoryInfo(dirInfo);
            storage.AddMappedFolder(new MappedObject("path", "remoteId", MappedObjectType.Folder, null, null)
            {
                Guid = guid
            }, path);
            var filter = new IgnoreAlreadyHandledFsEventsFilter(storage.Object, fsFactory.Object);

            Assert.That(filter.Handle(moveEvent), Is.True);
        }
        public void ContentChangeIndicatesFolderRenameOfExistingFolder() {
            var storage = this.GetInitializedStorage();
            string name = "a";
            string newName = "b";
            string parentId = "parentId";
            string path = Path.Combine(this.localRoot, name);
            string newPath = Path.Combine(this.localRoot, newName);
            string id = "1";
            string lastChangeToken = "changeToken";
            Guid guid = Guid.NewGuid();
            Mock<IFileSystemInfoFactory> fsFactory = new Mock<IFileSystemInfoFactory>();
            var dirInfo = new Mock<IDirectoryInfo>();
            dirInfo.Setup(d => d.Exists).Returns(true);
            dirInfo.Setup(d => d.FullName).Returns(path);
            dirInfo.Setup(d => d.Parent).Returns(Mock.Of<IDirectoryInfo>(r => r.FullName == this.localRoot));
            fsFactory.AddIDirectoryInfo(dirInfo.Object);
            var mappedRootObject = new MappedObject("/", parentId, MappedObjectType.Folder, null, storage.ChangeLogToken);
            storage.SaveMappedObject(mappedRootObject);
            var mappedObject = new MappedObject(name, id, MappedObjectType.Folder, parentId, null) { Guid = guid };
            storage.SaveMappedObject(mappedObject);
            storage.ChangeLogToken = "oldChangeToken";
            Console.WriteLine(storage.ToFindString());

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

            var queue = this.CreateQueue(session, storage, fsFactory.Object);
            dirInfo.Setup(d => d.MoveTo(It.IsAny<string>()))
                .Callback(() => {
                    queue.AddEvent(Mock.Of<IFSMovedEvent>(fs => fs.IsDirectory == true && fs.OldPath == path && fs.LocalPath == newPath && fs.Type == WatcherChangeTypes.Renamed));
                    var newDirInfo = new Mock<IDirectoryInfo>();
                    newDirInfo.Setup(d => d.Exists).Returns(true);
                    newDirInfo.Setup(d => d.FullName).Returns(newPath);
                    newDirInfo.Setup(d => d.Uuid).Returns(guid);
                    newDirInfo.Setup(d => d.Parent).Returns(Mock.Of<IDirectoryInfo>(r => r.FullName == this.localRoot));
                    fsFactory.AddIDirectoryInfo(newDirInfo.Object);
                });

            queue.RunStartSyncEvent();
            dirInfo.Verify(d => d.MoveTo(It.Is<string>(p => p.Equals(newPath))), Times.Once());
            Assert.That(storage.GetObjectByRemoteId(id), Is.Not.Null);
            Assert.That(storage.GetObjectByRemoteId(id).Name, Is.EqualTo(newName));
            Assert.That(storage.GetObjectByLocalPath(Mock.Of<IDirectoryInfo>(d => d.FullName == path)), Is.Null);
            Assert.That(storage.GetObjectByLocalPath(Mock.Of<IDirectoryInfo>(d => d.FullName == newPath)), Is.Not.Null);
        }
        public void ContentChangeIndicatesFolderDeletionOfExistingFolder() {
            var storage = this.GetInitializedStorage();
            var name = "a";
            string path = Path.Combine(this.localRoot, name);
            string id = "1";
            Mock<IFileSystemInfoFactory> fsFactory = new Mock<IFileSystemInfoFactory>();
            var dirInfo = new Mock<IDirectoryInfo>();
            dirInfo.Setup(d => d.Exists).Returns(true);
            dirInfo.Setup(d => d.FullName).Returns(path);
            fsFactory.AddIDirectoryInfo(dirInfo.Object);
            var mappedObject = new MappedObject(name, id, MappedObjectType.Folder, null, null);
            storage.SaveMappedObject(mappedObject);
            storage.ChangeLogToken = "oldtoken";

            Mock<ISession> session = MockSessionUtil.GetSessionMockReturningFolderChange(DotCMIS.Enums.ChangeType.Deleted, id);
            session.SetupTypeSystem();
            var queue = this.CreateQueue(session, storage, fsFactory.Object);
            queue.RunStartSyncEvent();
            dirInfo.Verify(d => d.Delete(false), Times.Once());
            Assert.That(storage.GetObjectByRemoteId(id), Is.Null);
        }
        public void FilterHandlesAlreadyMovedFolderEntries() {
            string path = "path";
            string oldPath = "oldpath";
            Guid guid = Guid.NewGuid();
            var storage = new Mock<IMetaDataStorage>();
            var fsFactory = new Mock<IFileSystemInfoFactory>(MockBehavior.Strict);
            var moveEvent = Mock.Of<IFSMovedEvent>(e => e.LocalPath == path && e.OldPath == oldPath && e.Type == WatcherChangeTypes.Renamed && e.IsDirectory == true);
            var dirInfo = Mock.Of<IDirectoryInfo>(d => d.FullName == path && d.Exists == true && d.Uuid == guid);
            fsFactory.AddIDirectoryInfo(dirInfo);
            storage.AddMappedFolder(new MappedObject("path", "remoteId", MappedObjectType.Folder, null, null) { Guid = guid }, path);
            var filter = new IgnoreAlreadyHandledFsEventsFilter(storage.Object, fsFactory.Object);

            Assert.That(filter.Handle(moveEvent), Is.True);
        }