public void ConstructorWithRemoteFolder() { var remoteFolder = Mock.Of<IFolder>(); var underTest = new FolderEvent(null, remoteFolder); Assert.That(underTest.RemoteFolder, Is.EqualTo(remoteFolder)); }
public void ConstructorWithLocalFolder() { var localFolder = Mock.Of<IDirectoryInfo>(); var underTest = new FolderEvent(localFolder); Assert.That(underTest.LocalFolder, Is.EqualTo(localFolder)); }
public void LocalPathIsFilterable() { var path = "localpath"; var localFolder = Mock.Of<IDirectoryInfo>(f => f.FullName == path); var underTest = new FolderEvent(localFolder); Assert.That(underTest.LocalPath, Is.EqualTo(path)); }
public void LocalPathReturnsNullIfLocalFolderIsNotSet() { var remoteFolder = Mock.Of<IFolder>(); var underTest = new FolderEvent(null, remoteFolder); Assert.That(underTest is IFilterableLocalPathEvent); Assert.That(underTest.LocalPath, Is.Null); }
public void ConstructorTakesLocalAndRemoteFolder() { var localFolder = Mock.Of<IDirectoryInfo>(); var remoteFolder = Mock.Of<IFolder>(); var underTest = new FolderEvent(localFolder, remoteFolder); Assert.That(underTest.LocalFolder, Is.EqualTo(localFolder)); Assert.That(underTest.RemoteFolder, Is.EqualTo(remoteFolder)); }
public void FetchOnlyIfLocalFolderNull() { var matcher = new Mock<IPathMatcher>(); var remoteFolder = new Mock<IFolder>(); var folder = new Mock<IDirectoryInfo>(); var folderEvent = new FolderEvent(remoteFolder: remoteFolder.Object, localFolder: folder.Object); var fetcher = new LocalObjectFetcher(matcher.Object); Assert.That(fetcher.Handle(folderEvent), Is.False); Assert.That(folderEvent.LocalFolder, Is.EqualTo(folder.Object)); }
public void FetchLocalFolder() { var localPath = Path.GetTempPath(); var remotePath = Path.Combine(Path.GetTempPath(), "a"); var matcher = new Mock<IPathMatcher>(); matcher.Setup(m => m.CreateLocalPath(remotePath)).Returns(localPath); matcher.Setup(m => m.CanCreateLocalPath(remotePath)).Returns(true); var remoteFolder = new Mock<IFolder>(); remoteFolder.Setup(f => f.Path).Returns(remotePath); var folderEvent = new FolderEvent(remoteFolder: remoteFolder.Object); var fetcher = new LocalObjectFetcher(matcher.Object); Assert.That(fetcher.Handle(folderEvent), Is.False); Assert.That(folderEvent.LocalFolder, Is.Not.Null); Assert.That(folderEvent.LocalFolder.FullName, Is.EqualTo(localPath)); }
public void NoChangeDetectedForFolder() { var remoteObject = new Mock<IFolder>(); var folderEvent = new FolderEvent(remoteFolder: remoteObject.Object); folderEvent.Remote = MetaDataChangeType.NONE; var underTest = new RemoteSituationDetection(); Assert.AreEqual(SituationType.NOCHANGE, underTest.Analyse(this.storage.Object, folderEvent)); }
public void LocalFolderAddedSituation() { var localFolder = Mock.Of<IDirectoryInfo>(); var localFolderAddedSolver = new Mock<ISolver>(); var localDetection = new LocalSituationDetection(); var remoteDetection = new RemoteSituationDetection(); var folderEvent = new FolderEvent(localFolder: localFolder) { Local = MetaDataChangeType.CREATED, Remote = MetaDataChangeType.NONE }; var mechanism = this.CreateMechanism(localDetection, remoteDetection); mechanism.Solver[(int)SituationType.ADDED, (int)SituationType.NOCHANGE] = localFolderAddedSolver.Object; Assert.IsTrue(mechanism.Handle(folderEvent)); localFolderAddedSolver.Verify( s => s.Solve( It.IsAny<IFileSystemInfo>(), It.IsAny<IObjectId>(), It.IsAny<ContentChangeType>(), It.IsAny<ContentChangeType>()), Times.Once()); this.VerifyThatListenerIsInformed(); }
public void FolderMovedDetectionOnChangeEvent() { string folderName = "old"; string oldLocalPath = Path.Combine(Path.GetTempPath(), folderName); string remoteId = "remoteId"; string oldParentId = "oldParentId"; string newParentId = "newParentId"; var remoteFolder = new Mock<IFolder>(); remoteFolder.Setup(f => f.Name).Returns(folderName); remoteFolder.Setup(f => f.Path).Returns("/new/" + folderName); remoteFolder.Setup(f => f.Id).Returns(remoteId); remoteFolder.Setup(f => f.ParentId).Returns(newParentId); var mappedParentFolder = Mock.Of<IMappedObject>(p => p.RemoteObjectId == oldParentId && p.Type == MappedObjectType.Folder); var mappedFolder = this.storage.AddLocalFolder(oldLocalPath, remoteId); mappedFolder.Setup(f => f.Name).Returns(folderName); mappedFolder.Setup(f => f.ParentId).Returns(mappedParentFolder.RemoteObjectId); var folderEvent = new FolderEvent(remoteFolder: remoteFolder.Object) { Remote = MetaDataChangeType.CHANGED }; var underTest = new RemoteSituationDetection(); Assert.AreEqual(SituationType.MOVED, underTest.Analyse(this.storage.Object, folderEvent)); }
public void FolderRenameDetectionOnChangeEvent() { string remoteId = "remoteId"; string oldName = "old"; string newName = "new"; var remoteFolder = new Mock<IFolder>(); remoteFolder.Setup(f => f.Name).Returns(newName); remoteFolder.Setup(f => f.Id).Returns(remoteId); var mappedFolder = Mock.Of<IMappedObject>(f => f.RemoteObjectId == remoteId && f.Name == oldName && f.Type == MappedObjectType.Folder); this.storage.AddMappedFolder(mappedFolder); var folderEvent = new FolderEvent(remoteFolder: remoteFolder.Object) { Remote = MetaDataChangeType.CHANGED }; var underTest = new RemoteSituationDetection(); Assert.AreEqual(SituationType.RENAMED, underTest.Analyse(this.storage.Object, folderEvent)); }
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); }
private void HandleAsIFolder(ContentChangeEvent contentChangeEvent) { IFolder folder = contentChangeEvent.CmisObject as IFolder; IMappedObject dir = this.storage.GetObjectByRemoteId(folder.Id); IDirectoryInfo dirInfo = (dir == null) ? null : this.fsFactory.CreateDirectoryInfo(this.storage.GetLocalPath(dir)); var folderEvent = new FolderEvent(dirInfo, folder, this); switch(contentChangeEvent.Type) { case DotCMIS.Enums.ChangeType.Created: Logger.Debug("Created Folder Event"); folderEvent.Remote = MetaDataChangeType.CREATED; break; case DotCMIS.Enums.ChangeType.Updated: folderEvent.Remote = MetaDataChangeType.CHANGED; break; case DotCMIS.Enums.ChangeType.Security: folderEvent.Remote = MetaDataChangeType.CHANGED; break; } Queue.AddEvent(folderEvent); }
public void FolderRemoved() { var folderEvent = new FolderEvent(Mock.Of<IDirectoryInfo>()) { Local = MetaDataChangeType.DELETED }; Assert.That(this.underTest.Analyse(Mock.Of<IMetaDataStorage>(), folderEvent), Is.EqualTo(SituationType.REMOVED)); }
public void FolderEventWithIFolder() { var session = new Mock<ISession>(); var fetcher = new RemoteObjectFetcher(session.Object, Mock.Of<IMetaDataStorage>()); var folderEvent = new FolderEvent(new Mock<IDirectoryInfo>().Object, new Mock<IFolder>().Object); fetcher.Handle(folderEvent); session.Verify(s => s.GetObject(It.IsAny<string>(), It.IsAny<IOperationContext>()), Times.Never()); }
private void TriggerNonExistingSolver() { var detection = new Mock<ISituationDetection<AbstractFolderEvent>>(); int numberOfSolver = Enum.GetNames(typeof(SituationType)).Length; ISolver[,] solver = new ISolver[numberOfSolver, numberOfSolver]; detection.Setup(d => d.Analyse( It.Is<IMetaDataStorage>(db => db == this.storage.Object), It.IsAny<AbstractFolderEvent>())).Returns(SituationType.NOCHANGE); var mechanism = this.CreateMechanism(detection.Object, detection.Object, solver); var localFolder = Mock.Of<IDirectoryInfo>(); var folderEvent = new FolderEvent(localFolder: localFolder) { Local = MetaDataChangeType.NONE, Remote = MetaDataChangeType.NONE }; mechanism.Handle(folderEvent); }
public void AddingEventBackToQueueOnRetryExceptionInSolverAndIncrementRetryCounter() { var localDetection = new Mock<ISituationDetection<AbstractFolderEvent>>(); var remoteDetection = new Mock<ISituationDetection<AbstractFolderEvent>>(); int numberOfSolver = Enum.GetNames(typeof(SituationType)).Length; ISolver[,] solver = new ISolver[numberOfSolver, numberOfSolver]; var retryProducer = new Mock<ISolver>(); retryProducer.Setup( r => r.Solve( It.IsAny<IFileSystemInfo>(), It.IsAny<IObjectId>(), It.IsAny<ContentChangeType>(), It.IsAny<ContentChangeType>())).Throws(new RetryException("reason")); solver[(int)SituationType.NOCHANGE, (int)SituationType.NOCHANGE] = retryProducer.Object; var mechanism = this.CreateMechanism(localDetection.Object, remoteDetection.Object, solver); localDetection.Setup(d => d.Analyse(this.storage.Object, It.IsAny<AbstractFolderEvent>())).Returns(SituationType.NOCHANGE); remoteDetection.Setup(d => d.Analyse(this.storage.Object, It.IsAny<AbstractFolderEvent>())).Returns(SituationType.NOCHANGE); var folderEvent = new FolderEvent(Mock.Of<IDirectoryInfo>(), Mock.Of<IFolder>()) { Local = MetaDataChangeType.NONE, Remote = MetaDataChangeType.NONE }; Assert.That(mechanism.Handle(folderEvent), Is.True); this.queue.Verify(q => q.AddEvent(folderEvent), Times.Once()); Assert.That(folderEvent.RetryCount, Is.EqualTo(1)); }
public void DoNotFilterIgnoredLocalFolderAddEvent() { this.SetupMocks(); var folderEvent = new FolderEvent(Mock.Of<IDirectoryInfo>(d => d.FullName == this.ignoredPath), null) { Local = MetaDataChangeType.CREATED }; Assert.That(this.underTest.Handle(folderEvent), Is.False); }
public void DoNotFilterIgnoredRemoteFolderAddedEvent() { this.SetupMocks(); var folderEvent = new FolderEvent(null, Mock.Of<IFolder>(f => f.Id == this.ignoredObjectId)) { Local = MetaDataChangeType.CREATED }; Assert.That(this.underTest.Handle(folderEvent), Is.False); }
public void AccumulatesRemoteMovedFolderEvents() { var storage = new Mock<IMetaDataStorage>(); var storedObject = Mock.Of<IMappedObject>( o => o.ParentId == "oldParentId"); storage.Setup(s => s.GetObjectByRemoteId(this.remoteId)).Returns(storedObject); storage.Setup(s => s.GetLocalPath(storedObject)).Returns(this.localPath); var fsFactory = new Mock<IFileSystemInfoFactory>(); var localPathInfo = Mock.Of<IDirectoryInfo>(); fsFactory.Setup(f => f.CreateDirectoryInfo(this.localPath)).Returns(localPathInfo); var acc = new RemoteObjectMovedOrRenamedAccumulator(Mock.Of<ISyncEventQueue>(), storage.Object, fsFactory.Object); var remoteFolder = Mock.Of<IFolder>( f => f.Id == this.remoteId && f.ParentId == this.parentId); var folderEvent = new FolderEvent(remoteFolder: remoteFolder) { Remote = MetaDataChangeType.CREATED }; Assert.That(acc.Handle(folderEvent), Is.False); Assert.That(folderEvent.LocalFolder, Is.EqualTo(localPathInfo)); }
public void ThrowExceptionOnCmisConnectionExceptionOccurence() { var localDetection = new Mock<ISituationDetection<AbstractFolderEvent>>(); var remoteDetection = new Mock<ISituationDetection<AbstractFolderEvent>>(); int numberOfSolver = Enum.GetNames(typeof(SituationType)).Length; ISolver[,] solver = new ISolver[numberOfSolver, numberOfSolver]; var interactionNeededProducer = new Mock<ISolver>(); var exception = new CmisConnectionException("reason"); interactionNeededProducer.Setup( r => r.Solve( It.IsAny<IFileSystemInfo>(), It.IsAny<IObjectId>(), It.IsAny<ContentChangeType>(), It.IsAny<ContentChangeType>())).Throws(exception); solver[(int)SituationType.NOCHANGE, (int)SituationType.NOCHANGE] = interactionNeededProducer.Object; var mechanism = this.CreateMechanism(localDetection.Object, remoteDetection.Object, solver); localDetection.Setup(d => d.Analyse(this.storage.Object, It.IsAny<AbstractFolderEvent>())).Returns(SituationType.NOCHANGE); remoteDetection.Setup(d => d.Analyse(this.storage.Object, It.IsAny<AbstractFolderEvent>())).Returns(SituationType.NOCHANGE); var folderEvent = new FolderEvent(Mock.Of<IDirectoryInfo>(), Mock.Of<IFolder>()) { Local = MetaDataChangeType.NONE, Remote = MetaDataChangeType.NONE }; Assert.Throws<CmisConnectionException>(() => mechanism.Handle(folderEvent)); this.queue.VerifyThatNoEventIsAdded(); }
public void IsIFilterableRemoteObjectEvent() { var remoteFolder = Mock.Of<IFolder>(); var underTest = new FolderEvent(null, remoteFolder); Assert.That(underTest is IFilterableRemoteObjectEvent); }
private void HandleFolderEvents(IFSEvent e) { var movedEvent = e as IFSMovedEvent; FolderEvent folderEvent; if (movedEvent != null) { folderEvent = new FolderMovedEvent( this.fsFactory.CreateDirectoryInfo(movedEvent.OldPath), this.fsFactory.CreateDirectoryInfo(movedEvent.LocalPath), null, null, this) { Local = MetaDataChangeType.MOVED }; } else { folderEvent = new FolderEvent(this.fsFactory.CreateDirectoryInfo(e.LocalPath), null, this); switch (e.Type) { case WatcherChangeTypes.Created: folderEvent.Local = MetaDataChangeType.CREATED; break; case WatcherChangeTypes.Changed: folderEvent.Local = MetaDataChangeType.CHANGED; break; case WatcherChangeTypes.Deleted: folderEvent.Local = MetaDataChangeType.DELETED; break; default: // This should never ever happen return; } } Queue.AddEvent(folderEvent); }
public void NotifyOneLocalFolderCreatedEventToQueue() { var dir = Mock.Of<IDirectoryInfo>(); var dirEvent = new FolderEvent(dir, null) { Local = MetaDataChangeType.CREATED }; this.collection.creationEvents.Add(dirEvent); this.underTest.MergeEventsAndAddToQueue(this.collection); this.queue.VerifyThatNoOtherEventIsAddedThan<FolderEvent>(); this.queue.Verify(q => q.AddEvent(dirEvent), Times.Once()); this.queue.Verify(q => q.AddEvent(It.IsAny<ISyncEvent>()), Times.Exactly(1)); }
public void FolderChanged() { var storage = new Mock<IMetaDataStorage>(); Guid guid = Guid.NewGuid(); var dirInfo = Mock.Of<IDirectoryInfo>( d => d.Name == "Name" && d.FullName == Path.Combine(Path.GetTempPath(), "Name") && d.Uuid == guid); storage.Setup(s => s.GetObjectByLocalPath(dirInfo)).Returns(Mock.Of<IMappedObject>()); var folderEvent = new FolderEvent(dirInfo) { Local = MetaDataChangeType.CHANGED }; Assert.That(this.underTest.Analyse(storage.Object, folderEvent), Is.EqualTo(SituationType.CHANGED)); }
public void NotifyOneRemoteFolderCreatedEventToQueue() { var folder = Mock.Of<IFolder>(); var folderEvent = new FolderEvent(null, folder) { Remote = MetaDataChangeType.CREATED }; this.collection.creationEvents.Add(folderEvent); this.underTest.MergeEventsAndAddToQueue(this.collection); this.queue.VerifyThatNoOtherEventIsAddedThan<FolderEvent>(); this.queue.Verify(q => q.AddEvent(folderEvent), Times.Once()); this.queue.Verify(q => q.AddEvent(It.IsAny<ISyncEvent>()), Times.Exactly(1)); }
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 NotifyAboutMultipleCreatedEvents() { var file = Mock.Of<IFileInfo>(); var fileEvent = new FileEvent(file) { Local = MetaDataChangeType.CREATED }; this.collection.creationEvents.Add(fileEvent); var folder = Mock.Of<IFolder>(); var folderEvent = new FolderEvent(null, folder) { Remote = MetaDataChangeType.CREATED }; this.collection.creationEvents.Add(folderEvent); var dir = Mock.Of<IDirectoryInfo>(); var dirEvent = new FolderEvent(dir, null) { Local = MetaDataChangeType.CREATED }; this.collection.creationEvents.Add(dirEvent); var doc = Mock.Of<IDocument>(); var docEvent = new FileEvent(null, doc) { Remote = MetaDataChangeType.CREATED }; this.collection.creationEvents.Add(docEvent); this.underTest.MergeEventsAndAddToQueue(this.collection); this.queue.VerifyThatNoOtherEventIsAddedThan<AbstractFolderEvent>(); this.queue.Verify(q => q.AddEvent(fileEvent), Times.Once()); this.queue.Verify(q => q.AddEvent(docEvent), Times.Once()); this.queue.Verify(q => q.AddEvent(folderEvent), Times.Once()); this.queue.Verify(q => q.AddEvent(dirEvent), Times.Once()); this.queue.Verify(q => q.AddEvent(It.IsAny<ISyncEvent>()), Times.Exactly(4)); }
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 FolderRemovedDetection() { var remoteObject = new Mock<IFolder>(); var folderEvent = new FolderEvent(remoteFolder: remoteObject.Object); folderEvent.Remote = MetaDataChangeType.DELETED; var underTest = new RemoteSituationDetection(); Assert.AreEqual(SituationType.REMOVED, underTest.Analyse(this.storage.Object, folderEvent)); }