public void TestListener()
        {
            _entries.Add(new LogLine(0, 0, "DEBUG: This is a test", LevelFlags.Debug));
            _entries.Add(new LogLine(1, 0, "Yikes", LevelFlags.None));
            using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, Filter.Create("yikes", true, LevelFlags.All)))
            {
                var sections = new List<LogFileSection>();
                var listener = new Mock<ILogFileListener>();

                listener.Setup(x => x.OnLogFileModified(It.IsAny<ILogFile>(), It.IsAny<LogFileSection>()))
                        .Callback((ILogFile l, LogFileSection s) => sections.Add(s));
                // We deliberately set the batchSize to be greater than the amount of entries that will be matched.
                // If the FilteredLogFile is implemented correctly, then it will continously notifiy the listener until
                // the maximum wait time is elapsed.
                const int batchSize = 10;
                file.AddListener(listener.Object, TimeSpan.FromMilliseconds(100), batchSize);
                file.OnLogFileModified(_logFile.Object, new LogFileSection(0, 2));

                _taskScheduler.RunOnce();
                file.EndOfSourceReached.Should().BeTrue();

                file.Count.Should().Be(2);
                sections.Should().Equal(new[]
                    {
                        LogFileSection.Reset,
                        new LogFileSection(0, 2)
                    });
            }
        }
        public void TestWait()
        {
            using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, Filter.Create(null, true, LevelFlags.Debug)))
            {
                var sections = new List<LogFileSection>();
                var listener = new Mock<ILogFileListener>();
                listener.Setup(x => x.OnLogFileModified(It.IsAny<ILogFile>(), It.IsAny<LogFileSection>()))
                        .Callback((ILogFile logFile, LogFileSection section) => sections.Add(section));
                file.AddListener(listener.Object, TimeSpan.FromMilliseconds(100), 3);

                _entries.Add(new LogLine(0, 0, "DEBUG: This is a test", LevelFlags.Debug));
                _entries.Add(new LogLine(1, 0, "DEBUG: Yikes", LevelFlags.None));
                file.OnLogFileModified(_logFile.Object, new LogFileSection(0, 2));

                _taskScheduler.RunOnce();
                file.EndOfSourceReached.Should().BeTrue();
                sections.Should().Equal(new object[]
                    {
                        LogFileSection.Reset,
                        new LogFileSection(new LogLineIndex(0), 2)
                    });
            }
        }
        public void TestInvalidate3()
        {
            using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, Filter.Create(null, true, LevelFlags.Info)))
            {
                file.AddListener(_listener.Object, TimeSpan.Zero, 1);

                _taskScheduler.RunOnce();
                file.EndOfSourceReached.Should().BeTrue();

                _entries.AddRange(new[]
                    {
                        new LogLine(0, 0, "A", LevelFlags.Info),
                        new LogLine(1, 0, "B", LevelFlags.Info),
                        new LogLine(2, 0, "C", LevelFlags.Info),
                        new LogLine(3, 0, "D", LevelFlags.Info)
                    });
                file.OnLogFileModified(_logFile.Object, new LogFileSection(0, 4));

                _taskScheduler.RunOnce();
                file.EndOfSourceReached.Should().BeTrue();

                file.OnLogFileModified(_logFile.Object, new LogFileSection(2, 2, true));

                _taskScheduler.RunOnce();
                file.EndOfSourceReached.Should().BeTrue("Because the filtered log file should be finished");
                file.Count.Should().Be(2);

                _sections.Should().Equal(new[]
                    {
                        LogFileSection.Reset,
                        new LogFileSection(0, 1),
                        new LogFileSection(1, 1),
                        new LogFileSection(2, 1),
                        new LogFileSection(3, 1),
                        new LogFileSection(2, 2, true)
                    });
            }
        }