Example #1
0
        public void PermissionDeniedOnModificationDateSavesTheLocalDate()
        {
            Guid uuid             = Guid.NewGuid();
            var  modificationDate = DateTime.UtcNow;

            var localFolder = new Mock <IDirectoryInfo>();

            localFolder.SetupProperty(f => f.LastWriteTimeUtc, modificationDate.AddMinutes(1));
            localFolder.Setup(f => f.FullName).Returns("path");
            localFolder.SetupGuid(uuid);
            localFolder.Setup(f => f.Exists).Returns(true);

            var mappedObject = new MappedObject(
                "name",
                "remoteId",
                MappedObjectType.Folder,
                "parentId",
                "changeToken")
            {
                Guid = uuid,
                LastRemoteWriteTimeUtc = modificationDate.AddMinutes(1),
                LastLocalWriteTimeUtc  = modificationDate,
            };

            this.storage.AddMappedFolder(mappedObject, "path");
            var remoteFolder = MockOfIFolderUtil.CreateRemoteFolderMock("remoteId", "name", "path", "parentId");

            remoteFolder.Setup(r => r.UpdateProperties(It.IsAny <IDictionary <string, object> >(), true)).Throws(new CmisPermissionDeniedException());

            this.underTest.Solve(localFolder.Object, remoteFolder.Object);

            this.storage.VerifySavedMappedObject(MappedObjectType.Folder, "remoteId", "name", "parentId", "changeToken", true, localFolder.Object.LastWriteTimeUtc, remoteFolder.Object.LastModificationDate);
            remoteFolder.Verify(r => r.UpdateProperties(It.IsAny <IDictionary <string, object> >(), true));
        }
Example #2
0
        public void RunFSEventFolderDeleted()
        {
            var storage = this.GetInitializedStorage();
            var path    = new Mock <IFileInfo>();
            var name    = "a";

            path.Setup(p => p.FullName).Returns(Path.Combine(this.localRoot, name));
            string id = "id";

            var mappedObject = new MappedObject(name, id, MappedObjectType.Folder, null, null);

            storage.SaveMappedObject(mappedObject);

            var session = new Mock <ISession>();

            session.SetupTypeSystem();
            session.SetupSessionDefaultValues();
            session.SetupChangeLogToken("default");
            IFolder remote = MockOfIFolderUtil.CreateRemoteFolderMock(id, name, (string)null).Object;

            session.Setup(s => s.GetObject(id, It.IsAny <IOperationContext>())).Returns(remote);
            var myEvent = new FSEvent(WatcherChangeTypes.Deleted, path.Object.FullName, true);
            var queue   = this.CreateQueue(session, storage);

            queue.AddEvent(myEvent);
            queue.Run();

            Mock.Get(remote).Verify(d => d.DeleteTree(false, UnfileObject.DeleteSinglefiled, true), Times.Once());
            Assert.That(storage.GetObjectByRemoteId(id), Is.Null);
        }
Example #3
0
        public void LocalAndRemoteFolderAreChanged([Values(true, false)] bool childrenAreIgnored)
        {
            this.InitMocks();
            string   folderName             = "folderName";
            DateTime lastLocalModification  = DateTime.UtcNow.AddDays(1);
            DateTime lastRemoteModification = DateTime.UtcNow.AddHours(1);
            var      localFolder            = Mock.Of <IDirectoryInfo>(f => f.LastWriteTimeUtc == lastLocalModification);
            var      remoteFolder           = MockOfIFolderUtil.CreateRemoteFolderMock(this.remoteId, folderName, "path", this.parentId, this.newChangeToken, childrenAreIgnored);

            remoteFolder.Setup(f => f.LastModificationDate).Returns(lastRemoteModification);
            var mappedFolder = Mock.Of <IMappedObject>(
                o =>
                o.Name == folderName &&
                o.RemoteObjectId == this.remoteId &&
                o.LastChangeToken == this.oldChangeToken &&
                o.LastLocalWriteTimeUtc == DateTime.UtcNow &&
                o.LastRemoteWriteTimeUtc == DateTime.UtcNow &&
                o.ParentId == this.parentId &&
                o.Type == MappedObjectType.Folder &&
                o.Guid == Guid.NewGuid() &&
                o.LastContentSize == -1);

            this.storage.AddMappedFolder(mappedFolder);

            this.underTest.Solve(localFolder, remoteFolder.Object, ContentChangeType.NONE, ContentChangeType.NONE);

            this.storage.VerifySavedMappedObject(MappedObjectType.Folder, this.remoteId, folderName, this.parentId, this.newChangeToken, lastLocalModification: lastLocalModification, lastRemoteModification: lastRemoteModification, ignored: childrenAreIgnored);
        }
