public void TestClear() { var collection = new LogSourceListenerCollection(new Mock <ILogSource>().Object); var listener = new Mock <ILogSourceListener>(); var modifications = new List <LogSourceModification>(); listener.Setup(x => x.OnLogFileModified(It.IsAny <ILogSource>(), It.IsAny <LogSourceModification>())) .Callback((ILogSource file, LogSourceModification y) => modifications.Add(y)); collection.AddListener(listener.Object, TimeSpan.FromHours(1), 1000); collection.OnRead(1); collection.Flush(); modifications.Should().Equal(new object[] { LogSourceModification.Reset(), LogSourceModification.Appended(0, 1), }); collection.Clear(); modifications.Clear(); collection.OnRead(2); collection.Flush(); modifications.Should() .BeEmpty("because the collection should have removed all listeners and thus we may not have been notified anymore"); }
public void TestFlush1() { var collection = new LogSourceListenerCollection(new Mock <ILogSource>().Object); var listener = new Mock <ILogSourceListener>(); var modifications = new List <LogSourceModification>(); listener.Setup(x => x.OnLogFileModified(It.IsAny <ILogSource>(), It.IsAny <LogSourceModification>())) .Callback((ILogSource file, LogSourceModification y) => modifications.Add(y)); collection.AddListener(listener.Object, TimeSpan.FromHours(1), 1000); collection.OnRead(1); modifications.Should().Equal(new object[] { LogSourceModification.Reset() }); collection.Flush(); modifications.Should().Equal(new object[] { LogSourceModification.Reset(), LogSourceModification.Appended(0, 1) }, "Because Flush() should force calling the OnLogFileModified method"); }
public void TestInvalidate() { var collection = new LogSourceListenerCollection(new Mock <ILogSource>().Object); collection.OnRead(1); collection.CurrentLineIndex.Should().Be(1); collection.Remove(0, 1); collection.CurrentLineIndex.Should().Be(0); }
public void TestAddListener1() { ILogSource logSource = new Mock <ILogSource>().Object; var collection = new LogSourceListenerCollection(logSource); var listener = new Mock <ILogSourceListener>(); var modifications = new List <LogSourceModification>(); listener.Setup(x => x.OnLogFileModified(It.IsAny <ILogSource>(), It.IsAny <LogSourceModification>())) .Callback((ILogSource file, LogSourceModification y) => modifications.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); modifications.Should().Equal(new[] { LogSourceModification.Reset(), LogSourceModification.Appended(0, 10) }, "Because even though we added the listener twice, it should never be invoked twice"); }
public void TestListen1() { using (var proxy = new LogSourceProxy(_taskScheduler, TimeSpan.Zero, _logFile.Object, 1000)) { proxy.AddListener(_listener.Object, TimeSpan.Zero, 1000); _listeners.OnRead(500); _listeners.OnRead(600); _taskScheduler.RunOnce(); _modifications.Should().Equal(new[] { LogSourceModification.Reset(), LogSourceModification.Appended(0, 500), LogSourceModification.Appended(500, 100) }); } }
public void TestGetPartiallyAdornedProperties() { var adorner = new LogSourcePropertyAdorner(_scheduler, _source.Object, TimeSpan.Zero); _sourceEntries.Add(new LogEntry { Index = 0, Timestamp = new DateTime(2021, 02, 20, 18, 31, 45) }); _listeners.OnRead(_sourceEntries.Count); _sourceProperties.SetValue(TextProperties.Encoding, Encoding.UTF32); _scheduler.RunOnce(); var buffer = new PropertiesBufferList(); adorner.GetAllProperties(buffer); buffer.GetValue(Core.Properties.StartTimestamp).Should().Be(new DateTime(2021, 02, 20, 18, 31, 45)); buffer.GetValue(Core.Properties.EndTimestamp).Should().Be(new DateTime(2021, 02, 20, 18, 31, 45)); buffer.GetValue(TextProperties.Encoding).Should().Be(Encoding.UTF32, "because those properties which are not adorned should have been retrieved from the source"); }