Exemple #1
0
        public void TestTwoEntriesDescendingTimestamp()
        {
            var adorner = new LogSourcePropertyAdorner(_scheduler, _source.Object, TimeSpan.Zero);

            _sourceEntries.Add(new LogEntry
            {
                Index     = 0,
                Timestamp = new DateTime(2021, 02, 20, 18, 03, 37)
            });
            _listeners.OnRead(_sourceEntries.Count);
            _scheduler.RunOnce();

            adorner.GetProperty(Core.Properties.StartTimestamp).Should().Be(new DateTime(2021, 02, 20, 18, 03, 37));
            adorner.GetProperty(Core.Properties.EndTimestamp).Should().Be(new DateTime(2021, 02, 20, 18, 03, 37));
            adorner.GetProperty(Core.Properties.Duration).Should().Be(TimeSpan.Zero);

            _sourceEntries.Add(new LogEntry
            {
                Index     = 1,
                Timestamp = new DateTime(2021, 02, 20, 18, 02, 12)
            });
            _listeners.OnRead(_sourceEntries.Count);
            _scheduler.RunOnce();

            adorner.GetProperty(Core.Properties.StartTimestamp).Should().Be(new DateTime(2021, 02, 20, 18, 02, 12));
            adorner.GetProperty(Core.Properties.EndTimestamp).Should().Be(new DateTime(2021, 02, 20, 18, 03, 37));
            adorner.GetProperty(Core.Properties.Duration).Should().Be(TimeSpan.FromSeconds(85));

            var buffer = new PropertiesBufferList(Core.Properties.StartTimestamp, Core.Properties.EndTimestamp);

            adorner.GetAllProperties(buffer);
            buffer.GetValue(Core.Properties.StartTimestamp).Should().Be(new DateTime(2021, 02, 20, 18, 02, 12));
            buffer.GetValue(Core.Properties.EndTimestamp).Should().Be(new DateTime(2021, 02, 20, 18, 03, 37));
            buffer.GetValue(Core.Properties.Duration).Should().Be(TimeSpan.FromSeconds(85));
        }
Exemple #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);
            });
        }
Exemple #3
0
        public void TestOneEntryTimestampReset()
        {
            var adorner = new LogSourcePropertyAdorner(_scheduler, _source.Object, TimeSpan.Zero);

            _sourceEntries.Add(new LogEntry
            {
                Index     = 0,
                Timestamp = new DateTime(2021, 02, 20, 17, 52, 31)
            });
            _listeners.OnRead(_sourceEntries.Count);
            _scheduler.RunOnce();

            adorner.GetProperty(Core.Properties.StartTimestamp).Should().Be(new DateTime(2021, 02, 20, 17, 52, 31));
            adorner.GetProperty(Core.Properties.EndTimestamp).Should().Be(new DateTime(2021, 02, 20, 17, 52, 31));
            adorner.GetProperty(Core.Properties.Duration).Should().Be(TimeSpan.Zero);

            var buffer = new PropertiesBufferList(Core.Properties.StartTimestamp, Core.Properties.EndTimestamp);

            adorner.GetAllProperties(buffer);
            buffer.GetValue(Core.Properties.StartTimestamp).Should().Be(new DateTime(2021, 02, 20, 17, 52, 31));
            buffer.GetValue(Core.Properties.EndTimestamp).Should().Be(new DateTime(2021, 02, 20, 17, 52, 31));
            buffer.GetValue(Core.Properties.Duration).Should().Be(TimeSpan.Zero);

            _sourceEntries.Clear();
            _listeners.Reset();
            _scheduler.RunOnce();
            adorner.GetProperty(Core.Properties.StartTimestamp).Should().BeNull();
            adorner.GetProperty(Core.Properties.EndTimestamp).Should().BeNull();
            adorner.GetProperty(Core.Properties.Duration).Should().BeNull();

            adorner.GetAllProperties(buffer);
            buffer.GetValue(Core.Properties.StartTimestamp).Should().BeNull();
            buffer.GetValue(Core.Properties.EndTimestamp).Should().BeNull();
            buffer.GetValue(Core.Properties.Duration).Should().BeNull();
        }
Exemple #4
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);
            }
        }
        public void TestCopyAllValuesTo4()
        {
            var properties = Create(new KeyValuePair <IReadOnlyPropertyDescriptor, object>(Core.Properties.Created, new DateTime(2017, 12, 29, 13, 1, 0)),
                                    new KeyValuePair <IReadOnlyPropertyDescriptor, object>(Core.Properties.StartTimestamp, new DateTime(2017, 12, 29, 13, 3, 0)));

            var buffer = new PropertiesBufferList(Core.Properties.StartTimestamp);

            properties.CopyAllValuesTo(buffer);
            buffer.GetValue(Core.Properties.StartTimestamp).Should().Be(new DateTime(2017, 12, 29, 13, 3, 0));
        }
Exemple #6
0
        protected override IPropertiesBuffer Create(params KeyValuePair <IReadOnlyPropertyDescriptor, object>[] properties)
        {
            var list = new PropertiesBufferList(properties.Select(x => x.Key).ToArray());

            foreach (var pair in properties)
            {
                list.SetValue(pair.Key, pair.Value);
            }

            return(list);
        }