Example #4
0
        public void PermissionDeniedLeadsToNoOperation()
        {
            var remoteFolder       = MockOfIFolderUtil.CreateRemoteFolderMock("folderId", "folder", "/folder", this.rootId);
            var remoteTargetFolder = MockOfIFolderUtil.CreateRemoteFolderMock("targetId", "target", "/target", this.rootId);

            this.session.AddRemoteObjects(remoteFolder.Object, remoteTargetFolder.Object);
            var localTargetFolder = MockOfIFileSystemInfoFactoryUtil.CreateLocalFolder(Path.Combine(Path.GetTempPath(), "target"));
            var localFolder       = MockOfIFileSystemInfoFactoryUtil.CreateLocalFolder(Path.Combine(Path.GetTempPath(), "target", "folder"));

            localFolder.Setup(f => f.Parent).Returns(localTargetFolder.Object);
            var mappedFolder = new MappedObject("folder", "folderId", MappedObjectType.Folder, this.rootId, "changetoken")
            {
                Guid = Guid.NewGuid()
            };
            var mappedTargetFolder = new MappedObject("target", "targetId", MappedObjectType.Folder, this.rootId, "changetoken")
            {
                Guid = Guid.NewGuid()
            };

            this.storage.Setup(s => s.GetObjectByLocalPath(It.Is <IDirectoryInfo>(d => d.Equals(localTargetFolder.Object)))).Returns(mappedTargetFolder);
            this.storage.Setup(s => s.GetObjectByRemoteId("folderId")).Returns(mappedFolder);
            remoteFolder.Setup(f => f.Move(this.remoteRootFolder.Object, remoteTargetFolder.Object)).Throws(new CmisPermissionDeniedException());

            this.underTest.Solve(localFolder.Object, remoteFolder.Object);

            remoteFolder.Verify(f => f.Move(this.remoteRootFolder.Object, remoteTargetFolder.Object), Times.Once());
            this.storage.VerifyThatNoObjectIsManipulated();
        }
        public void LocalFolderMovedAndRenamed([Values(true, false)] bool childrenAreIgnored)
        {
            this.SetUpMocks();
            string oldDirName = "oldName";
            string newDirName = "newName";
            var    dir        = Mock.Of <IDirectoryInfo>(
                d =>
                d.FullName == Path.Combine(Path.GetTempPath(), this.newParentsName, newDirName) &&
                d.Name == newDirName &&
                d.Parent.Uuid == this.parentUuid);
            var folder = MockOfIFolderUtil.CreateRemoteFolderMock(this.remoteObjectId, oldDirName, "path", this.oldParentsId, ignored: childrenAreIgnored);

            folder.Setup(d => d.Move(It.IsAny <IObjectId>(), It.IsAny <IObjectId>())).Returns(folder.Object);
            var obj = new MappedObject(oldDirName, this.remoteObjectId, MappedObjectType.Folder, this.oldParentsId, this.changeToken)
            {
                Guid = Guid.NewGuid()
            };

            this.storage.AddMappedFolder(obj);
            this.underTest.Solve(dir, folder.Object, ContentChangeType.NONE, ContentChangeType.NONE);
            this.storage.VerifySavedMappedObject(MappedObjectType.Folder, this.remoteObjectId, newDirName, this.newParentsId, this.changeToken, Times.Exactly(2), ignored: childrenAreIgnored);
            folder.Verify(d => d.Move(It.Is <IObjectId>(o => o.Id == this.oldParentsId), It.Is <IObjectId>(o => o.Id == this.newParentsId)));
            this.renameSolver.Verify(s => s.Solve(dir, folder.Object, ContentChangeType.NONE, ContentChangeType.NONE), Times.Once());
            this.changeSolver.Verify(s => s.Solve(It.IsAny <IFileSystemInfo>(), It.IsAny <IObjectId>(), It.IsAny <ContentChangeType>(), It.IsAny <ContentChangeType>()), Times.Never);
        }
Example #6
0
 public void CreateMockObjects()
 {
     this.storageEngine = new DBreezeEngine(new DBreezeConfiguration {
         Storage = DBreezeConfiguration.eStorage.MEMORY
     });
     this.localRootPath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
     this.matcher       = new PathMatcher(this.localRootPath, this.remoteRootPath);
     this.queue         = new Mock <ISyncEventQueue>();
     this.remoteFolder  = MockOfIFolderUtil.CreateRemoteFolderMock(this.remoteRootId, this.remoteRootPath, this.remoteRootPath);
     this.remoteFolder.SetupDescendants();
     this.localFolder = new Mock <IDirectoryInfo>();
     this.localFolder.Setup(f => f.FullName).Returns(this.localRootPath);
     this.localFolder.Setup(f => f.Exists).Returns(true);
     this.localFolder.Setup(f => f.IsExtendedAttributeAvailable()).Returns(true);
     this.localFolder.SetupGuid(this.rootGuid);
     this.localFolder.Setup(f => f.LastWriteTimeUtc).Returns(this.lastLocalWriteTime);
     this.fsFactory = new Mock <IFileSystemInfoFactory>();
     this.fsFactory.AddIDirectoryInfo(this.localFolder.Object);
     this.mappedRootObject = new MappedObject(
         this.remoteRootPath,
         this.remoteRootId,
         MappedObjectType.Folder,
         null,
         "changeToken")
     {
         Guid = this.rootGuid,
         LastLocalWriteTimeUtc = this.lastLocalWriteTime
     };
     this.storage = new MetaDataStorage(this.storageEngine, this.matcher);
     this.storage.SaveMappedObject(this.mappedRootObject);
     this.filter   = MockOfIFilterAggregatorUtil.CreateFilterAggregator().Object;
     this.listener = new Mock <IActivityListener>();
 }
Example #7
0
        public void OneRemoteFolderRenamed()
        {
            DateTime modification   = DateTime.UtcNow;
            string   oldFolderName  = "folderName";
            string   newFolderName  = "newfolderName";
            string   folderId       = "folderId";
            var      localGuid      = Guid.NewGuid();
            var      oldLocalFolder = this.fsFactory.AddDirectory(Path.Combine(this.localRootPath, oldFolderName));

            oldLocalFolder.Setup(f => f.LastWriteTimeUtc).Returns(modification);
            oldLocalFolder.SetupGuid(localGuid);
            var storedFolder = new MappedObject(oldFolderName, folderId, MappedObjectType.Folder, this.remoteRootId, "changeToken")
            {
                Guid = localGuid,
                LastLocalWriteTimeUtc = modification
            };

            this.localFolder.SetupDirectories(oldLocalFolder.Object);
            this.storage.SaveMappedObject(storedFolder);
            var renamedRemoteFolder = MockOfIFolderUtil.CreateRemoteFolderMock(folderId, newFolderName, this.remoteRootPath + newFolderName, this.remoteRootId, "newChangeToken");

            this.remoteFolder.SetupDescendants(renamedRemoteFolder.Object);
            Assert.That(this.CreateCrawler().Handle(new StartNextSyncEvent()), Is.True);
            this.queue.Verify(
                q =>
                q.AddEvent(
                    It.Is <FolderEvent>(
                        e =>
                        e.Remote == MetaDataChangeType.CHANGED &&
                        e.Local == MetaDataChangeType.NONE &&
                        e.RemoteFolder.Equals(renamedRemoteFolder.Object))),
                Times.Once());
            this.VerifyThatCountOfAddedEventsIsLimitedTo(Times.Once());
            this.VerifyThatListenerHasBeenUsed();
        }
