title: How can I use FileSystemWatcher from System.IO.Abstractions to monitor a mock filesystem?
body: <p>I'm trying to create a class to monitor USB device arrivals and removals on Linux. On Linux, USB devices are represented as device files under <code>/dev/bus/usb</code> which are created/deleted in response to these events.</p>
  
  <p>It seems the best way to track these events is using <code>FileSystemWatcher</code>. To make the class testable, I'm using <a href="https://github.com/tathamoddie/System.IO.Abstractions" rel="nofollow noreferrer"><code>System.IO.Abstractions</code></a> and injecting an instance of <code>IFileSystem</code> to the class during construction. What I want is to create something that behaves like a <code>FileSystemWatcher</code> but monitors changes to the injected <code>IFileSystem</code>, not the real file-system directly.</p>
  
  <p>Looking at <code>FileSystemWatcherBase</code> and <code>FileSystemWatcherWrapper</code> from <code>System.IO.Abstractions</code>, I'm not sure how to do this. At the moment I have this (which I know is wrong):</p>
  
  <pre><code>public DevMonitor(
      [NotNull] IFileSystem fileSystem,
      [NotNull] IDeviceFileParser deviceFileParser,
      [NotNull] ILogger logger,
      [NotNull] string devDirectoryPath = DefaultDevDirectoryPath)
  {
      Raise.ArgumentNullException.IfIsNull(logger, nameof(logger));
      Raise.ArgumentNullException.IfIsNull(devDirectoryPath, nameof(devDirectoryPath));
  
      _fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
      _deviceFileParser = deviceFileParser ?? throw new ArgumentNullException(nameof(deviceFileParser));
      _logger = logger.ForContext&lt;DevMonitor&gt;();
      _watcher = new FileSystemWatcherWrapper(devDirectoryPath);
  }
  </code></pre>