public void AggregatesFolderDeletedAndCreatedEventToFSMovedEvent([Values(true, false)] bool ordered) { using (var underTest = new CreatedChangedDeletedFileSystemEventHandler(this.queue.Object, this.storage.Object, this.fsFactory.Object)) { string newName = "new"; string oldName = "old"; Guid guid = Guid.NewGuid(); string newPath = Path.Combine(this.path, newName); string oldPath = Path.Combine(Directory, oldName); this.fsFactory.Setup(f => f.IsDirectory(newPath)).Returns((bool?)true); this.fsFactory.AddDirectory(newPath, guid, true); this.fsFactory.Setup(f => f.CreateFileInfo(oldPath)).Returns(Mock.Of <IFileInfo>(file => file.Exists == false && file.FullName == oldPath)); this.storage.AddLocalFolder(oldPath, "id", guid); if (ordered) { underTest.Handle(null, new FileSystemEventArgs(WatcherChangeTypes.Deleted, Directory, oldName)); underTest.Handle(null, new FileSystemEventArgs(WatcherChangeTypes.Created, this.path, newName)); } else { underTest.Handle(null, new FileSystemEventArgs(WatcherChangeTypes.Created, this.path, newName)); underTest.Handle(null, new FileSystemEventArgs(WatcherChangeTypes.Deleted, Directory, oldName)); } this.WaitForThreshold(); this.queue.Verify(q => q.AddEvent(It.Is <FSMovedEvent>(e => e.IsDirectory == true && e.Name == newName && e.OldPath == oldPath && e.LocalPath == newPath)), Times.Once()); this.WaitForThreshold(); this.queue.VerifyThatNoOtherEventIsAddedThan <FSMovedEvent>(); } }
public void HandlesTwoFileCreatedEvent() { using (var underTest = new CreatedChangedDeletedFileSystemEventHandler(this.queue.Object, this.storage.Object, this.fsFactory.Object)) { this.fsFactory.Setup(f => f.IsDirectory(this.path)).Returns((bool?)false); this.fsFactory.AddFile(this.path, true); underTest.Handle(null, new FileSystemEventArgs(WatcherChangeTypes.Created, Directory, Name)); underTest.Handle(null, new FileSystemEventArgs(WatcherChangeTypes.Created, Directory, Name)); this.WaitForThreshold(); this.queue.Verify(q => q.AddEvent(It.Is <FSEvent>(e => e.IsDirectory == false && e.Name == Name && e.LocalPath == this.path && e.Type == WatcherChangeTypes.Created)), Times.Exactly(2)); this.queue.VerifyThatNoOtherEventIsAddedThan <FSEvent>(); } }
public void DoesNotAggregateFolderChangedEventsToFSMovedEvent() { using (var underTest = new CreatedChangedDeletedFileSystemEventHandler(this.queue.Object, this.storage.Object, this.fsFactory.Object)) { Guid guid = Guid.NewGuid(); this.fsFactory.Setup(f => f.IsDirectory(this.path)).Returns((bool?)true); this.fsFactory.AddDirectory(this.path, guid, true); this.storage.AddLocalFolder(this.path, "id", guid); underTest.Handle(null, new FileSystemEventArgs(WatcherChangeTypes.Created, Directory, Name)); underTest.Handle(null, new FileSystemEventArgs(WatcherChangeTypes.Changed, Directory, Name)); this.WaitForThreshold(); this.queue.Verify(q => q.AddEvent(It.IsAny <FSMovedEvent>()), Times.Never()); } }
public void IgnoresDeletionOfPathWithNoEntryInStorage() { using (var underTest = new CreatedChangedDeletedFileSystemEventHandler(this.queue.Object, this.storage.Object, this.fsFactory.Object)) { underTest.Handle(null, new FileSystemEventArgs(WatcherChangeTypes.Deleted, Directory, Name)); this.queue.Verify(q => q.AddEvent(It.IsAny <ISyncEvent>()), Times.Never()); } }
public void IgnoresEventOnNonExistingPath() { using (var underTest = new CreatedChangedDeletedFileSystemEventHandler(this.queue.Object, this.storage.Object, this.fsFactory.Object)) { this.fsFactory.Setup(f => f.IsDirectory(this.path)).Returns((bool?)null); underTest.Handle(null, new FileSystemEventArgs(WatcherChangeTypes.Created, Directory, Name)); this.queue.Verify(q => q.AddEvent(It.IsAny <ISyncEvent>()), Times.Never()); } }
public void HandleDirectoryNotFoundExceptionOnExtendedAttributeByJustIgnoringTheEvent() { using (var underTest = new CreatedChangedDeletedFileSystemEventHandler(this.queue.Object, this.storage.Object, this.fsFactory.Object)) { this.fsFactory.Setup(f => f.IsDirectory(this.path)).Returns((bool?)true); var dirInfo = this.fsFactory.AddDirectory(this.path, Guid.Empty, true); underTest.Handle(null, new FileSystemEventArgs(WatcherChangeTypes.Created, Directory, Name)); dirInfo.Setup(f => f.Uuid).Throws(new DirectoryNotFoundException()); this.WaitForThreshold(); this.queue.Verify(q => q.AddEvent(It.IsAny <ISyncEvent>()), Times.Never); } }
public void HandleChangeEventOnNoMoreExistingFileOrFolderByJustPassingTheEvent() { using (var underTest = new CreatedChangedDeletedFileSystemEventHandler(this.queue.Object, this.storage.Object, this.fsFactory.Object)) { this.fsFactory.Setup(f => f.IsDirectory(this.path)).Returns((bool?)true); var dirInfo = this.fsFactory.AddDirectory(this.path, Guid.Empty, true); underTest.Handle(null, new FileSystemEventArgs(WatcherChangeTypes.Changed, Directory, Name)); dirInfo.Setup(d => d.Exists).Returns(false); this.WaitForThreshold(); this.queue.Verify(q => q.AddEvent(It.Is <FSEvent>(f => f.IsDirectory == true && f.LocalPath == this.path && f.Name == Name && f.Type == WatcherChangeTypes.Changed))); this.queue.VerifyThatNoOtherEventIsAddedThan <FSEvent>(); } }
public void HandleExceptionsOnProcessingByInvokingCrawlSync() { using (var underTest = new CreatedChangedDeletedFileSystemEventHandler(this.queue.Object, this.storage.Object, this.fsFactory.Object)) { this.fsFactory.Setup(f => f.IsDirectory(this.path)).Throws(new Exception("Generic exception")); underTest.Handle(null, new FileSystemEventArgs(WatcherChangeTypes.Created, Directory, Name)); this.queue.Verify(q => q.AddEvent(It.Is <StartNextSyncEvent>(e => e.FullSyncRequested == true))); this.queue.VerifyThatNoOtherEventIsAddedThan <StartNextSyncEvent>(); this.WaitForThreshold(); this.queue.Verify(q => q.AddEvent(It.Is <StartNextSyncEvent>(e => e.FullSyncRequested == true))); this.queue.VerifyThatNoOtherEventIsAddedThan <StartNextSyncEvent>(); } }
public void HandlesFileDeletedEvent() { using (var underTest = new CreatedChangedDeletedFileSystemEventHandler(this.queue.Object, this.storage.Object, this.fsFactory.Object, Threshold)) { this.fsFactory.Setup(f => f.IsDirectory(this.path)).Returns((bool?)null); var file = this.fsFactory.AddFile(this.path, false); this.storage.AddLocalFile(file.Object.FullName, "id", Guid.NewGuid()); underTest.Handle(null, new FileSystemEventArgs(WatcherChangeTypes.Deleted, Directory, Name)); this.queue.Verify(q => q.AddEvent(It.IsAny <ISyncEvent>()), Times.Never); this.WaitForThreshold(); this.queue.Verify(q => q.AddEvent(It.Is <FSEvent>(e => e.IsDirectory == false && e.LocalPath == this.path && e.Name == Name && e.Type == WatcherChangeTypes.Deleted))); this.queue.VerifyThatNoOtherEventIsAddedThan <FSEvent>(); } }
public void HandleExceptionsOnUuidReadingByJustPassingEmptyUuid() { using (var underTest = new CreatedChangedDeletedFileSystemEventHandler(this.queue.Object, this.storage.Object, this.fsFactory.Object)) { this.fsFactory.Setup(f => f.IsDirectory(this.path)).Returns((bool?)false); var filemock = this.fsFactory.AddFile(this.path, Guid.Empty, true); filemock.Setup(f => f.Uuid).Throws <ExtendedAttributeException>(); underTest.Handle(null, new FileSystemEventArgs(WatcherChangeTypes.Created, Directory, Name)); this.queue.Verify(q => q.AddEvent(It.IsAny <ISyncEvent>()), Times.Never); this.WaitForThreshold(); this.queue.Verify(q => q.AddEvent(It.Is <FSEvent>(e => e.IsDirectory == false && e.Name == Name && e.LocalPath == this.path && e.Type == WatcherChangeTypes.Created)), Times.Once()); this.queue.VerifyThatNoOtherEventIsAddedThan <FSEvent>(); } }
public void HandleExceptionsOnTransformingByInvokingCrawlSync() { using (var underTest = new CreatedChangedDeletedFileSystemEventHandler(this.queue.Object, this.storage.Object, this.fsFactory.Object)) { this.fsFactory.Setup(f => f.IsDirectory(this.path)).Returns((bool?)false); this.fsFactory.AddFile(this.path, Guid.Empty, true); underTest.Handle(null, new FileSystemEventArgs(WatcherChangeTypes.Created, Directory, Name)); this.queue.Verify(q => q.AddEvent(It.IsAny <ISyncEvent>()), Times.Never()); this.fsFactory.Setup(f => f.CreateDirectoryInfo(It.IsAny <string>())).Throws(new Exception("Generic exception")); this.fsFactory.Setup(f => f.CreateFileInfo(It.IsAny <string>())).Throws(new Exception("Generic exception")); this.WaitForThreshold(); this.queue.VerifyThatNoOtherEventIsAddedThan <StartNextSyncEvent>(); this.queue.Verify(q => q.AddEvent(It.Is <StartNextSyncEvent>(e => e.FullSyncRequested == true))); } }