Example #8
0
        public void OneLocalFolderRenamed()
        {
            var uuid           = Guid.NewGuid();
            var oldLocalFolder = this.fsFactory.AddDirectory(Path.Combine(this.localRootPath, "oldFolder"));
            var newLocalFolder = this.fsFactory.AddDirectory(Path.Combine(this.localRootPath, "newFolder"));

            oldLocalFolder.Setup(f => f.Exists).Returns(false);
            newLocalFolder.SetupGuid(uuid);
            var remoteSubFolder = MockOfIFolderUtil.CreateRemoteFolderMock("oldFolderId", "oldFolder", this.remoteRootPath + "oldFolder", this.remoteRootId, "oldChange");
            var storedFolder    = new MappedObject("oldFolder", "oldFolderId", MappedObjectType.Folder, this.remoteRootId, "oldChange")
            {
                Guid = uuid
            };

            this.storage.SaveMappedObject(storedFolder);
            this.remoteFolder.SetupDescendants(remoteSubFolder.Object);

            this.localFolder.SetupDirectories(newLocalFolder.Object);
            var crawler = this.CreateCrawler();

            Assert.That(crawler.Handle(new StartNextSyncEvent()), Is.True);
            this.queue.Verify(
                q =>
                q.AddEvent(
                    It.Is <FolderEvent>(
                        e =>
                        e.LocalFolder.Equals(newLocalFolder.Object) &&
                        e.Local.Equals(MetaDataChangeType.CHANGED))),
                Times.Once());
            this.VerifyThatCountOfAddedEventsIsLimitedTo(Times.Once());
            this.VerifyThatListenerHasBeenUsed();
        }
Example #9
0
        public void MoveObjectToSubfolder()
        {
            var remoteFolder       = MockOfIFolderUtil.CreateRemoteFolderMock("folderId", "folder", "/folder", this.rootId);
            var remoteTargetFolder = MockOfIFolderUtil.CreateRemoteFolderMock("targetId", "target", "/target", this.rootId);

            this.session.AddRemoteObjects(remoteFolder.Object, remoteTargetFolder.Object);
            var localTargetFolder = MockOfIFileSystemInfoFactoryUtil.CreateLocalFolder(Path.Combine(Path.GetTempPath(), "target"));
            var localFolder       = MockOfIFileSystemInfoFactoryUtil.CreateLocalFolder(Path.Combine(Path.GetTempPath(), "target", "folder"));

            localFolder.Setup(f => f.Parent).Returns(localTargetFolder.Object);
            var mappedFolder = new MappedObject("folder", "folderId", MappedObjectType.Folder, this.rootId, "changetoken")
            {
                Guid = Guid.NewGuid()
            };
            var mappedTargetFolder = new MappedObject("target", "targetId", MappedObjectType.Folder, this.rootId, "changetoken")
            {
                Guid = Guid.NewGuid()
            };

            this.storage.Setup(s => s.GetObjectByLocalPath(It.Is <IDirectoryInfo>(d => d.Equals(localTargetFolder.Object)))).Returns(mappedTargetFolder);
            this.storage.Setup(s => s.GetObjectByRemoteId("folderId")).Returns(mappedFolder);
            remoteFolder.Setup(f => f.Move(this.remoteRootFolder.Object, remoteTargetFolder.Object)).Callback(() => { remoteFolder.Setup(r => r.ChangeToken).Returns("new ChangeToken"); }).Returns(remoteFolder.Object);

            this.underTest.Solve(localFolder.Object, remoteFolder.Object);

            remoteFolder.Verify(f => f.Move(this.remoteRootFolder.Object, remoteTargetFolder.Object), Times.Once());
            remoteFolder.VerifyUpdateLastModificationDate(localFolder.Object.LastWriteTimeUtc);
            this.storage.VerifySavedMappedObject(MappedObjectType.Folder, "folderId", "folder", "targetId", "new ChangeToken", true);
        }
        public void LocalFolderRenamed([Values(true, false)] bool childrenAreIgnored)
        {
            var remoteFolder = MockOfIFolderUtil.CreateRemoteFolderMock(this.id, this.oldName, "path", null, changetoken: null, ignored: childrenAreIgnored);

            remoteFolder.Setup(f => f.Rename(this.newName, true)).Callback(
                () => {
                remoteFolder.Setup(f => f.Name).Returns(this.newName);
                remoteFolder.Setup(f => f.ChangeToken).Returns(this.newChangeToken);
                remoteFolder.Setup(f => f.LastModificationDate).Returns(this.newModificationDate);
            }).Returns(Mock.Of <IObjectId>(o => o.Id == this.id));
            var localFolder = new Mock <IDirectoryInfo>();

            localFolder.SetupProperty(f => f.LastWriteTimeUtc, this.modificationDate);
            localFolder.Setup(f => f.Name).Returns(this.newName);
            var mappedFolder = new Mock <IMappedObject>();

            mappedFolder.SetupAllProperties();
            mappedFolder.SetupProperty(f => f.Guid, Guid.NewGuid());
            mappedFolder.SetupProperty(f => f.Name, this.oldName);
            mappedFolder.SetupProperty(f => f.RemoteObjectId, this.id);
            mappedFolder.Setup(f => f.Type).Returns(MappedObjectType.Folder);
            mappedFolder.Setup(f => f.LastContentSize).Returns(-1);
            this.storage.AddMappedFolder(mappedFolder.Object);

            this.underTest.Solve(localFolder.Object, remoteFolder.Object);

            remoteFolder.Verify(f => f.Rename(It.Is <string>(s => s == this.newName), It.Is <bool>(b => b == true)), Times.Once());

            this.storage.VerifySavedMappedObject(MappedObjectType.Folder, this.id, this.newName, null, this.newChangeToken, true, this.modificationDate, this.newModificationDate, ignored: childrenAreIgnored);
        }
