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 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 Setup2() { _scheduler = new ManualTaskScheduler(); _source = new Mock <ILogSource>(); _listeners = new LogSourceListenerCollection(_source.Object); _sourceEntries = new LogBufferList(Core.Columns.Index, Core.Columns.LogLevel, Core.Columns.Timestamp); _sourceProperties = new PropertiesBufferList(); _source.Setup(x => x.GetAllProperties(It.IsAny <IPropertiesBuffer>())) .Callback((IPropertiesBuffer destination) => _sourceProperties.CopyAllValuesTo(destination)); _source.Setup(x => x.GetProperty(It.IsAny <IPropertyDescriptor>())) .Returns((IPropertyDescriptor property) => _sourceProperties.GetValue(property)); _source.Setup(x => x.Columns).Returns(() => _sourceEntries.Columns); _source.Setup(x => x.AddListener(It.IsAny <ILogSourceListener>(), It.IsAny <TimeSpan>(), It.IsAny <int>())) .Callback((ILogSourceListener listener, TimeSpan maximumWaitTime, int maximumLineCount) => { _listeners.AddListener(listener, maximumWaitTime, maximumLineCount); }); _source.Setup(x => x.RemoveListener(It.IsAny <ILogSourceListener>())) .Callback((ILogSourceListener listener) => { _listeners.RemoveListener(listener); }); _source.Setup(x => x.GetEntries(It.IsAny <IReadOnlyList <LogLineIndex> >(), It.IsAny <ILogBuffer>(), It.IsAny <int>(), It.IsAny <LogSourceQueryOptions>())) .Callback((IReadOnlyList <LogLineIndex> sourceIndices, ILogBuffer destination, int destinationIndex, LogSourceQueryOptions queryOptions) => { _sourceEntries.CopyTo(new Int32View(sourceIndices), destination, destinationIndex); }); }
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 Setup() { _taskScheduler = new ManualTaskScheduler(); _logFile = new Mock <ILogSource>(); _listeners = new LogSourceListenerCollection(_logFile.Object); _logFile.Setup(x => x.AddListener(It.IsAny <ILogSourceListener>(), It.IsAny <TimeSpan>(), It.IsAny <int>())) .Callback((ILogSourceListener listener, TimeSpan maximumWaitTime, int maximumLineCount) => _listeners.AddListener(listener, maximumWaitTime, maximumLineCount)); _logFile.Setup(x => x.RemoveListener(It.IsAny <ILogSourceListener>())) .Callback((ILogSourceListener listener) => _listeners.RemoveListener(listener)); _listener = new Mock <ILogSourceListener>(); _modifications = new List <LogSourceModification>(); _listener.Setup(x => x.OnLogFileModified(It.IsAny <ILogSource>(), It.IsAny <LogSourceModification>())) .Callback((ILogSource logFile, LogSourceModification modification) => _modifications.Add(modification)); }