protected AbstractLogFile(ITaskScheduler scheduler) { if (scheduler == null) throw new ArgumentNullException("scheduler"); _scheduler = scheduler; _cancellationTokenSource = new CancellationTokenSource(); _listeners = new LogFileListenerCollection(this); }
public LogFileProxy(ITaskScheduler taskScheduler, TimeSpan maximumWaitTime) { if (taskScheduler == null) throw new ArgumentNullException("taskScheduler"); _taskScheduler = taskScheduler; _pendingSections = new ConcurrentQueue<KeyValuePair<ILogFile, LogFileSection>>(); _listeners = new LogFileListenerCollection(this); _task = _taskScheduler.StartPeriodic(RunOnce, "Log File Proxy"); _maximumWaitTime = maximumWaitTime; }
public void Setup() { _logFile = new Mock<ILogFile>(); _listeners = new LogFileListenerCollection(_logFile.Object); _logFile.Setup(x => x.AddListener(It.IsAny<ILogFileListener>(), It.IsAny<TimeSpan>(), It.IsAny<int>())) .Callback((ILogFileListener listener, TimeSpan maximumWaitTime, int maximumLineCount) => _listeners.AddListener(listener, maximumWaitTime, maximumLineCount)); _logFile.Setup(x => x.RemoveListener(It.IsAny<ILogFileListener>())) .Callback((ILogFileListener listener) => _listeners.RemoveListener(listener)); _listener = new Mock<ILogFileListener>(); _modifications = new List<LogFileSection>(); _listener.Setup(x => x.OnLogFileModified(It.IsAny<ILogFile>(), It.IsAny<LogFileSection>())) .Callback((ILogFile logFile, LogFileSection section) => _modifications.Add(section)); }
public void Setup() { _entries = new List<LogLine>(); _logFile = new Mock<ILogFile>(); _listeners = new LogFileListenerCollection(_logFile.Object); _logFile.Setup(x => x.EndOfSourceReached).Returns(true); _logFile.Setup(x => x.GetSection(It.IsAny<LogFileSection>(), It.IsAny<LogLine[]>())) .Callback( (LogFileSection section, LogLine[] entries) => _entries.CopyTo((int)section.Index, entries, 0, section.Count)); _logFile.Setup(x => x.AddListener(It.IsAny<ILogFileListener>(), It.IsAny<TimeSpan>(), It.IsAny<int>())) .Callback((ILogFileListener listener, TimeSpan maximumWaitTime, int maximumLineCount) => _listeners.AddListener(listener, maximumWaitTime, maximumLineCount)); _logFile.Setup(x => x.RemoveListener(It.IsAny<ILogFileListener>())) .Callback((ILogFileListener listener) => _listeners.RemoveListener(listener)); _logFile.Setup(x => x.GetLine(It.IsAny<int>())).Returns((int index) => _entries[index]); _logFile.Setup(x => x.Count).Returns(() => _entries.Count); }
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)).ShouldNotThrow(); 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 TestFlush2() { 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); collection.Flush(); collection.Flush(); sections.Should().Equal(new object[] { LogFileSection.Reset, new LogFileSection(0, 1) }, "Because Flush() shouldn't forward the same result to the same listener more than once"); }
public void TestFlush3() { 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); collection.Flush(); collection.OnRead(2); collection.Flush(); sections.Should().Equal(new object[] { LogFileSection.Reset, new LogFileSection(0, 1), new LogFileSection(1, 1) }); }
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); }