Example #11
0
        public void Utf8CharacterLeadsToNoSavings()
        {
            string newFolderName = @"ä".Normalize(System.Text.NormalizationForm.FormD);
            var    remoteFolder  = MockOfIFolderUtil.CreateRemoteFolderMock("folderId", "folder", "/folder", this.rootId);
            var    targetFolder  = MockOfIFolderUtil.CreateRemoteFolderMock("targetId", "target", "/target", this.rootId);

            this.session.AddRemoteObjects(remoteFolder.Object, targetFolder.Object);
            var localTargetFolder = MockOfIFileSystemInfoFactoryUtil.CreateLocalFolder(Path.Combine(Path.GetTempPath(), "target"));
            var localFolder       = MockOfIFileSystemInfoFactoryUtil.CreateLocalFolder(Path.Combine(Path.GetTempPath(), "target", newFolderName));

            localFolder.Setup(f => f.Parent).Returns(localTargetFolder.Object);
            var mappedFolder = new MappedObject("folder", "folderId", MappedObjectType.Folder, this.rootId, "changetoken")
            {
                Guid = Guid.NewGuid()
            };
            var mappedTargetFolder = new MappedObject("target", "targetId", MappedObjectType.Folder, this.rootId, "changetoken")
            {
                Guid = Guid.NewGuid()
            };

            this.storage.Setup(s => s.GetObjectByLocalPath(It.Is <IDirectoryInfo>(d => d.Equals(localTargetFolder.Object)))).Returns(mappedTargetFolder);
            this.storage.Setup(s => s.GetObjectByRemoteId("folderId")).Returns(mappedFolder);
            remoteFolder.Setup(f => f.Move(this.remoteRootFolder.Object, targetFolder.Object)).Returns(remoteFolder.Object);
            remoteFolder.Setup(f => f.Rename(newFolderName, true)).Throws <CmisConstraintException>();

            Assert.Throws <InteractionNeededException>(() => this.underTest.Solve(localFolder.Object, remoteFolder.Object));

            remoteFolder.Verify(f => f.Move(this.remoteRootFolder.Object, targetFolder.Object), Times.Once());
            remoteFolder.Verify(f => f.Rename(newFolderName, true), Times.Once());
            remoteFolder.Verify(f => f.UpdateProperties(It.IsAny <System.Collections.Generic.IDictionary <string, object> >()), Times.Never());
            this.storage.VerifyThatNoObjectIsManipulated();
        }
Example #12
0
        private Mock <IFolder> CreateRemoteFolder(bool ignored)
        {
            var folder = MockOfIFolderUtil.CreateRemoteFolderMock(this.remoteId, this.newName, "path", this.oldParentId, ignored: ignored);

            folder.Setup(
                d =>
                d.Move(It.Is <IObjectId>(o => o.Id == this.oldParentId), It.Is <IObjectId>(o => o.Id == this.newParentId)))
            .Returns(folder.Object);
            return(folder);
        }
Example #13
0
        public void OneRemoteFolderAdded()
        {
            IFolder newRemoteFolder = MockOfIFolderUtil.CreateRemoteFolderMock("id", "name", "/name", this.remoteRootId).Object;

            this.remoteFolder.SetupDescendants(newRemoteFolder);
            var crawler = this.CreateCrawler();

            Assert.That(crawler.Handle(new StartNextSyncEvent()), Is.True);
            this.queue.Verify(q => q.AddEvent(It.Is <FolderEvent>(e => e.RemoteFolder.Equals(newRemoteFolder))), Times.Once());
            this.VerifyThatListenerHasBeenUsed();
        }
        public void MoveFolderToNewLocation([Values(true, false)] bool childrenAreIgnored)
        {
            DateTime modifiedDate    = DateTime.UtcNow.AddMinutes(1);
            string   oldFolderName   = "a";
            string   subFolderName   = "sub";
            string   subFolderId     = "sub";
            string   newFolderName   = "b";
            string   oldPath         = Path.Combine(Path.GetTempPath(), oldFolderName);
            string   oldRemotePath   = "/" + oldFolderName;
            string   newPath         = Path.Combine(Path.GetTempPath(), subFolderName, newFolderName);
            string   id              = "id";
            string   parentId        = "papa";
            string   lastChangeToken = "token";

            var dirInfo = new Mock <IDirectoryInfo>();

            dirInfo.Setup(d => d.FullName).Returns(oldPath);
            dirInfo.Setup(d => d.Name).Returns(oldFolderName);
            dirInfo.Setup(d => d.Parent).Returns(Mock.Of <IDirectoryInfo>(p => p.FullName == Path.GetTempPath()));

            Mock <IFolder> remoteObject = MockOfIFolderUtil.CreateRemoteFolderMock(id, newFolderName, newPath, subFolderId, lastChangeToken, childrenAreIgnored);

            remoteObject.Setup(f => f.LastModificationDate).Returns((DateTime?)modifiedDate);

            var mappedFolder = Mock.Of <IMappedObject>(
                f =>
                f.Name == oldFolderName &&
                f.RemoteObjectId == id &&
                f.LastChangeToken == "oldToken" &&
                f.LastRemoteWriteTimeUtc == DateTime.UtcNow &&
                f.Type == MappedObjectType.Folder &&
                f.ParentId == parentId &&
                f.Guid == Guid.NewGuid() &&
                f.LastContentSize == -1);
            var mappedSubFolder = Mock.Of <IMappedObject>(
                f =>
                f.Name == subFolderName &&
                f.RemoteObjectId == subFolderId &&
                f.LastChangeToken == "oldToken" &&
                f.Type == MappedObjectType.Folder &&
                f.ParentId == parentId &&
                f.Guid == Guid.NewGuid() &&
                f.LastContentSize == -1);

            this.storage.AddMappedFolder(mappedFolder, oldPath, oldRemotePath);
            this.storage.AddMappedFolder(mappedSubFolder, Path.Combine(Path.GetTempPath(), subFolderName), "/" + subFolderName);
            this.matcher.Setup(m => m.CreateLocalPath(It.Is <IFolder>(f => f == remoteObject.Object))).Returns(newPath);

            this.underTest.Solve(dirInfo.Object, remoteObject.Object);

            dirInfo.Verify(d => d.MoveTo(It.Is <string>(p => p.Equals(newPath))), Times.Once());

            this.storage.VerifySavedMappedObject(MappedObjectType.Folder, id, newFolderName, subFolderId, lastChangeToken, lastRemoteModification: modifiedDate, ignored: childrenAreIgnored);
        }
