public void TestClear2() { const string fname = "TestClear2.log"; using (FileStream stream = File.OpenWrite(fname)) using (var writer = new StreamWriter(stream)) { stream.SetLength(0); writer.WriteLine("Test"); } using (var logFile = new LogFile(_scheduler, fname)) { var listener = new Mock<ILogFileListener>(); var sections = new List<LogFileSection>(); listener.Setup(x => x.OnLogFileModified(It.IsAny<ILogFile>(), It.IsAny<LogFileSection>())) .Callback((ILogFile log, LogFileSection section) => sections.Add(section)); logFile.AddListener(listener.Object, TimeSpan.Zero, 2); logFile.Property(x => x.Count).ShouldEventually().Be(1, TimeSpan.FromSeconds(5)); using (var stream = new FileStream(fname, FileMode.Open, FileAccess.Write, FileShare.ReadWrite)) { stream.SetLength(0); logFile.Property(x => x.Count).ShouldEventually().Be(0, TimeSpan.FromSeconds(5)); sections.Should().EndWith(LogFileSection.Reset); } } }
public void TestRead2LogEntries() { using (var file = new LogFile(_scheduler, File2Entries)) { var listener = new Mock<ILogFileListener>(); var changes = new List<LogFileSection>(); listener.Setup(x => x.OnLogFileModified(It.IsAny<ILogFile>(), It.IsAny<LogFileSection>())) .Callback((ILogFile logFile, LogFileSection section) => changes.Add(section)); file.AddListener(listener.Object, TimeSpan.Zero, 1); changes.Property(x => x.Count).ShouldEventually().Be(7, TimeSpan.FromSeconds(5)); changes.Should().Equal(new[] { LogFileSection.Reset, new LogFileSection(0, 1), new LogFileSection(1, 1), new LogFileSection(2, 1), new LogFileSection(3, 1), new LogFileSection(4, 1), new LogFileSection(5, 1) }); file.StartTimestamp.Should().Be(new DateTime(2015, 10, 7, 19, 50, 58, 982)); LogLine[] lines = file.GetSection(new LogFileSection(0, 6)); lines.Should().Equal(new[] { new LogLine(0, 0, "2015-10-07 19:50:58,982 [8092, 1] INFO SharpRemote.Hosting.OutOfProcessSiloServer (null) - Silo Server starting, args (1): \"14056\", without custom type resolver", LevelFlags.Info, new DateTime(2015, 10, 7, 19, 50, 58, 982)), new LogLine(1, 0, "Foobar", LevelFlags.Info, new DateTime(2015, 10, 7, 19, 50, 58, 982)), new LogLine(2, 0, "Some more info", LevelFlags.Info, new DateTime(2015, 10, 7, 19, 50, 58, 982)), new LogLine(3, 1, "2015-10-07 19:50:58,998 [8092, 1] DEBUG SharpRemote.Hosting.OutOfProcessSiloServer (null) - Args.Length: 1", LevelFlags.Debug, new DateTime(2015, 10, 7, 19, 50, 58, 998)), new LogLine(4, 1, "Hey look at me", LevelFlags.Debug, new DateTime(2015, 10, 7, 19, 50, 58, 998)), new LogLine(5, 1, "dwadawdadw", LevelFlags.Debug, new DateTime(2015, 10, 7, 19, 50, 58, 998)) }); } }
public void TestReadAll2() { using (var file = new LogFile(_scheduler, File20Mb)) { var listener = new Mock<ILogFileListener>(); var sections = new List<LogFileSection>(); listener.Setup(x => x.OnLogFileModified(It.IsAny<ILogFile>(), It.IsAny<LogFileSection>())) .Callback((ILogFile logFile, LogFileSection section) => sections.Add(section)); file.AddListener(listener.Object, TimeSpan.Zero, 1); file.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue(TimeSpan.FromSeconds(20)); file.Count.Should().Be(165342); sections[0].Should().Be(LogFileSection.Reset); for (int i = 1; i < sections.Count; ++i) { LogFileSection change = sections[i]; change.Index.Should().Be((LogLineIndex) (i - 1)); change.Count.Should().Be(1); } } }
public void TestRead2Lines() { using (var file = new LogFile(_scheduler, File2Lines)) { var listener = new Mock<ILogFileListener>(); var changes = new List<LogFileSection>(); listener.Setup(x => x.OnLogFileModified(It.IsAny<ILogFile>(), It.IsAny<LogFileSection>())) .Callback((ILogFile logFile, LogFileSection section) => changes.Add(section)); file.AddListener(listener.Object, TimeSpan.Zero, 1); changes.Property(x => x.Count).ShouldEventually().Be(3, TimeSpan.FromSeconds(5)); changes.Should().Equal(new[] { LogFileSection.Reset, new LogFileSection(0, 1), new LogFileSection(1, 1) }); } }