public void TestDisposeChildDataSources() { var path = Path.Combine(_filesystem.Roots.First().FullName, "logs"); _settings.LogFileFolderPath = path; _settings.LogFileSearchPattern = "*.log"; var folderDataSource = new FolderDataSource(_taskScheduler, _logFileFactory, _filesystem, _settings, TimeSpan.Zero); _filesystem.CreateDirectory(path); _filesystem.WriteAllBytes(Path.Combine(path, "foo.log"), new byte[0]); _taskScheduler.RunOnce(); var children = folderDataSource.OriginalSources; children.Should().HaveCount(1); var childDataSource = children[0]; childDataSource.IsDisposed.Should().BeFalse(); folderDataSource.Dispose(); childDataSource.IsDisposed.Should().BeTrue("because the folder data source should dispose of its children upon being disposed of itself"); }
public void TestDisposeFilesystemWatcher() { var filesystem = new Mock <IFilesystem>(); var watchdog = new Mock <IFilesystemWatchdog>(); var watchers = new List <Mock <IFilesystemWatcher> >(); watchdog.Setup(x => x.StartDirectoryWatch(It.IsAny <string>(), It.IsAny <TimeSpan>(), It.IsAny <string>(), It.IsAny <SearchOption>())) .Returns(() => { var watcher = new Mock <IFilesystemWatcher>(); watchers.Add(watcher); return(watcher.Object); }); filesystem.Setup(x => x.Watchdog).Returns(watchdog.Object); var dataSource = new FolderDataSource(_taskScheduler, _logFileFactory, filesystem.Object, _settings, TimeSpan.Zero); watchers.Should().HaveCount(1, "because the data source should've created one filesystem watcher"); dataSource.Dispose(); watchers.Should().HaveCount(1, "because the data source should not have created anymore watchers"); watchers[0].Verify(x => x.Dispose(), Times.Once, "because the data source should've disposed of the watcher"); }