Example #15
0
        public void ChangedEventForUnchangedIgnoredStateObject()
        {
            this.SetUpMocks();
            var changedObject = MockOfIFolderUtil.CreateRemoteFolderMock(this.folderId, this.folderName, this.remotePath, Guid.NewGuid().ToString());
            var changeEvent   = new ContentChangeEvent(ChangeType.Updated, this.folderId);

            this.session.Setup(s => s.GetObject(It.IsAny <string>(), It.IsAny <IOperationContext>())).Returns(changedObject.Object);
            changeEvent.UpdateObject(this.session.Object);

            Assert.That(this.underTest.Handle(changeEvent), Is.False);

            this.ignoreStorage.Verify(s => s.AddOrUpdateEntryAndDeleteAllChildrenFromStorage(It.IsAny <IIgnoredEntity>()), Times.Never());
            this.queue.VerifyThatNoEventIsAdded();
        }
Example #16
0
 public void SetUp()
 {
     this.storage          = new Mock <IMetaDataStorage>();
     this.session          = new Mock <ISession>();
     this.remoteRootFolder = MockOfIFolderUtil.CreateRemoteFolderMock(this.rootId, "/", "/", null);
     this.session.AddRemoteObject(this.remoteRootFolder.Object);
     this.localRootFolder  = MockOfIFileSystemInfoFactoryUtil.CreateLocalFolder(Path.GetTempPath());
     this.mappedRootFolder = new MappedObject("/", this.rootId, MappedObjectType.Folder, null, "changeToken")
     {
         Guid = Guid.NewGuid()
     };
     this.storage.Setup(s => s.GetObjectByLocalPath(It.Is <IDirectoryInfo>(d => d.Equals(this.localRootFolder.Object)))).Returns(this.mappedRootFolder);
     this.underTest = new LocalObjectMoved(this.session.Object, this.storage.Object, true);
 }
        public void RemoteFolderAdded(
            [Values(true, false)] bool childrenAreIgnored,
            [Values(true, false)] bool extendedAttributesAvailable,
            [Values(true, false)] bool throwExceptionOnUpdateModificationDate)
        {
            var localModificationDate = DateTime.Now - TimeSpan.FromDays(1);
            var dirInfo = new Mock <IDirectoryInfo>();

            dirInfo.SetupAllProperties();
            dirInfo.Setup(d => d.FullName).Returns(this.path);
            dirInfo.Setup(d => d.Name).Returns(this.objectName);
            dirInfo.Setup(d => d.Parent).Returns(Mock.Of <IDirectoryInfo>());
            dirInfo.Setup(d => d.IsExtendedAttributeAvailable()).Returns(extendedAttributesAvailable);
            dirInfo.SetupProperty(dir => dir.LastWriteTimeUtc, localModificationDate);
            if (throwExceptionOnUpdateModificationDate)
            {
                dirInfo.SetupSet(d => d.LastWriteTimeUtc = It.IsAny <DateTime>()).Throws(new IOException("Another process is using this folder"));
            }

            Mock <IFolder> remoteObject = MockOfIFolderUtil.CreateRemoteFolderMock(
                this.id,
                this.objectName,
                this.path,
                this.parentId,
                this.lastChangeToken,
                ignored: childrenAreIgnored);

            remoteObject.Setup(f => f.LastModificationDate).Returns((DateTime?)this.creationDate);

            this.underTest.Solve(dirInfo.Object, remoteObject.Object);

            dirInfo.Verify(d => d.Create(), Times.Once());
            this.storage.VerifySavedMappedObject(
                MappedObjectType.Folder,
                this.id,
                this.objectName,
                this.parentId,
                this.lastChangeToken,
                extendedAttributesAvailable,
                lastLocalModification: throwExceptionOnUpdateModificationDate?localModificationDate: this.creationDate,
                lastRemoteModification: this.creationDate,
                ignored: childrenAreIgnored);
            dirInfo.VerifySet(d => d.LastWriteTimeUtc = It.Is <DateTime>(date => date.Equals(this.creationDate)), Times.Once());
            dirInfo.VerifySet(d => d.Uuid             = It.IsAny <Guid?>(), extendedAttributesAvailable ? Times.Once() : Times.Never());
            if (extendedAttributesAvailable)
            {
                dirInfo.VerifySet(d => d.Uuid = It.Is <Guid?>(uuid => uuid != null && !uuid.Equals(Guid.Empty)), Times.Once());
            }
        }
