private void When_async_appending_to_stream_it_must_raise_events(NotifyFilters filters, [NotNull] string expectedText) { // Arrange const string directoryToWatch = @"c:\some"; const string containerDirectoryName = "Container"; const string fileNameToWrite = "file.txt"; string pathToFileToWrite = Path.Combine(directoryToWatch, containerDirectoryName, fileNameToWrite); FakeFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingBinaryFile(pathToFileToWrite, BufferFactory.Create(1024)) .Build(); var buffer = new byte[512]; using (FakeFileSystemWatcher watcher = fileSystem.ConstructFileSystemWatcher(directoryToWatch)) { watcher.NotifyFilter = filters; watcher.IncludeSubdirectories = true; using (var listener = new FileSystemWatcherEventListener(watcher)) { using (IFileStream stream = fileSystem.File.Open(pathToFileToWrite, FileMode.Open, FileAccess.ReadWrite)) { stream.Seek(0, SeekOrigin.End); // Act Task task = stream.WriteAsync(buffer, 0, buffer.Length); task.Wait(); } watcher.FinishAndWaitForFlushed(MaxTestDurationInMilliseconds); // Assert string text = string.Join(Environment.NewLine, listener.GetEventsCollectedAsText()); text.Should().Be(expectedText); } } }