public async Task TestSubscription() { var fileSystem = new FileSystem(TestContext.TestRunDirectory); fileSystem.RemoveFile(TestFileName); Assert.AreEqual(false, fileSystem.FileExists(TestFileName)); var c = new TaskCompletionSource<IFileInfo>(); using (await fileSystem.SubscribeAsync(TestFilePattern, s => c.TrySetResult(s)).ConfigureAwait(false)) { using (var writer = new StreamWriter(fileSystem.OpenWrite(TestFileName))) { writer.BaseStream.SetLength(0); writer.Write("123456789"); } var result = await c.Task.ConfigureAwait(false); Assert.AreEqual(TestFileName.ToString(), Path.GetFileName(result.FilePath.ToString())); } }
public async Task TestSubscription() { var fileSystem = new FileSystem(PathUtility.GetDirectory()); fileSystem.RemoveFile(TestFileName); Assert.Equal(false, fileSystem.FileExists(TestFileName)); var c = new TaskCompletionSource<FileChangeEventArgs>(); using (fileSystem.Subscribe(GlobPattern.All, s => c.TrySetResult(s))) { using (var writer = new StreamWriter(fileSystem.OpenWrite(TestFileName))) { writer.BaseStream.SetLength(0); writer.Write("123456789"); } var result = await c.Task.ConfigureAwait(false); Assert.Equal(TestFileName.ToString(), Path.GetFileName(result.FileInfo.FilePath.ToString())); } }
public async Task TestDirectorySubscription() { IFileSystem fileSystem = new FileSystem(TestContext.TestRunDirectory); fileSystem.RemoveFile(TestFileName); Assert.AreEqual(false, fileSystem.FileExists(TestFileName)); var c = new TaskCompletionSource<IEnumerable<IFileInfo>>(); using (await fileSystem.SubscribeDirectoryGetFilesAsync(PathInfo.Create(""), "txt", infos => { c.SetResult(infos); }).ConfigureAwait(false)) { using (var writer = new StreamWriter(fileSystem.OpenWrite(TestFileName))) { writer.BaseStream.SetLength(0); writer.Write("123456789"); } var result = await c.Task.ConfigureAwait(false); CollectionAssert.AreEquivalent(new[] { TestFileName }, result.Select(i => i.FilePath).ToList()); } }