Exemple #7
0
        public void TestSetToDefaultPartial()
        {
            var properties             = new PropertiesBufferList();
            var sourceCannotBeAccessed = new SourceDoesNotExist("wdawdwaw.txt");

            properties.SetValue(Core.Properties.EmptyReason, sourceCannotBeAccessed);
            properties.SetValue(Core.Properties.PercentageProcessed, Percentage.Of(50, 100));

            properties.SetToDefault(new [] { Core.Properties.PercentageProcessed });
            properties.GetValue(Core.Properties.EmptyReason).Should().Be(sourceCannotBeAccessed, "because only the PercentageProcessed property may have been reset");
            properties.GetValue(Core.Properties.PercentageProcessed).Should().Be(Core.Properties.PercentageProcessed.DefaultValue);
        }
Exemple #8
0
        public void TestSetToDefault()
        {
            var properties             = new PropertiesBufferList();
            var sourceCannotBeAccessed = new SourceDoesNotExist("wdawdwaw.txt");

            properties.SetValue(Core.Properties.EmptyReason, sourceCannotBeAccessed);
            properties.SetValue(Core.Properties.PercentageProcessed, Percentage.Of(50, 100));

            properties.SetToDefault();
            properties.GetValue(Core.Properties.EmptyReason).Should().Be(Core.Properties.EmptyReason.DefaultValue);
            properties.GetValue(Core.Properties.PercentageProcessed).Should().Be(Percentage.Zero);
        }
Exemple #9
0
        public void TestSetToDefaultNull()
        {
            var properties             = new PropertiesBufferList();
            var sourceCannotBeAccessed = new SourceDoesNotExist("wdawdwaw.txt");

            properties.SetValue(Core.Properties.EmptyReason, sourceCannotBeAccessed);
            properties.SetValue(Core.Properties.PercentageProcessed, Percentage.Of(50, 100));

            new Action(() => properties.SetToDefault(null)).Should().Throw <ArgumentNullException>();
            properties.GetValue(Core.Properties.EmptyReason).Should().Be(sourceCannotBeAccessed);
            properties.GetValue(Core.Properties.PercentageProcessed).Should().Be(Percentage.Of(50, 100));
        }
Exemple #10
0
 public PropertiesSidePanelViewModel(IServiceContainer serviceContainer)
 {
     Tooltip               = "Show properties of the current log file";
     _propertyValues       = new PropertiesBufferList();
     _presentersByProperty = new Dictionary <IReadOnlyPropertyDescriptor, IPropertyPresenter>();
     _presenters           = new ObservableCollection <IPropertyPresenter>();
     _registry             = serviceContainer.TryRetrieve <IPropertyPresenterPlugin>();
     if (_registry == null)
     {
         Log.WarnFormat("Registry is missing: No properties will be displayed...");
     }
 }
Exemple #11
0
        public void TestConstruction()
        {
            var adorner = new LogSourcePropertyAdorner(_scheduler, _source.Object, TimeSpan.Zero);

            adorner.Properties.Should().Contain(LogSourcePropertyAdorner.AllAdornedProperties);

            adorner.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.Zero, "because no processing has been done just yet");

            var buffer = new PropertiesBufferList();

            adorner.GetAllProperties(buffer);
            buffer.GetValue(Core.Properties.PercentageProcessed).Should().Be(Percentage.Zero, "because no processing has been done just yet");
        }
Exemple #12
0
        public void TestSetValue6()
        {
            var properties         = new PropertiesBufferList();
            var sourceDoesNotExist = new SourceDoesNotExist("dawdaw.txt");

            properties.SetValue((IReadOnlyPropertyDescriptor)Core.Properties.EmptyReason, sourceDoesNotExist);
            properties.GetValue(Core.Properties.EmptyReason).Should().Be(sourceDoesNotExist);

            var sourceCannotBeAccessed = new SourceDoesNotExist("wdawdwaw.txt");

            properties.SetValue((IReadOnlyPropertyDescriptor)Core.Properties.EmptyReason, sourceCannotBeAccessed);
            properties.GetValue(Core.Properties.EmptyReason).Should().Be(sourceCannotBeAccessed);
        }
