public void ChangedDocuments_ReactsOnRename() { InNewTempDirectory(path => { var source = new DirectoryDocumentSource(path, "*.txt"); var sourceFileName = CopyContentFilesTo("text.txt", path).Single(); var tcsLastChanged = new TaskCompletionSource <IList <DocumentInfo> >(); using (source.WatchForChangedDocuments() .Buffer(TimeSpan.FromSeconds(0.1)) .Where(list => list.Any()) .Subscribe(d => tcsLastChanged.TrySetResult(d))) { var newFileName = sourceFileName + ".new.txt"; File.Move(sourceFileName, newFileName); var lastChanged = tcsLastChanged.Task.Result; Assert.That(lastChanged, Is.Not.Null); lastChanged = lastChanged.Distinct().ToList(); Assert.That(lastChanged, Has.Count.EqualTo(2)); Assert.That(lastChanged.Select(d => d.Id), Is.EquivalentTo(new[] { sourceFileName, newFileName }).IgnoreCase); } }); }
public void ChangedDocuments_ReactsOnCreateUpdateDelete() { InNewTempDirectory(path => { var source = new DirectoryDocumentSource(path, "*.txt"); Assert.That(source.FindAllDocuments().ToList().Wait(), Is.Empty); var tcsLastChanged = new TaskCompletionSource <DocumentInfo>(); Action reset = () => { Thread.Sleep(300); tcsLastChanged = new TaskCompletionSource <DocumentInfo>(); }; string destFileName = null; Action assertLastChangedIsDestFile = () => { var lastChanged = tcsLastChanged.Task.Result; Assert.That(lastChanged, Is.Not.Null); Assert.That(lastChanged.Id, Is.EqualTo(destFileName).IgnoreCase); }; using (source.WatchForChangedDocuments().Subscribe(d => tcsLastChanged.TrySetResult(d))) { destFileName = CopyContentFilesTo("text.txt", path).Single(); assertLastChangedIsDestFile(); reset(); File.AppendAllText(destFileName, "\nNew line to change file"); assertLastChangedIsDestFile(); reset(); File.Delete(destFileName); assertLastChangedIsDestFile(); } }); }
public void ChangedDocuments_WhenFolderDoesNotExist_Fails() { var source = new DirectoryDocumentSource(GetNewTempDirectoryPath()); Assert.That(IgnoreEventsReturnError(source.WatchForChangedDocuments()).Wait(), Is.Not.Null); }