コード例 #1
0
        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");
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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));
        }
コード例 #4
0
 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);
 }
コード例 #5
0
        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");
        }