public void TestFlush1() { var collection = new LogFileListenerCollection(new Mock <ILogFile>().Object); var listener = new Mock <ILogFileListener>(); var sections = new List <LogFileSection>(); listener.Setup(x => x.OnLogFileModified(It.IsAny <ILogFile>(), It.IsAny <LogFileSection>())) .Callback((ILogFile file, LogFileSection y) => sections.Add(y)); collection.AddListener(listener.Object, TimeSpan.FromHours(1), 1000); collection.OnRead(1); sections.Should().Equal(new object[] { LogFileSection.Reset }); collection.Flush(); sections.Should().Equal(new object[] { LogFileSection.Reset, new LogFileSection(0, 1) }, "Because Flush() should force calling the OnLogFileModified method"); }
private void AddEntry(string message) { var index = _entries.Count; var entry = new LogLine(index, index, message, LevelFlags.Other); _entries.Add(entry); _listeners.OnRead(_entries.Count); }
public void TestInvalidate() { var collection = new LogFileListenerCollection(new Mock <ILogFile>().Object); collection.OnRead(1); collection.CurrentLineIndex.Should().Be(1); collection.Invalidate(0, 1); collection.CurrentLineIndex.Should().Be(0); }
public void TestSearch1() { using (var dataSource = new SingleDataSource(_scheduler, CreateDataSource(), _logFile.Object, TimeSpan.Zero)) { _entries.Add(new LogLine(0, 0, "Hello foobar world!", LevelFlags.None)); _listeners.OnRead(1); _scheduler.RunOnce(); dataSource.SearchTerm = "foobar"; _scheduler.Run(10); dataSource.Search.Count.Should().Be(1); var matches = dataSource.Search.Matches.ToList(); matches.Should().Equal(new LogMatch(0, new LogLineMatch(6, 6))); } }
public void TestAddListener1() { ILogFile logFile = new Mock <ILogFile>().Object; var collection = new LogFileListenerCollection(logFile); var listener = new Mock <ILogFileListener>(); var sections = new List <LogFileSection>(); listener.Setup(x => x.OnLogFileModified(It.IsAny <ILogFile>(), It.IsAny <LogFileSection>())) .Callback((ILogFile file, LogFileSection y) => sections.Add(y)); collection.AddListener(listener.Object, TimeSpan.FromSeconds(1), 10); new Action(() => collection.AddListener(listener.Object, TimeSpan.FromSeconds(1), 10)).Should().NotThrow(); collection.OnRead(10); sections.Should().Equal(new[] { LogFileSection.Reset, new LogFileSection(0, 10) }, "Because even though we added the listener twice, it should never be invoked twice"); }
public void TestListen1() { using (var proxy = new LogFileProxy(_scheduler, TimeSpan.Zero, _logFile.Object)) { proxy.AddListener(_listener.Object, TimeSpan.Zero, 1000); _listeners.OnRead(500); _listeners.OnRead(600); _scheduler.RunOnce(); _modifications.Should().Equal(new[] { LogFileSection.Reset, new LogFileSection(0, 500), new LogFileSection(500, 100) }); } }