public void TestCurrentLineChanged1() { var notifier = new LogFileListenerNotifier(_logFile.Object, _listener.Object, TimeSpan.Zero, 1); notifier.OnRead(1); notifier.OnRead(2); notifier.OnRead(3); notifier.OnRead(4); _changes.Should().Equal(new[] { LogFileSection.Reset, new LogFileSection(0, 1), new LogFileSection(1, 1), new LogFileSection(2, 1), new LogFileSection(3, 1) }); }
public void TestCurrentLineChanged2() { var notifier = new LogFileListenerNotifier(_logFile.Object, _listener.Object, TimeSpan.FromHours(1), 4); _changes.Clear(); notifier.OnRead(1); _changes.Should().BeEmpty(); notifier.OnRead(2); _changes.Should().BeEmpty(); notifier.OnRead(3); _changes.Should().BeEmpty(); notifier.OnRead(4); _changes.Should().Equal(new[] { new LogFileSection(0, 4) }); }
public void TestCurrentLineChanged3() { var notifier = new LogFileListenerNotifier(_logFile.Object, _listener.Object, TimeSpan.FromHours(1), 4); notifier.OnRead(4); _changes.Should().Equal(new[] { LogFileSection.Reset, new LogFileSection(0, 4) }); }
public void AddListener(ILogFileListener listener, TimeSpan maximumWaitTime, int maximumLineCount) { lock (_listeners) { if (!_listeners.ContainsKey(listener)) { var notifier = new LogFileListenerNotifier(_logFile, listener, maximumWaitTime, maximumLineCount); _listeners.Add(listener, notifier); notifier.OnRead(_currentLineIndex); } } }
public void TestInvalidate5() { var notifier = new LogFileListenerNotifier(_logFile.Object, _listener.Object, TimeSpan.FromMilliseconds(100), 100); notifier.OnRead(1); notifier.OnRead(-1); _changes.Should().Equal(new[] {LogFileSection.Reset}); notifier.OnRead(-1); _changes.Should().Equal(new[] {LogFileSection.Reset}); notifier.OnRead(-1); _changes.Should().Equal(new[] {LogFileSection.Reset}); }
public void TestInvalidate4() { var notifier = new LogFileListenerNotifier(_logFile.Object, _listener.Object, TimeSpan.FromMilliseconds(100), 100); notifier.OnRead(9); Thread.Sleep(TimeSpan.FromMilliseconds(1000)); notifier.OnRead(9); _changes.Should().Equal(new[] { LogFileSection.Reset, new LogFileSection(0, 9) }); notifier.OnRead(35); notifier.Invalidate(10, 25); _changes.Should().Equal(new[] { LogFileSection.Reset, new LogFileSection(0, 9) }, "Because the notifier should've reported only the first 10 changes and therefore Invalidate() only had to invalidate those 10 changes" ); notifier.LastNumberOfLines.Should().Be(9); }
public void TestInvalidate3() { var notifier = new LogFileListenerNotifier(_logFile.Object, _listener.Object, TimeSpan.FromSeconds(1), 10); notifier.OnRead(10); notifier.OnRead(20); notifier.OnRead(22); notifier.Invalidate(0, 22); _changes.Should().Equal(new[] { LogFileSection.Reset, new LogFileSection(0, 10), new LogFileSection(10, 10), new LogFileSection(0, 20, true) }, "Because the notifier should've reported only the first 10 changes and therefore Invalidate() only had to invalidate those 10 changes" ); notifier.LastNumberOfLines.Should().Be(0); }
public void TestInvalidate1() { var notifier = new LogFileListenerNotifier(_logFile.Object, _listener.Object, TimeSpan.Zero, 1); notifier.OnRead(1); notifier.Invalidate(0, 1); _changes.Should().Equal(new[] { LogFileSection.Reset, new LogFileSection(0, 1), new LogFileSection(0, 1, true) }); notifier.LastNumberOfLines.Should().Be(0); }