Exemple #13
0
        public void TestLogLevelFatal()
        {
            var adorner = new LogSourcePropertyAdorner(_scheduler, _source.Object, TimeSpan.Zero);

            _sourceEntries.Add(new LogEntry
            {
                Index    = 0,
                LogLevel = LevelFlags.Fatal
            });
            _listeners.OnRead(_sourceEntries.Count);
            _scheduler.RunOnce();

            adorner.GetProperty(Core.Properties.TraceLogEntryCount).Should().Be(0);
            adorner.GetProperty(Core.Properties.DebugLogEntryCount).Should().Be(0);
            adorner.GetProperty(Core.Properties.InfoLogEntryCount).Should().Be(0);
            adorner.GetProperty(Core.Properties.WarningLogEntryCount).Should().Be(0);
            adorner.GetProperty(Core.Properties.ErrorLogEntryCount).Should().Be(0);
            adorner.GetProperty(Core.Properties.FatalLogEntryCount).Should().Be(1);
            adorner.GetProperty(Core.Properties.OtherLogEntryCount).Should().Be(0);

            var buffer = new PropertiesBufferList(Core.Properties.StartTimestamp, Core.Properties.EndTimestamp);

            adorner.GetAllProperties(buffer);
            buffer.GetValue(Core.Properties.TraceLogEntryCount).Should().Be(0);
            buffer.GetValue(Core.Properties.DebugLogEntryCount).Should().Be(0);
            buffer.GetValue(Core.Properties.InfoLogEntryCount).Should().Be(0);
            buffer.GetValue(Core.Properties.WarningLogEntryCount).Should().Be(0);
            buffer.GetValue(Core.Properties.ErrorLogEntryCount).Should().Be(0);
            buffer.GetValue(Core.Properties.FatalLogEntryCount).Should().Be(1);
            buffer.GetValue(Core.Properties.OtherLogEntryCount).Should().Be(0);

            _sourceEntries.Clear();
            _listeners.Reset();
            _scheduler.RunOnce();
            adorner.GetProperty(Core.Properties.TraceLogEntryCount).Should().Be(0);
            adorner.GetProperty(Core.Properties.DebugLogEntryCount).Should().Be(0);
            adorner.GetProperty(Core.Properties.InfoLogEntryCount).Should().Be(0);
            adorner.GetProperty(Core.Properties.WarningLogEntryCount).Should().Be(0);
            adorner.GetProperty(Core.Properties.ErrorLogEntryCount).Should().Be(0);
            adorner.GetProperty(Core.Properties.FatalLogEntryCount).Should().Be(0);
            adorner.GetProperty(Core.Properties.OtherLogEntryCount).Should().Be(0);

            adorner.GetAllProperties(buffer);
            buffer.GetValue(Core.Properties.TraceLogEntryCount).Should().Be(0);
            buffer.GetValue(Core.Properties.DebugLogEntryCount).Should().Be(0);
            buffer.GetValue(Core.Properties.InfoLogEntryCount).Should().Be(0);
            buffer.GetValue(Core.Properties.WarningLogEntryCount).Should().Be(0);
            buffer.GetValue(Core.Properties.ErrorLogEntryCount).Should().Be(0);
            buffer.GetValue(Core.Properties.FatalLogEntryCount).Should().Be(0);
            buffer.GetValue(Core.Properties.OtherLogEntryCount).Should().Be(0);
        }
Exemple #14
0
        public void TestEmptySourceFinishedProcessing()
        {
            var adorner = new LogSourcePropertyAdorner(_scheduler, _source.Object, TimeSpan.Zero);

            _sourceProperties.SetValue(Core.Properties.PercentageProcessed, Percentage.HundredPercent);
            _scheduler.RunOnce();

            adorner.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.HundredPercent, "because both the source and adorner are finished processing");

            var buffer = new PropertiesBufferList();

            adorner.GetAllProperties(buffer);
            buffer.GetValue(Core.Properties.PercentageProcessed).Should().Be(Percentage.HundredPercent, "because both the source and adorner are finished processing");
        }
Exemple #15
0
        public void TestAdd()
        {
            var properties = new PropertiesBufferList();

            properties.Properties.Should().BeEmpty();

            properties.Add(Core.Properties.Created);
            properties.Properties.Should().Equal(new object[] { Core.Properties.Created });

            properties.SetValue(Core.Properties.Created, new DateTime(2021, 02, 14, 12, 13, 01));
            new Action(() => properties.Add(Core.Properties.Created)).Should().NotThrow("because adding properties again should be tolerate and just not do anything");
            properties.Properties.Should().Equal(new object[] { Core.Properties.Created });
            properties.GetValue(Core.Properties.Created).Should().Be(new DateTime(2021, 02, 14, 12, 13, 01));
        }
Exemple #16
0
        public void TestOneEntryNoTimestampColumn()
        {
            var adorner = new LogSourcePropertyAdorner(_scheduler, _source.Object, TimeSpan.Zero);

            _scheduler.RunOnce();
            adorner.GetProperty(Core.Properties.StartTimestamp).Should().BeNull();
            adorner.GetProperty(Core.Properties.EndTimestamp).Should().BeNull();
            adorner.GetProperty(Core.Properties.Duration).Should().BeNull();

            var buffer = new PropertiesBufferList(Core.Properties.StartTimestamp, Core.Properties.EndTimestamp);

            adorner.GetAllProperties(buffer);
            buffer.GetValue(Core.Properties.StartTimestamp).Should().BeNull();
            buffer.GetValue(Core.Properties.EndTimestamp).Should().BeNull();
            buffer.GetValue(Core.Properties.Duration).Should().BeNull();
        }
Exemple #17
0
        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");
        }
Exemple #18
0
        public void TestConstruction()
        {
            var properties = new PropertiesBufferList(Core.Properties.Created);

            properties.GetValue(Core.Properties.Created).Should().Be(Core.Properties.Created.DefaultValue);
        }