Example #1
0
        public void TestPercentageProcessed()
        {
            var source           = new Mock <ILogSource>();
            var sourceProperties = new PropertiesBufferList();

            sourceProperties.SetValue(Core.Properties.PercentageProcessed, Percentage.Zero);
            source.Setup(x => x.Columns).Returns(Core.Columns.Minimum);
            source.Setup(x => x.GetAllProperties(It.IsAny <IPropertiesBuffer>()))
            .Callback((IPropertiesBuffer destination) => sourceProperties.CopyAllValuesTo(destination));
            source.Setup(x => x.GetProperty(Core.Properties.PercentageProcessed))
            .Returns(() => sourceProperties.GetValue(Core.Properties.PercentageProcessed));
            source.Setup(x => x.Properties).Returns(() => sourceProperties.Properties);

            using (var file = Create(source.Object))
            {
                var fileListener = (ILogSourceListener)file;

                file.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.Zero, "because the filtered log file hasn't consumed anything of its source (yet)");

                _taskScheduler.RunOnce();
                file.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.Zero, "because even though the filter doesn't have anything to do just yet - it's because its own source hasn't even started");

                sourceProperties.SetValue(Core.Properties.PercentageProcessed, Percentage.FromPercent(42));
                fileListener.OnLogFileModified(source.Object, LogSourceModification.Appended(0, 84));
                _taskScheduler.RunOnce();
                file.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.FromPercent(42), "because now the filtered log file has processed 100% of the data the source sent it, but the original data source is still only at 42%");

                sourceProperties.SetValue(Core.Properties.PercentageProcessed, Percentage.HundredPercent);
                fileListener.OnLogFileModified(source.Object, LogSourceModification.Appended(84, 200));
                _taskScheduler.RunOnce();
                file.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.HundredPercent);
            }
        }
Example #2
0
        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);
            });
        }