private void When_async_reading_from_stream_it_must_raise_events(NotifyFilters filters, [NotNull] string expectedText) { // Arrange const string directoryToWatch = @"c:\some"; const string containerDirectoryName = "Container"; const string fileNameToRead = "file.txt"; string pathToFileToRead = Path.Combine(directoryToWatch, containerDirectoryName, fileNameToRead); FakeFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingBinaryFile(pathToFileToRead, 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(pathToFileToRead, FileMode.Open, FileAccess.ReadWrite)) { // Act Task <int> task = stream.ReadAsync(buffer, 0, buffer.Length); task.Wait(); } watcher.FinishAndWaitForFlushed(MaxTestDurationInMilliseconds); // Assert string text = string.Join(Environment.NewLine, listener.GetEventsCollectedAsText()); text.Should().Be(expectedText); } } }