public void ReportFSFileAddedEvent() { this.localFile.Delete(); this.localFile = new FileInfo(Path.Combine(this.localFolder.FullName, Path.GetRandomFileName())); this.queue.Setup(q => q.AddEvent(It.Is<FSEvent>(e => e.LocalPath == this.localFile.FullName))) .Callback((ISyncEvent file) => this.returnedFSEvent = file as FSEvent); var watcherData = this.GetWatcherData(this.localFolder.FullName, this.queue.Object); watcherData.Watcher.EnableEvents = true; var t = Task.Factory.StartNew(() => { int count = 0; while (this.returnedFSEvent == null && count < RETRIES) { WaitWatcherData(watcherData, this.localFile.FullName, WatcherChangeTypes.Created, MILISECONDSWAIT); count++; } }); using (this.localFile.Create()) { } t.Wait(); if (this.returnedFSEvent != null) { Assert.IsFalse(this.returnedFSEvent.IsDirectory); Assert.AreEqual(this.localFile.FullName, this.returnedFSEvent.LocalPath); Assert.AreEqual(WatcherChangeTypes.Created, this.returnedFSEvent.Type); } else { Assert.Inconclusive("Missed file added event"); } }
public void FilterIgnoresNonExistingPaths() { var storage = new Mock<IMetaDataStorage>(); var fsFactory = new Mock<IFileSystemInfoFactory>(); var filter = new IgnoreAlreadyHandledFsEventsFilter(storage.Object, fsFactory.Object); var fsEvent = new FSEvent(WatcherChangeTypes.Created, Path.Combine(Path.GetTempPath(), "path"), true); Assert.That(filter.Handle(fsEvent), Is.False); }
public void Constructor() { string name = "test"; string path = Path.Combine(Path.GetTempPath(), name); var e = new FSEvent(WatcherChangeTypes.Created, path, false); Assert.That(e.Name, Is.EqualTo(name)); Assert.That(e.LocalPath, Is.EqualTo(path)); }
public void FsEventStoresDirectoryState() { var path = Path.Combine(Path.GetTempPath(), "newPath"); Directory.CreateDirectory(path); var e = new FSEvent(WatcherChangeTypes.Created, path, true); Assert.That(e.IsDirectory, Is.True, "It is a Directory"); }
public void FsEventExtractsDirectoryName() { string name = "newPath"; var path = Path.Combine(Path.GetTempPath(), name); Directory.CreateDirectory(path); var e = new FSEvent(WatcherChangeTypes.Created, path, true); Assert.That(e.Name, Is.EqualTo(name)); }
/// <summary></summary> /// <param name="e"></param> /// <returns></returns> public override bool Handle(ISyncEvent e) { if (!(e is FSEvent)) { return(false); } FSEvent fsEvent = e as FSEvent; if (fsEvent.Type != WatcherChangeTypes.Deleted) { return(false); } return(true); }
protected void SetUp() { var config = ITUtils.GetConfig(); this.uuid = Guid.NewGuid(); string localPath = Path.Combine(config[1].ToString(), Path.GetRandomFileName()); this.localFolder = new DirectoryInfo(localPath); this.localFolder.Create(); this.localSubFolder = new DirectoryInfo(Path.Combine(this.localFolder.FullName, Path.GetRandomFileName())); this.localSubFolder.Create(); this.localFile = new FileInfo(Path.Combine(this.localFolder.FullName, Path.GetRandomFileName())); using (this.localFile.Create()) { } if (AreExtendedAttributesAvailable(this.localFile.FullName)) { new FileInfoWrapper(this.localFile).Uuid = this.uuid; } if (AreExtendedAttributesAvailable(this.localSubFolder.FullName)) { new DirectoryInfoWrapper(this.localSubFolder).Uuid = this.uuid; } this.queue = new Mock<ISyncEventQueue>(); this.returnedFSEvent = null; }
public void ReportFSFolderMovedEvent() { var anotherSubFolder = new DirectoryInfo(Path.Combine(this.localFolder.FullName, Path.GetRandomFileName())); anotherSubFolder.Create(); string oldpath = this.localSubFolder.FullName; string newpath = Path.Combine(anotherSubFolder.FullName, Path.GetRandomFileName()); this.queue.Setup(q => q.AddEvent(It.IsAny<FSMovedEvent>())) .Callback((ISyncEvent f) => this.returnedFSEvent = f as FSMovedEvent); var watcherData = this.GetWatcherData(this.localFolder.FullName, this.queue.Object); watcherData.Watcher.EnableEvents = true; var t = Task.Factory.StartNew(() => { int count = 0; while (this.returnedFSEvent == null && count < RETRIES) { WaitWatcherData(watcherData, newpath, WatcherChangeTypes.Renamed, MILISECONDSWAIT); count++; } }); new DirectoryInfoWrapper(this.localSubFolder).MoveTo(newpath); t.Wait(); if (this.returnedFSEvent != null) { FSMovedEvent movedEvent = this.returnedFSEvent as FSMovedEvent; Assert.That(movedEvent.OldPath, Is.EqualTo(oldpath)); Assert.That(movedEvent.LocalPath, Is.EqualTo(newpath)); Assert.That(movedEvent.Type, Is.EqualTo(WatcherChangeTypes.Renamed)); Assert.That(movedEvent.IsDirectory, Is.True); } else { Assert.Inconclusive("Missed folder moved event(s)"); } this.localSubFolder = new DirectoryInfo(newpath); }
public void ReportFSFolderRenamedEvent() { string oldpath = this.localSubFolder.FullName; string newpath = Path.Combine(this.localFolder.FullName, Path.GetRandomFileName()); this.queue.Setup(q => q.AddEvent(It.Is<FSEvent>(e => e.LocalPath == newpath))) .Callback((ISyncEvent folder) => this.returnedFSEvent = folder as FSEvent); var watcherData = this.GetWatcherData(this.localFolder.FullName, this.queue.Object); watcherData.Watcher.EnableEvents = true; var t = Task.Factory.StartNew(() => { int count = 0; while (this.returnedFSEvent == null && count < RETRIES) { WaitWatcherData(watcherData, newpath, WatcherChangeTypes.Renamed, MILISECONDSWAIT); count++; } }); this.localSubFolder.MoveTo(newpath); t.Wait(); if (this.returnedFSEvent != null) { Assert.IsTrue(this.returnedFSEvent.IsDirectory); if (this.returnedFSEvent.Type == WatcherChangeTypes.Renamed) { Assert.AreEqual(oldpath, (this.returnedFSEvent as FSMovedEvent).OldPath); Assert.AreEqual(newpath, (this.returnedFSEvent as FSMovedEvent).LocalPath); } else { Assert.Inconclusive(string.Format("File System Event: \"{0}\"", this.returnedFSEvent.ToString())); } } else { Assert.Inconclusive("Missed folder renamed event"); } this.localSubFolder = new DirectoryInfo(newpath); }
public void ReportFSWatcherRootFolderRemoved() { this.queue.Setup(q => q.AddEvent(It.Is<FSEvent>(e => e.LocalPath == this.localFolder.FullName))) .Callback((ISyncEvent file) => this.returnedFSEvent = file as FSEvent); var watcherData = this.GetWatcherData(this.localFolder.FullName, this.queue.Object); this.localSubFolder.Delete(); this.localFile.Delete(); watcherData.Watcher.EnableEvents = true; var t = Task.Factory.StartNew(() => { int count = 0; while (this.returnedFSEvent == null && count < RETRIES) { try { WaitWatcherData(watcherData, this.localFolder.FullName, WatcherChangeTypes.Deleted, MILISECONDSWAIT); count++; } catch (FileNotFoundException) { break; } } }); this.localFolder.Delete(); t.Wait(); if (this.returnedFSEvent != null) { Assert.AreEqual(this.localFolder.FullName, this.returnedFSEvent.LocalPath); Assert.AreEqual(WatcherChangeTypes.Deleted, this.returnedFSEvent.Type); Assert.That(this.returnedFSEvent.IsDirectory, Is.True); } else { Assert.Inconclusive("Missed folder removed event"); } }
public void ReportFSFolderChangedEvent() { this.queue.Setup(q => q.AddEvent(It.Is<FSEvent>(e => e.LocalPath == this.localSubFolder.FullName && e.Type == WatcherChangeTypes.Changed))) .Callback((ISyncEvent file) => this.returnedFSEvent = file as FSEvent); var watcherData = this.GetWatcherData(this.localFolder.FullName, this.queue.Object); watcherData.Watcher.EnableEvents = true; var t = Task.Factory.StartNew(() => { int count = 0; while (this.returnedFSEvent == null && count < RETRIES) { WaitWatcherData(watcherData, this.localSubFolder.FullName, WatcherChangeTypes.Changed, MILISECONDSWAIT); count++; } }); this.localSubFolder.CreationTime = this.localSubFolder.CreationTime.AddDays(1); t.Wait(); if (this.returnedFSEvent != null) { Assert.IsTrue(this.returnedFSEvent.IsDirectory); Assert.AreEqual(this.localSubFolder.FullName, this.returnedFSEvent.LocalPath); Assert.AreEqual(WatcherChangeTypes.Changed, this.returnedFSEvent.Type); } else { Assert.Inconclusive("Missed folder changed event"); } }
public void HandleFSFileAddedEvents() { this.queue.Setup(q => q.AddEvent(It.IsAny<AbstractFolderEvent>())) .Callback((ISyncEvent f) => this.returnedFileEvent = f as AbstractFolderEvent); var watcher = new WatcherConsumer(this.queue.Object); var fileCreatedFSEvent = new FSEvent(WatcherChangeTypes.Created, this.localFile.FullName, false); Assert.True(watcher.Handle(fileCreatedFSEvent)); Assert.AreEqual(MetaDataChangeType.CREATED, this.returnedFileEvent.Local); Assert.AreEqual(ContentChangeType.CREATED, (this.returnedFileEvent as FileEvent).LocalContent); Assert.AreEqual(this.localFile.FullName, (this.returnedFileEvent as FileEvent).LocalFile.FullName); Assert.IsNull((this.returnedFileEvent as FileEvent).RemoteFile); Assert.AreEqual(MetaDataChangeType.NONE, (this.returnedFileEvent as FileEvent).Remote); Assert.AreEqual(ContentChangeType.NONE, (this.returnedFileEvent as FileEvent).RemoteContent); }
public void HandleFSFolderRemovedEvents() { this.queue.Setup(q => q.AddEvent(It.IsAny<AbstractFolderEvent>())) .Callback((ISyncEvent f) => this.returnedFolderEvent = f as AbstractFolderEvent); var watcher = new WatcherConsumer(this.queue.Object); var folderRemovedFSEvent = new FSEvent(WatcherChangeTypes.Deleted, this.localFolder.FullName, true); Assert.True(watcher.Handle(folderRemovedFSEvent)); Assert.AreEqual(MetaDataChangeType.DELETED, this.returnedFolderEvent.Local); Assert.AreEqual(this.localFolder.FullName, (this.returnedFolderEvent as FolderEvent).LocalFolder.FullName); Assert.IsNull((this.returnedFolderEvent as FolderEvent).RemoteFolder); Assert.AreEqual(MetaDataChangeType.NONE, (this.returnedFolderEvent as FolderEvent).Remote); }
public void FSEventPreventNullTest() { ISyncEvent e = new FSEvent(WatcherChangeTypes.Created,null); }
public void DoNotFilterValidLocalFSAddedEvents() { this.SetupMocks(); var fileEvent = new FSEvent(WatcherChangeTypes.Created, Path.Combine(Path.GetTempPath(), "file.txt"), false); Assert.That(this.underTest.Handle(fileEvent), Is.False); }
public void FilterLocalFSDeletionEvents() { this.SetupMocks(); var fileEvent = new FSEvent(WatcherChangeTypes.Deleted, Path.Combine(this.ignoredPath, "file.txt"), false); Assert.That(this.underTest.Handle(fileEvent), Is.True); }
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, "changeToken"); storage.SaveMappedObject(mappedObject); var session = new Mock<ISession>(); session.SetupSessionDefaultValues(); session.SetupChangeLogToken("default"); session.SetupTypeSystem(); IFolder remote = MockOfIFolderUtil.CreateRemoteFolderMock(id, name, (string)null, changetoken: "changeToken").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); }
public void ReportFSFileChangedEvent() { this.queue.Setup(q => q.AddEvent(It.Is<FSEvent>(e => e.LocalPath == this.localFile.FullName && e.Type == WatcherChangeTypes.Changed))) .Callback((ISyncEvent file) => this.returnedFSEvent = file as FSEvent); var watcherData = this.GetWatcherData(this.localFolder.FullName, this.queue.Object); watcherData.Watcher.EnableEvents = true; var t = Task.Factory.StartNew(() => { int count = 0; while (this.returnedFSEvent == null && count < RETRIES) { WaitWatcherData(watcherData, this.localFile.FullName, WatcherChangeTypes.Changed, MILISECONDSWAIT); count++; } }); using (FileStream stream = File.OpenWrite(this.localFile.FullName)) { byte[] data = new byte[1024]; // Write data stream.Write(data, 0, data.Length); } t.Wait(); if (this.returnedFSEvent != null) { if (this.returnedFSEvent.Type == WatcherChangeTypes.Changed) { Assert.IsFalse(this.returnedFSEvent.IsDirectory); Assert.AreEqual(this.localFile.FullName, this.returnedFSEvent.LocalPath); } else { Assert.Inconclusive(string.Format("File System Event: \"{0}\"", this.returnedFSEvent.ToString())); } } else { Assert.Inconclusive("Missed file changed event"); } }
public void FSEventTest() { ISyncEvent e = new FSEvent(WatcherChangeTypes.Created, "test"); Assert.AreEqual("FSEvent with type \"Created\" on path \"test\"",e.ToString()); }