Example #18
0
        public void DoNotMoveFolderToSameLocation()
        {
            DateTime modifiedDate    = DateTime.UtcNow.AddMinutes(1);
            string   oldFolderName   = "a";
            string   subFolderName   = "sub";
            string   subFolderId     = "sub";
            string   newFolderName   = "b";
            string   oldPath         = Path.Combine(Path.GetTempPath(), oldFolderName);
            string   oldRemotePath   = "/" + oldFolderName;
            string   id              = "id";
            string   parentId        = "papa";
            string   lastChangeToken = "token";

            var dirInfo = new Mock <IDirectoryInfo>();

            dirInfo.Setup(d => d.FullName).Returns(oldPath);
            dirInfo.Setup(d => d.Name).Returns(oldFolderName);
            dirInfo.Setup(d => d.Parent).Returns(Mock.Of <IDirectoryInfo>(p => p.FullName == Path.GetTempPath()));

            Mock <IFolder> remoteObject = MockOfIFolderUtil.CreateRemoteFolderMock(id, newFolderName, oldPath, subFolderId, lastChangeToken);

            remoteObject.Setup(f => f.LastModificationDate).Returns((DateTime?)modifiedDate);

            var mappedFolder = Mock.Of <IMappedObject>(
                f =>
                f.Name == oldFolderName &&
                f.RemoteObjectId == id &&
                f.LastChangeToken == "oldToken" &&
                f.LastRemoteWriteTimeUtc == DateTime.UtcNow &&
                f.Type == MappedObjectType.Folder &&
                f.ParentId == parentId);
            var mappedSubFolder = Mock.Of <IMappedObject>(
                f =>
                f.Name == subFolderName &&
                f.RemoteObjectId == subFolderId &&
                f.LastChangeToken == "oldToken" &&
                f.Type == MappedObjectType.Folder &&
                f.ParentId == parentId);

            this.storage.AddMappedFolder(mappedFolder, oldPath, oldRemotePath);
            this.storage.AddMappedFolder(mappedSubFolder, Path.Combine(Path.GetTempPath(), subFolderName), "/" + subFolderName);
            this.matcher.Setup(m => m.CreateLocalPath(It.Is <IFolder>(f => f == remoteObject.Object))).Returns(oldPath);

            this.underTest.Solve(dirInfo.Object, remoteObject.Object);

            dirInfo.Verify(d => d.MoveTo(It.IsAny <string>()), Times.Never());

            this.storage.Verify(s => s.SaveMappedObject(It.IsAny <IMappedObject>()), Times.Never());
        }
Example #19
0
        public void PermissionDeniedOnModificationDateSavesTheLocalDate()
        {
            this.SetUpMocks();
            var localFolder  = this.CreateLocalDirectory(this.modificationDate.AddMinutes(1));
            var mappedObject = this.CreateMappedObject(false, this.modificationDate.AddMinutes(1));

            this.storage.AddMappedFolder(mappedObject);
            var remoteFolder = MockOfIFolderUtil.CreateRemoteFolderMock(this.remoteId, this.objectName, this.remotePath, this.parentId, this.oldChangeToken);

            remoteFolder.Setup(r => r.UpdateProperties(It.IsAny <IDictionary <string, object> >(), true)).Throws(new CmisPermissionDeniedException());

            this.underTest.Solve(localFolder.Object, remoteFolder.Object);
            this.VerifySavedFolder(this.oldChangeToken, localFolder.Object.LastWriteTimeUtc, remoteFolder.Object.LastModificationDate);
            remoteFolder.Verify(r => r.UpdateProperties(It.IsAny <IDictionary <string, object> >(), true));
        }
Example #20
0
        public void SimpleRemoteFolderHierarchyAdded()
        {
            var newRemoteSubFolder = MockOfIFolderUtil.CreateRemoteFolderMock("remoteSubFolder", "sub", "/name/sub", "remoteFolder");
            var newRemoteFolder    = MockOfIFolderUtil.CreateRemoteFolderMock("remoteFolder", "name", "/name", this.remoteRootId);

            newRemoteFolder.SetupDescendants(newRemoteSubFolder.Object);
            this.remoteFolder.SetupDescendants(newRemoteFolder.Object);
            var crawler = this.CreateCrawler();

            Assert.That(crawler.Handle(new StartNextSyncEvent()), Is.True);
            this.queue.Verify(q => q.AddEvent(It.Is <FolderEvent>(e => e.RemoteFolder.Equals(newRemoteFolder.Object))), Times.Once());
            this.queue.Verify(q => q.AddEvent(It.Is <FolderEvent>(e => e.RemoteFolder.Equals(newRemoteSubFolder.Object))), Times.Once());
            this.VerifyThatCountOfAddedEventsIsLimitedTo(Times.Exactly(2));
            this.VerifyThatListenerHasBeenUsed();
        }
Example #21
0
        public void FolderMovedToEqualFolderAndNamesAreEqual()
        {
            this.SetupOldMappedFolder();
            this.remoteModification = this.localModification - TimeSpan.FromMinutes(30);
            var newLocalParent = this.CreateNewLocalParent(this.newParentUuid);
            var localFolder    = this.CreateLocalFolder(this.oldName, newLocalParent, this.localModification);
            var remoteFolder   = MockOfIFolderUtil.CreateRemoteFolderMock(this.remoteObjectId, this.oldName, "/" + this.oldName, this.newRemoteParentId, this.newChangeToken);

            remoteFolder.SetupLastModificationDate(remoteModification);

            this.underTest.Solve(localFolder.Object, remoteFolder.Object, ContentChangeType.NONE, ContentChangeType.NONE);

            remoteFolder.VerifyUpdateLastModificationDate(this.localModification);
            this.VerifySavedFolder(this.oldName, this.localModification);
        }
Example #22
0
        public void IFolderConstructor()
        {
            string         folderName      = "a";
            string         path            = Path.Combine(Path.GetTempPath(), folderName);
            string         id              = "id";
            string         parentId        = "papa";
            string         lastChangeToken = "token";
            Mock <IFolder> remoteObject    = MockOfIFolderUtil.CreateRemoteFolderMock(id, folderName, path, parentId, lastChangeToken);
            MappedObject   mappedObject    = new MappedObject(remoteObject.Object);

            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");
        }
