public async void FileIndexingEvents_EmptyFolderIndexed_NotRaised(string eventName) { var engine = SearchEngineFactory.New(); var tcs = new TaskCompletionSource <bool>(); using (var folder = new TestFolder()) { var folderPath = folder.Path; #pragma warning disable CS4014 Task.Run(async() => { await Task.Delay(1000); tcs.TrySetResult(true); }); #pragma warning restore CS4014 engine.Add(folderPath); await Task.Delay(100); engine.AddHandler(eventName, args => { tcs.TrySetResult(false); }); Assert.True(await tcs.Task); } }
public async void FileIndexingEvents_NotIndexedFileMovedToSubFolder_Raised(string eventName) { var engine = SearchEngineFactory.New(); var tcs = new TaskCompletionSource <bool>(); using (var folder = new TestFolder()) { var folderPath = folder.Path; using (var file = new TestFile("foo", folderPath)) { var fileName = file.Name; using (var subFolder = new TestFolder(folderPath)) { var subFolderPath = subFolder.Path; engine.Add(subFolderPath); await Task.Delay(300); engine.AddHandler(eventName, args => { var expectedPath = Path.GetFullPath($"{subFolderPath}\\{fileName}"); tcs.TrySetResult(expectedPath == args.Path); }); file.Move(subFolderPath); Assert.True(await tcs.Task); } } } }
public void Add_TwoFiles_ReturnsTrue() { var engine = SearchEngineFactory.New(); Assert.True(engine.Add(TestTextFiles.OneLineFile)); Assert.True(engine.Add(TestTextFiles.TwoLinesFile)); }
public async void FileIndexingEvents_FileMovedToWatchedDirectory_Raised(string eventName) { var engine = SearchEngineFactory.New(); var tcs = new TaskCompletionSource <bool>(); using (var sourceFolder = new TestFolder()) { using (var file = new TestFile("foo", sourceFolder.Path)) { var fileName = file.Name; using (var destFolder = new TestFolder()) { var destFolderPath = destFolder.Path; using (new TestFile("bar", destFolderPath)) { engine.Add(destFolderPath); await Task.Delay(100); engine.AddHandler(eventName, args => { tcs.TrySetResult(Path.GetFullPath($"{destFolderPath}\\{fileName}") == args.Path); }); file.Move(destFolderPath); Assert.True(await tcs.Task); } } } } }
public void Remove_RemoveAdded_ReturnsTrue() { var engine = SearchEngineFactory.New(); engine.Add(TestTextFiles.OneLineFile); Assert.True(engine.Remove(TestTextFiles.OneLineFile)); }
public void Add_AlreadyAdded_ReturnsFalse() { var engine = SearchEngineFactory.New(); engine.Add(TestTextFiles.OneLineFile); Assert.False(engine.Add(TestTextFiles.OneLineFile)); }
public async void FilePathChanged_NotEmptyWatchedFolderRenamed_Raised() { var engine = SearchEngineFactory.New(); var tcs = new TaskCompletionSource <bool>(); using (var folder = new TestFolder()) { var folderPath = folder.Path; using (new TestFile("foo", folderPath)) { engine.Add(folderPath); await Task.Delay(100); var newName = $"new-test-{Guid.NewGuid()}"; engine.FilePathChanged += args => { var expectedPath = Path.GetFullPath($".\\{newName}"); tcs.TrySetResult(expectedPath == args.Path); }; folder.Rename(newName); Assert.True(await tcs.Task); } } }
public async void PathWatchingEnded_EmptyWatchedFolderRemoved_Raised() { var engine = SearchEngineFactory.New(); var tcs = new TaskCompletionSource <bool>(); using (var folder = new TestFolder()) { var folderPath = folder.Path; using (var file = new TestFile("foo", folderPath)) { engine.Add(folder.Path); await Task.Delay(100); engine.PathWatchingEnded += args => { tcs.TrySetResult(Path.GetFullPath(folderPath) == args.Path); }; file.Delete(); folder.Delete(); Assert.True(await tcs.Task); } } }
public async void FileUpdateInitiated_FileInFolderChanged_Raised() { var engine = SearchEngineFactory.New(); var tcs = new TaskCompletionSource <bool>(); using (var folder = new TestFolder()) { var folderPath = folder.Path; using (var file = new TestFile("foo", folderPath)) { var filePath = file.Path; engine.Add(folderPath); await Task.Delay(100); engine.FileUpdateInitiated += args => { tcs.TrySetResult(Path.GetFullPath(filePath) == args.Path); }; file.ChangeContent("bar"); Assert.True(await tcs.Task); } } }
public async void FileRemovingEvents_FileInFolderRemoved_Raised(string eventName) { var engine = SearchEngineFactory.New(); var tcs = new TaskCompletionSource <bool>(); using (var folder = new TestFolder()) { var folderPath = folder.Path; using (var subFolder = new TestFolder(folderPath)) { var subFolderPath = subFolder.Path; using (var file = new TestFile("foo", subFolderPath)) { var filePath = file.Path; engine.Add(folderPath); await Task.Delay(100); engine.AddHandler(eventName, args => { tcs.TrySetResult(Path.GetFullPath(filePath) == args.Path); }); file.Delete(); Assert.True(await tcs.Task); } } } }
public async void FileIndexingEvents_FileCreatedToWatchedDirectory_Raised(string eventName) { var engine = SearchEngineFactory.New(); var tcs = new TaskCompletionSource <bool>(); using (var folder = new TestFolder()) { var fileName = TestFile.GenerateFileName(); var folderPath = folder.Path; engine.Add(folderPath); await Task.Delay(100); engine.AddHandler(eventName, args => { tcs.TrySetResult(Path.GetFullPath($"{folderPath}\\{fileName}") == args.Path); }); using (new TestFile("foo", folderPath, fileName)) { Assert.True(await tcs.Task); } await Task.Delay(100); } }
private static async void TestEncoding(string filePath, string searchQuery, int expectedLineNumber, int expectedPosition) { var engine = SearchEngineFactory.New(); var tcs = new TaskCompletionSource <bool>(); engine.FileIndexingEnded += args => { var wordEntries = engine.Search(searchQuery).ToList(); if (wordEntries.Count != 1) { tcs.TrySetResult(false); } var entry = wordEntries.First(); var result = expectedLineNumber == entry.LineNumber && expectedPosition == entry.Position; tcs.TrySetResult(result); }; var isAdded = engine.Add(filePath); Assert.True(isAdded); Assert.True(await tcs.Task); }
public async void FileIndexingEvents_FileAdded_Raised(string eventName) { var filePath = TestTextFiles.OneLineFile; var engine = SearchEngineFactory.New(); var tcs = new TaskCompletionSource <bool>(); engine.AddHandler(eventName, args => { tcs.TrySetResult(Path.GetFullPath(filePath) == args.Path); }); Assert.True(engine.Add(filePath)); Assert.True(await tcs.Task); }
private static async void IndexFileAndDoAction(string filePath, Action <ISearchEngine, string> action) { var engine = SearchEngineFactory.New(); var tcs = new TaskCompletionSource <bool>(); engine.FileIndexingEnded += args => { action(engine, args.Path); tcs.TrySetResult(true); }; var isAdded = engine.Add(filePath); Assert.True(isAdded); Assert.True(await tcs.Task); }
public async void PathWatchingStarted_EmptyFolderAdded_Raised() { var engine = SearchEngineFactory.New(); var tcs = new TaskCompletionSource <bool>(); using (var folder = new TestFolder()) { var folderPath = folder.Path; engine.PathWatchingStarted += args => { tcs.TrySetResult(Path.GetFullPath(folderPath) == args.Path); }; engine.Add(folderPath); await Task.Delay(100); Assert.True(await tcs.Task); } }
public async void FileIndexingEvents_FileChanged_Raised(string eventName) { var engine = SearchEngineFactory.New(); var tcs = new TaskCompletionSource <bool>(); using (var file = new TestFile("foo")) { var filePath = file.Path; engine.Add(filePath); await Task.Delay(100); engine.AddHandler(eventName, args => { tcs.TrySetResult(Path.GetFullPath(filePath) == args.Path); }); file.ChangeContent("bar"); Assert.True(await tcs.Task); } }
public async void FilePathChanged_FileRenamed_Raised() { var engine = SearchEngineFactory.New(); var tcs = new TaskCompletionSource <bool>(); using (var file = new TestFile("foo")) { engine.Add(file.Path); await Task.Delay(100); var newName = $"new-test-{Guid.NewGuid()}.txt"; engine.FilePathChanged += args => { tcs.TrySetResult(Path.GetFullPath(".\\" + newName) == args.Path); }; file.Rename(newName); Assert.True(await tcs.Task); } }
public async void PathWatchingStarted_FolderWithFileAddedAgain_NotRaised() { var engine = SearchEngineFactory.New(); var tcs = new TaskCompletionSource <bool>(); using (var folder = new TestFolder()) { using (new TestFile("foo", folder.Path)) { engine.Add(folder.Path); await Task.Delay(100); } } engine.PathWatchingStarted += args => { tcs.TrySetResult(false); }; #pragma warning disable CS4014 Task.Run(async() => { await Task.Delay(1000); tcs.TrySetResult(true); }); #pragma warning restore CS4014 using (var folder = new TestFolder()) { var folderPath = folder.Path; using (new TestFile("foo", folderPath)) { Assert.True(await tcs.Task); } } }
public void Remove_NullPath_ReturnsFalse() { var engine = SearchEngineFactory.New(); Assert.False(engine.Remove(null)); }
public void Add_EmptyPath_ReturnsFalse() { var engine = SearchEngineFactory.New(); Assert.False(engine.Add(string.Empty)); }
public void Remove_NotAddedFile_ReturnsFalse() { var engine = SearchEngineFactory.New(); Assert.False(engine.Remove(TestTextFiles.OneLineFile)); }
public void Add_DirectoryPathNotExists_ReturnsFalse() { var engine = SearchEngineFactory.New(); Assert.False(engine.Add(TestTextFiles.RootDirectory + "foo")); }
public void Add_FilePathNotExists_ReturnsFalse() { var engine = SearchEngineFactory.New(); Assert.False(engine.Add(TestTextFiles.OneLineFile + "foo")); }
public void Add_InvalidPath_ReturnsFalse() { var engine = SearchEngineFactory.New(); Assert.False(engine.Add("INVALID")); }
public void Add_NullPath_ReturnsFalse() { var engine = SearchEngineFactory.New(); Assert.False(engine.Add(null)); }