Esempio n. 1
0
        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");
        }
Esempio n. 2
0
        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");
        }
Esempio n. 3
0
        private static IDataSource GetInnerDataSource(FolderDataSource folderDataSource)
        {
            var inner = (IDataSource)folderDataSource.GetType().GetField("_mergedDataSource", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(folderDataSource);

            inner.Should().NotBeNull();
            return(inner);
        }
Esempio n. 4
0
        public void TestNoSuchDrive()
        {
            var dataSource = new FolderDataSource(_taskScheduler,
                                                  _logFileFactory,
                                                  _filesystem,
                                                  _settings,
                                                  TimeSpan.Zero);

            var path = Path.Combine("Z:\\", "logs");

            dataSource.Change(path, "*", false);

            dataSource.OriginalSources.Should().BeEmpty();
        }
Esempio n. 5
0
        public void TestNoSuchFolder()
        {
            var dataSource = new FolderDataSource(_taskScheduler,
                                                  _logFileFactory,
                                                  _filesystem,
                                                  _settings,
                                                  TimeSpan.Zero);
            var path = Path.Combine(_filesystem.Roots.First().FullName, "logs");

            dataSource.Change(path, "*", false);

            _taskScheduler.RunOnce();
            dataSource.OriginalSources.Should().BeEmpty();
        }
Esempio n. 6
0
        public void TestClearAllShowAll()
        {
            var folderDataSource = new FolderDataSource(_taskScheduler,
                                                        _logFileFactory,
                                                        _filesystem,
                                                        _settings,
                                                        TimeSpan.Zero);
            var merged = GetInnerDataSource(folderDataSource);

            folderDataSource.ScreenCleared.Should().BeFalse();
            folderDataSource.ClearScreen();
            folderDataSource.ScreenCleared.Should().BeTrue();
            merged.ScreenCleared.Should().BeTrue();

            folderDataSource.ShowAll();
            folderDataSource.ScreenCleared.Should().BeFalse();
            merged.ScreenCleared.Should().BeFalse();
        }
Esempio n. 7
0
        public void TestChange([Values(null, "", @"C:\temp")] string folderPath,
                               [Values(null, "", "*.log")] string logFileRegex,
                               [Values(true, false)] bool recursive)
        {
            var dataSource = new FolderDataSource(_taskScheduler,
                                                  _logFileFactory,
                                                  _filesystem,
                                                  _settings,
                                                  TimeSpan.Zero);

            dataSource.Change(folderPath, logFileRegex, recursive);
            dataSource.LogFileFolderPath.Should().Be(folderPath);
            dataSource.LogFileSearchPattern.Should().Be(logFileRegex);
            dataSource.Recursive.Should().Be(recursive);

            _settings.LogFileFolderPath.Should().Be(folderPath);
            _settings.LogFileSearchPattern.Should().Be(logFileRegex);
            _settings.Recursive.Should().Be(recursive);
        }
Esempio n. 8
0
        public void TestChangeLevelFilter()
        {
            var dataSource = new FolderDataSource(_taskScheduler,
                                                  _logFileFactory,
                                                  _filesystem,
                                                  _settings,
                                                  TimeSpan.Zero);

            var unfiltered = dataSource.UnfilteredLogFile;
            var filtered   = dataSource.FilteredLogFile;

            dataSource.LevelFilter = LevelFlags.Error;
            dataSource.UnfilteredLogFile.Should().BeSameAs(unfiltered);
            dataSource.FilteredLogFile.Should().BeSameAs(filtered);

            dataSource.LevelFilter = LevelFlags.All;
            dataSource.UnfilteredLogFile.Should().BeSameAs(unfiltered);
            dataSource.FilteredLogFile.Should().BeSameAs(filtered);
        }
Esempio n. 9
0
        public void TestChangeSingleLine()
        {
            var dataSource = new FolderDataSource(_taskScheduler,
                                                  _logFileFactory,
                                                  _filesystem,
                                                  _settings,
                                                  TimeSpan.Zero);

            var unfiltered = dataSource.UnfilteredLogFile;
            var filtered   = dataSource.FilteredLogFile;

            dataSource.IsSingleLine = !dataSource.IsSingleLine;
            dataSource.UnfilteredLogFile.Should().BeSameAs(unfiltered);
            dataSource.FilteredLogFile.Should().BeSameAs(filtered);

            dataSource.IsSingleLine = !dataSource.IsSingleLine;
            dataSource.UnfilteredLogFile.Should().BeSameAs(unfiltered);
            dataSource.FilteredLogFile.Should().BeSameAs(filtered);
        }
Esempio n. 10
0
        public void TestChangeFilter()
        {
            var dataSource = new FolderDataSource(_taskScheduler,
                                                  _logFileFactory,
                                                  _filesystem,
                                                  _settings,
                                                  TimeSpan.Zero);

            var unfiltered = dataSource.UnfilteredLogFile;
            var filtered   = dataSource.FilteredLogFile;

            dataSource.QuickFilterChain = new List <ILogEntryFilter>();
            dataSource.UnfilteredLogFile.Should().BeSameAs(unfiltered);
            dataSource.FilteredLogFile.Should().BeSameAs(filtered);

            dataSource.QuickFilterChain = null;
            dataSource.UnfilteredLogFile.Should().BeSameAs(unfiltered);
            dataSource.FilteredLogFile.Should().BeSameAs(filtered);
        }
Esempio n. 11
0
        public void TestMultiplePatterns()
        {
            var dataSource = new FolderDataSource(_taskScheduler,
                                                  _logFileFactory,
                                                  _filesystem,
                                                  _settings,
                                                  TimeSpan.Zero);

            var path = Path.Combine(_filesystem.Roots.First().FullName, "logs");

            _filesystem.CreateDirectory(path);
            _filesystem.WriteAllBytes(Path.Combine(path, "foo.log"), new byte[0]);
            _filesystem.WriteAllBytes(Path.Combine(path, "foo.bar"), new byte[0]);
            _filesystem.WriteAllBytes(Path.Combine(path, "foo.txt"), new byte[0]);

            dataSource.Change(path, "*.log;*.txt", false);
            _taskScheduler.RunOnce();

            dataSource.Property(x => (IEnumerable <IDataSource>)x.OriginalSources).ShouldEventually().HaveCount(2);
            dataSource.OriginalSources[0].FullFileName.Should().Be(Path.Combine(path, "foo.log"));
            dataSource.OriginalSources[1].FullFileName.Should().Be(Path.Combine(path, "foo.txt"));
        }
Esempio n. 12
0
        public void TestTooManySources()
        {
            var dataSource = new FolderDataSource(_taskScheduler,
                                                  _logFileFactory,
                                                  _filesystem,
                                                  _settings,
                                                  TimeSpan.Zero);

            var path = Path.Combine(_filesystem.Roots.First().FullName, "logs");

            _filesystem.CreateDirectory(path);
            for (int i = 0; i < 257; ++i)
            {
                _filesystem.WriteAllBytes(Path.Combine(path, $"{i}.txt"), new byte[0]);
            }

            dataSource.Change(path, "*.log;*.txt", false);
            _taskScheduler.RunOnce();

            dataSource.Property(x => (IEnumerable <IDataSource>)x.OriginalSources).ShouldEventually().HaveCount(255,
                                                                                                                "because merged log file cannot merge more than 256 logs");
            dataSource.UnfilteredFileCount.Should().Be(257);
            dataSource.FilteredFileCount.Should().Be(257);
        }