Example #23
0
        public void FolderMovedToEqualFolderAndBothNamesAreChangedAndRemoteModificationIsNewer()
        {
            this.SetupOldMappedFolder();
            this.localModification = this.remoteModification - TimeSpan.FromMinutes(30);
            var newLocalParent = this.CreateNewLocalParent(this.newParentUuid, this.newParentPath);
            var localFolder    = this.CreateLocalFolder(this.newLocalName, newLocalParent, localModification);
            var remoteFolder   = MockOfIFolderUtil.CreateRemoteFolderMock(this.remoteObjectId, this.newRemoteName, "/" + this.oldName, this.newRemoteParentId, this.newChangeToken);

            remoteFolder.SetupLastModificationDate(remoteModification);

            this.underTest.Solve(localFolder.Object, remoteFolder.Object, ContentChangeType.NONE, ContentChangeType.NONE);

            remoteFolder.Verify(r => r.Rename(It.IsAny <string>(), It.IsAny <bool>()), Times.Never());
            localFolder.Verify(f => f.MoveTo(Path.Combine()), Times.Never());
            this.VerifySavedFolder(this.newRemoteName, remoteModification);
        }
Example #24
0
        public void ChangeEventForFormerIgnoredObjectAndNowNotIgnoredObject()
        {
            this.SetUpMocks();
            var changedObject = MockOfIFolderUtil.CreateRemoteFolderMock(this.folderId, this.folderName, this.remotePath, Guid.NewGuid().ToString());
            var changeEvent   = new ContentChangeEvent(ChangeType.Updated, this.folderId);

            this.session.Setup(s => s.GetObject(It.IsAny <string>(), It.IsAny <IOperationContext>())).Returns(changedObject.Object);
            this.ignoreStorage.Setup(i => i.IsIgnoredId(this.folderId)).Returns(IgnoredState.IGNORED);
            changeEvent.UpdateObject(this.session.Object);

            Assert.That(this.underTest.Handle(changeEvent), Is.False);

            this.ignoreStorage.Verify(s => s.AddOrUpdateEntryAndDeleteAllChildrenFromStorage(It.IsAny <IIgnoredEntity>()), Times.Never());
            this.ignoreStorage.Verify(s => s.Remove(this.folderId));
            this.queue.Verify(q => q.AddEvent(It.Is <StartNextSyncEvent>(e => e.FullSyncRequested == true)), Times.Once());
            this.queue.VerifyThatNoOtherEventIsAddedThan <StartNextSyncEvent>();
        }
        public void RenameFolderToLowerCaseAndIOExceptionIsHandled()
        {
            this.SetUpMocks();
            DateTime modifiedDate    = DateTime.UtcNow.AddMinutes(1);
            string   oldFolderName   = "A";
            string   newFolderName   = "a";
            string   oldPath         = Path.Combine(Path.GetTempPath(), oldFolderName);
            string   oldRemotePath   = "/" + oldFolderName;
            string   newPath         = Path.Combine(Path.GetTempPath(), newFolderName);
            string   id              = "id";
            string   parentId        = "papa";
            string   lastChangeToken = "token";

            var dirInfo = new Mock <IDirectoryInfo>();

            dirInfo.Setup(d => d.FullName).Returns(oldPath);
            dirInfo.Setup(d => d.Name).Returns(oldFolderName);
            dirInfo.SetupProperty(d => d.LastWriteTimeUtc);
            dirInfo.Setup(d => d.Parent).Returns(Mock.Of <IDirectoryInfo>(p => p.FullName == Path.GetTempPath()));

            Mock <IFolder> remoteObject = MockOfIFolderUtil.CreateRemoteFolderMock(id, newFolderName, newPath, parentId, lastChangeToken);

            remoteObject.Setup(f => f.LastModificationDate).Returns((DateTime?)modifiedDate);

            var mappedFolder = Mock.Of <IMappedObject>(
                f =>
                f.Name == oldFolderName &&
                f.RemoteObjectId == id &&
                f.LastChangeToken == "oldToken" &&
                f.LastRemoteWriteTimeUtc == DateTime.UtcNow &&
                f.Type == MappedObjectType.Folder &&
                f.ParentId == parentId);

            this.storage.AddMappedFolder(mappedFolder, oldPath, oldRemotePath);
            dirInfo.Setup(d => d.MoveTo(It.Is <string>(p => p.Equals(newPath)))).Throws <IOException>();

            this.underTest.Solve(dirInfo.Object, remoteObject.Object);

            dirInfo.Verify(d => d.MoveTo(It.Is <string>(p => p.Equals(newPath))), Times.Once());

            dirInfo.VerifySet(d => d.LastWriteTimeUtc = It.Is <DateTime>(date => date.Equals(modifiedDate)), Times.Once());
            this.storage.Verify(
                s => s.SaveMappedObject(
                    It.Is <IMappedObject>(f => this.VerifySavedObject(f, MappedObjectType.Folder, id, oldFolderName, parentId, lastChangeToken, modifiedDate))),
                Times.Once());
        }
        public void FolderMovedToEqualFolderAndRemoteNameChanged([Values(true, false)] bool childrenAreIgnored)
        {
            this.SetupOldMappedFolder();
            this.remoteModification = this.localModification - TimeSpan.FromMinutes(30);
            var newLocalParent = this.CreateNewLocalParent(this.newParentUuid, this.newParentPath);
            var localFolder    = this.CreateLocalFolder(this.oldName, newLocalParent, this.localModification);

            localFolder.SetupMoveTo(Path.Combine(this.newParentPath, this.newRemoteName));
            var remoteFolder = MockOfIFolderUtil.CreateRemoteFolderMock(this.remoteObjectId, this.newRemoteName, "/" + this.newRemoteName, this.newRemoteParentId, this.newChangeToken, ignored: childrenAreIgnored);

            remoteFolder.SetupLastModificationDate(this.remoteModification);

            this.underTest.Solve(localFolder.Object, remoteFolder.Object, ContentChangeType.NONE, ContentChangeType.NONE);

            remoteFolder.Verify(r => r.Rename(It.IsAny <string>(), It.IsAny <bool>()), Times.Never());
            remoteFolder.VerifyUpdateLastModificationDate(this.localModification);
            this.VerifySavedFolder(this.newRemoteName, this.localModification, childrenAreIgnored);
        }
