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); }