Example #27
0
        public void CreatedEventForIgnoredObject()
        {
            this.SetUpMocks();
            var createdObject = MockOfIFolderUtil.CreateRemoteFolderMock(this.folderId, this.folderName, this.remotePath, Guid.NewGuid().ToString());

            createdObject.SetupIgnore("*");
            var createdEvent = new ContentChangeEvent(ChangeType.Created, this.folderId);

            this.session.Setup(s => s.GetObject(It.IsAny <string>(), It.IsAny <IOperationContext>())).Returns(createdObject.Object);
            createdEvent.UpdateObject(this.session.Object);
            this.matcher.Setup(m => m.CanCreateLocalPath(createdObject.Object)).Returns(true);
            this.matcher.Setup(m => m.CreateLocalPath(createdObject.Object)).Returns(this.localPath);

            Assert.That(this.underTest.Handle(createdEvent), Is.False);

            this.ignoreStorage.Verify(s => s.AddOrUpdateEntryAndDeleteAllChildrenFromStorage(It.Is <IIgnoredEntity>(e => e.LocalPath == this.localPath && e.ObjectId == this.folderId)));
            this.queue.VerifyThatNoEventIsAdded();
        }
        public void RenameFolder([Values(true, false)] bool childrenAreIgnored)
        {
            this.SetUpMocks();
            var dir = Mock.Of <IDirectoryInfo>(
                f =>
                f.Name == "newName");
            var folder = MockOfIFolderUtil.CreateRemoteFolderMock("remoteId", "oldName", "path", ignored: childrenAreIgnored);
            var obj    = new MappedObject("oldName", "remoteId", MappedObjectType.Folder, "parentId", "changeToken")
            {
                Guid = Guid.NewGuid()
            };

            this.storage.AddMappedFolder(obj);
            this.underTest.Solve(dir, folder.Object, ContentChangeType.NONE, ContentChangeType.NONE);
            folder.Verify(f => f.Rename("newName", true), Times.Once());
            this.storage.VerifySavedMappedObject(MappedObjectType.Folder, "remoteId", "newName", "parentId", "changeToken", ignored: childrenAreIgnored);
            this.changeSolver.Verify(s => s.Solve(dir, folder.Object, ContentChangeType.NONE, ContentChangeType.NONE));
        }
Example #29
0
        public void RemoteFolderAddedAndExtendedAttributesAreAvailable()
        {
            var dirInfo = new Mock <IDirectoryInfo>();

            dirInfo.SetupAllProperties();
            dirInfo.Setup(d => d.FullName).Returns(this.path);
            dirInfo.Setup(d => d.Name).Returns(this.objectName);
            dirInfo.Setup(d => d.Parent).Returns(Mock.Of <IDirectoryInfo>());
            dirInfo.Setup(d => d.IsExtendedAttributeAvailable()).Returns(true);

            Mock <IFolder> remoteObject = MockOfIFolderUtil.CreateRemoteFolderMock(this.id, this.objectName, this.path, this.parentId, this.lastChangeToken);

            remoteObject.Setup(f => f.LastModificationDate).Returns((DateTime?)this.creationDate);

            this.underTest.Solve(dirInfo.Object, remoteObject.Object);
            dirInfo.Verify(d => d.Create(), Times.Once());
            this.storage.VerifySavedMappedObject(MappedObjectType.Folder, this.id, this.objectName, this.parentId, this.lastChangeToken, true, this.creationDate);
            dirInfo.VerifySet(d => d.LastWriteTimeUtc = It.Is <DateTime>(date => date.Equals(this.creationDate)), Times.Once());
            dirInfo.VerifySet(d => d.Uuid             = It.Is <Guid?>(uuid => uuid != null && !uuid.Equals(Guid.Empty)), Times.Once());
        }
Example #30
0
        public void RemoteFolderChangedAndModificationDateCouldNotBeSet()
        {
            DateTime creationDate    = DateTime.UtcNow;
            string   folderName      = "a";
            string   path            = Path.Combine(Path.GetTempPath(), folderName);
            string   id              = "id";
            string   parentId        = "papa";
            string   lastChangeToken = "token";
            string   newChangeToken  = "newToken";
            DateTime modification    = DateTime.UtcNow;

            var dirInfo = new Mock <IDirectoryInfo>();

            dirInfo.Setup(d => d.FullName).Returns(path);
            dirInfo.Setup(d => d.Name).Returns(folderName);
            dirInfo.Setup(d => d.Parent).Returns(Mock.Of <IDirectoryInfo>());
            dirInfo.SetupGet(d => d.LastWriteTimeUtc).Returns(modification);
            dirInfo.SetupSet(d => d.LastWriteTimeUtc = It.IsAny <DateTime>()).Throws(new IOException("Another process is using this folder"));

            var mappedObject = new MappedObject(
                folderName,
                id,
                MappedObjectType.Folder,
                parentId,
                lastChangeToken)
            {
                Guid = Guid.NewGuid()
            };

            this.storage.AddMappedFolder(mappedObject);

            Mock <IFolder> remoteObject = MockOfIFolderUtil.CreateRemoteFolderMock(id, folderName, path, parentId, newChangeToken);

            remoteObject.Setup(f => f.LastModificationDate).Returns((DateTime?)creationDate);

            this.underTest.Solve(dirInfo.Object, remoteObject.Object);

            this.storage.VerifySavedMappedObject(MappedObjectType.Folder, id, folderName, parentId, newChangeToken, lastLocalModification: modification);
            dirInfo.VerifySet(d => d.LastWriteTimeUtc = It.Is <DateTime>(date => date.Equals(creationDate)), Times.Once());
            this.queue.Verify(q => q.AddEvent(It.IsAny <ISyncEvent>()), Times.Never());
        }