Example #1
0
        public void TestSearch1()
        {
            var settings = new DataSource(TextLogFileAcceptanceTest.File2Mb)
            {
                Id = DataSourceId.CreateNew()
            };

            using (var logFile = new TextLogFile(_taskScheduler, TextLogFileAcceptanceTest.File2Mb))
                using (var dataSource = new SingleDataSource(_taskScheduler, settings, logFile, TimeSpan.Zero))
                {
                    var model = new SingleDataSourceViewModel(dataSource, new Mock <IActionCenter>().Object);

                    logFile.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue();

                    model.Property(x =>
                    {
                        x.Update();
                        return(x.TotalCount);
                    }).ShouldEventually().Be(16114);

                    //model.Update();
                    //model.TotalCount.Should().Be(16114);

                    model.SearchTerm = "RPC #12";
                    var search = dataSource.Search;
                    search.Property(x => x.Count).ShouldEventually().Be(334);

                    model.Update();
                    model.SearchResultCount.Should().Be(334);
                    model.CurrentSearchResultIndex.Should().Be(0);
                }
        }
        private IDataSourceViewModel CreateViewModel(IDataSource dataSource)
        {
            if (dataSource == null)
                throw new ArgumentNullException(nameof(dataSource));

            IDataSourceViewModel viewModel;
            var single = dataSource as ISingleDataSource;
            if (single != null)
            {
                viewModel = new SingleDataSourceViewModel(single, _actionCenter);
            }
            else
            {
                var merged = dataSource as MergedDataSource;
                if (merged != null)
                {
                    viewModel = new MergedDataSourceViewModel(merged, _actionCenter);
                }
                else
                {
                    throw new ArgumentException(string.Format("Unknown data source: {0} ({1})", dataSource, dataSource.GetType()));
                }
            }
            viewModel.Remove += OnRemove;
            _allDataSourceViewModels.Add(viewModel);

            if (_settings.DataSources.SelectedItem == viewModel.DataSource.Id)
            {
                SelectedItem = viewModel;
            }

            return viewModel;
        }
Example #3
0
        public void TestCanBeRemovedAsPartOfMergedDataSource()
        {
            var actionCenter = new Mock <IActionCenter>();
            var dataSource   = new Mock <ISingleDataSource>();

            dataSource.Setup(x => x.Settings).Returns(new DataSource());
            var model = new SingleDataSourceViewModel(dataSource.Object, actionCenter.Object);

            using (var monitor = model.Monitor())
            {
                model.CanBeRemoved.Should().BeTrue();

                var mergedDataSource = new Mock <IMergedDataSource>();
                mergedDataSource.Setup(x => x.Settings).Returns(new DataSource());
                var merged = new MergedDataSourceViewModel(mergedDataSource.Object, actionCenter.Object);
                model.Parent = merged;
                model.CanBeRemoved.Should().BeTrue();
                monitor.Should().NotRaisePropertyChangeFor(x => x.CanBeRemoved);

                monitor.Clear();
                model.Parent = null;
                model.CanBeRemoved.Should().BeTrue();
                monitor.Should().NotRaisePropertyChangeFor(x => x.CanBeRemoved);
            }
        }
Example #4
0
        public void TestDisplayRelativePathWithFolderParent()
        {
            var single = new Mock <ISingleDataSource>();

            single.Setup(x => x.Settings).Returns(new DataSource());
            single.Setup(x => x.FullFileName).Returns(@"C:\Users\Simon\AppData\Local\Tailviewer\Installation.log");
            var singleViewModel = new SingleDataSourceViewModel(single.Object, _actionCenter.Object);

            using (var monitor = singleViewModel.Monitor())
            {
                singleViewModel.DisplayName.Should().Be("Installation.log");
                singleViewModel.Folder.Should().Be(@"C:\Users\Simon\AppData\Local\Tailviewer\");

                var folder = new Mock <IFolderDataSource>();
                folder.Setup(x => x.OriginalSources).Returns(new List <IDataSource>());
                folder.Setup(x => x.LogFileFolderPath).Returns(@"C:\Users\Simon\AppData\Local\");
                var folderViewModel = new FolderDataSourceViewModel(folder.Object, _actionCenter.Object);

                singleViewModel.Parent = folderViewModel;
                singleViewModel.DisplayName.Should().Be("Installation.log");
                singleViewModel.Folder.Should().Be(@"<root>\Tailviewer\");
                monitor.Should().RaisePropertyChangeFor(x => x.Folder);
                monitor.Clear();

                singleViewModel.Parent = null;
                singleViewModel.DisplayName.Should().Be("Installation.log");
                singleViewModel.Folder.Should().Be(@"C:\Users\Simon\AppData\Local\Tailviewer\");
                monitor.Should().RaisePropertyChangeFor(x => x.Folder);
            }
        }
        public void TestDataSourceDoesntExist2()
        {
            var dataSource = new Mock <ISingleDataSource>();
            var logFile    = new Mock <ILogFile>();

            logFile.Setup(x => x.GetValue(LogFileProperties.EmptyReason)).Returns(ErrorFlags.SourceDoesNotExist);
            logFile.Setup(x => x.GetValue(LogFileProperties.Size)).Returns((Size?)null);
            var filteredLogFile       = new Mock <ILogFile>();
            ILogFileListener listener = null;

            filteredLogFile.Setup(x => x.AddListener(It.IsAny <ILogFileListener>(), It.IsAny <TimeSpan>(), It.IsAny <int>()))
            .Callback((ILogFileListener l, TimeSpan t, int i) => listener = l);
            dataSource.Setup(x => x.UnfilteredLogFile).Returns(logFile.Object);
            dataSource.Setup(x => x.FullFileName).Returns(@"E:\Tailviewer\somefile.log");
            dataSource.Setup(x => x.FilteredLogFile).Returns(filteredLogFile.Object);
            dataSource.Setup(x => x.Search).Returns(new Mock <ILogFileSearch>().Object);

            var dataSourceModel = new SingleDataSourceViewModel(dataSource.Object, _actionCenter.Object);
            var model           = new LogViewerViewModel(dataSourceModel, _actionCenter.Object, _settings.Object, TimeSpan.Zero);

            model.LogEntryCount.Should().Be(0);
            model.NoEntriesExplanation.Should().Be("Can't find \"somefile.log\"");
            model.NoEntriesSubtext.Should().Be("It was last seen at E:\\Tailviewer");

            logFile.Setup(x => x.GetValue(LogFileProperties.EmptyReason)).Returns(ErrorFlags.None);
            logFile.Setup(x => x.GetValue(LogFileProperties.Size)).Returns(Size.Zero);
            listener.OnLogFileModified(logFile.Object, new LogFileSection(0, 0));
            model.Update();

            model.NoEntriesExplanation.Should().Be("The data source is empty");
            model.NoEntriesSubtext.Should().BeNull();
        }
        public void TestCtor()
        {
            var source =
                new SingleDataSourceViewModel(
                    new SingleDataSource(_logFileFactory, _scheduler, new DataSource("Foobar")
            {
                Id = DataSourceId.CreateNew()
            }),
                    _actionCenter.Object);

            source.LevelsFilter = LevelFlags.All;

            var control = new LogViewerControl
            {
                DataSource = source
            };

            control.ShowOther.Should().BeTrue();
            control.ShowTrace.Should().BeTrue();
            control.ShowDebug.Should().BeTrue();
            control.ShowInfo.Should().BeTrue();
            control.ShowWarning.Should().BeTrue();
            control.ShowError.Should().BeTrue();
            control.ShowFatal.Should().BeTrue();
        }
Example #7
0
        public void TestCannotBeRemovedAsPartOfFolder()
        {
            var actionCenter = new Mock <IActionCenter>();
            var dataSource   = new Mock <ISingleDataSource>();

            dataSource.Setup(x => x.Settings).Returns(new DataSource());
            var model = new SingleDataSourceViewModel(dataSource.Object, actionCenter.Object);

            using (var monitor = model.Monitor())
            {
                model.CanBeRemoved.Should().BeTrue();

                var folderDataSource = new Mock <IFolderDataSource>();
                folderDataSource.Setup(x => x.Settings).Returns(new DataSource());
                var folder = new FolderDataSourceViewModel(folderDataSource.Object, actionCenter.Object);
                model.Parent = folder;
                model.CanBeRemoved.Should().BeFalse();
                monitor.Should().RaisePropertyChangeFor(x => x.CanBeRemoved);

                monitor.Clear();
                model.Parent = null;
                model.CanBeRemoved.Should().BeTrue();
                monitor.Should().RaisePropertyChangeFor(x => x.CanBeRemoved);
            }
        }
        public void TestQuickFilter()
        {
            var dataSource = new Mock <ISingleDataSource>();
            var logFile    = new Mock <ILogFile>();

            logFile.Setup(x => x.GetValue(LogFileProperties.EmptyReason)).Returns(ErrorFlags.None);
            logFile.Setup(x => x.Count).Returns(1);
            logFile.Setup(x => x.GetValue(LogFileProperties.Size)).Returns(Size.FromBytes(1));
            var filteredLogFile = new Mock <ILogFile>();

            dataSource.Setup(x => x.UnfilteredLogFile).Returns(logFile.Object);
            dataSource.Setup(x => x.FilteredLogFile).Returns(filteredLogFile.Object);
            dataSource.Setup(x => x.SearchTerm).Returns("");
            dataSource.Setup(x => x.QuickFilterChain).Returns(new List <ILogEntryFilter> {
                new Mock <ILogEntryFilter>().Object
            });
            dataSource.Setup(x => x.LevelFilter).Returns(LevelFlags.All);
            dataSource.Setup(x => x.Search).Returns(new Mock <ILogFileSearch>().Object);

            var dataSourceModel = new SingleDataSourceViewModel(dataSource.Object, _actionCenter.Object);
            var model           = new LogViewerViewModel(dataSourceModel, _actionCenter.Object, _settings.Object, TimeSpan.Zero);

            model.LogEntryCount.Should().Be(0);
            model.NoEntriesExplanation.Should().Be("Not a single log entry matches the activated quick filters");
            model.NoEntriesSubtext.Should().BeNull();
        }
Example #9
0
        public void TestAddChild1()
        {
            var model = new MergedDataSourceViewModel(_dataSources.AddGroup(), _actionCenter.Object);
            SingleDataSource source = _dataSources.AddDataSource("foo");
            var sourceViewModel     = new SingleDataSourceViewModel(source, _actionCenter.Object);

            model.AddChild(sourceViewModel);
            model.Observable.Should().Equal(sourceViewModel);
            sourceViewModel.Parent.Should().BeSameAs(model);
        }
Example #10
0
        public void TestRename()
        {
            var dataSource = new Mock <ISingleDataSource>();

            dataSource.Setup(x => x.FullFileName).Returns("A:\\foo");
            var model = new SingleDataSourceViewModel(dataSource.Object, _actionCenter.Object);

            model.DisplayName.Should().Be("foo");
            new Action(() => model.DisplayName = "bar").ShouldThrow <InvalidOperationException>();
            model.DisplayName.Should().Be("foo");
        }
Example #11
0
        public void TestInsertChild1()
        {
            var dataSource = _dataSources.AddGroup();
            var model      = new MergedDataSourceViewModel(dataSource, _actionCenter.Object);

            SingleDataSource source = _dataSources.AddDataSource("foo");
            var sourceViewModel     = new SingleDataSourceViewModel(source, _actionCenter.Object);

            model.Insert(0, sourceViewModel);
            sourceViewModel.CharacterCode.Should().Be("A", "because the merged data source is responsible for providing unique character codes");
        }
Example #12
0
 public void TestConstruction4([Values(true, false)] bool showElapsedTime)
 {
     using (var source = new SingleDataSource(_scheduler, new DataSource
     {
         Id = DataSourceId.CreateNew(),
         File = @"C:\temp\foo.txt",
         ShowElapsedTime = showElapsedTime
     }, new Mock <ILogFile>().Object, TimeSpan.Zero))
     {
         var model = new SingleDataSourceViewModel(source, _actionCenter.Object);
         model.ShowElapsedTime.Should().Be(showElapsedTime);
     }
 }
Example #13
0
        public void TestPluginDescription()
        {
            var single = new Mock <ISingleDataSource>();

            single.Setup(x => x.Settings).Returns(new DataSource());
            var pluginDescription = new PluginDescription();

            single.Setup(x => x.TranslationPlugin).Returns(pluginDescription);
            var singleViewModel = new SingleDataSourceViewModel(single.Object, _actionCenter.Object);

            singleViewModel.TranslationPlugin.Should().NotBeNull();
            singleViewModel.TranslationPlugin.Should().BeSameAs(pluginDescription);
        }
Example #14
0
        public void TestConstruction2()
        {
            using (
                var source = new SingleDataSource(_scheduler,
                                                  new DataSource {
                Id = DataSourceId.CreateNew(), File = @"C:\temp\foo.txt", SearchTerm = "foobar"
            },
                                                  new Mock <ILogFile>().Object, TimeSpan.Zero))
            {
                source.SearchTerm.Should().Be("foobar");

                var model = new SingleDataSourceViewModel(source, _actionCenter.Object);
                model.SearchTerm.Should().Be("foobar");
            }
        }
Example #15
0
 public void TestRemoveCommand1()
 {
     using (
         var source =
             new SingleDataSource(_logFileFactory, _scheduler,
                                  new DataSource(@"E:\Code\SharpTail\SharpTail.Test\TestData\20Mb.test")
     {
         Id = DataSourceId.CreateNew()
     }))
     {
         var model = new SingleDataSourceViewModel(source, _actionCenter.Object);
         model.RemoveCommand.Should().NotBeNull();
         model.RemoveCommand.CanExecute(null).Should().BeTrue();
         new Action(() => model.RemoveCommand.Execute(null)).ShouldNotThrow();
     }
 }
Example #16
0
        public void TestSetQuickFilterChain1()
        {
            var settings = new DataSource(@"E:\Code\SharpTail\SharpTail.Test\TestData\20Mb.test")
            {
                Id = DataSourceId.CreateNew()
            };

            using (var dataSource = new SingleDataSource(_logFileFactory, _scheduler, settings))
            {
                var model = new SingleDataSourceViewModel(dataSource, _actionCenter.Object);
                var chain = new[] { new SubstringFilter("foobar", true) };
                model.QuickFilterChain = chain;
                model.QuickFilterChain.Should().BeSameAs(chain);
                dataSource.QuickFilterChain.Should().BeSameAs(chain);
            }
        }
Example #17
0
 public void TestRemoveCommand2()
 {
     using (
         var source =
             new SingleDataSource(_logFileFactory, _scheduler,
                                  new DataSource(@"E:\Code\SharpTail\SharpTail.Test\TestData\20Mb.test")
     {
         Id = DataSourceId.CreateNew()
     }))
     {
         var model = new SingleDataSourceViewModel(source, _actionCenter.Object);
         var calls = new List <IDataSourceViewModel>();
         model.Remove += calls.Add;
         new Action(() => model.RemoveCommand.Execute(null)).ShouldNotThrow();
         calls.Should().Equal(new object[] { model });
     }
 }
Example #18
0
        public void TestConstruction1()
        {
            var settings = new DataSource(@"E:\Code\SharpTail\SharpTail.Test\TestData\20Mb.test")
            {
                Id = DataSourceId.CreateNew()
            };

            using (var source = new SingleDataSource(_logFileFactory, _scheduler, settings))
            {
                var model = new SingleDataSourceViewModel(source, _actionCenter.Object);
                model.FullName.Should().Be(@"E:\Code\SharpTail\SharpTail.Test\TestData\20Mb.test");
                model.Id.Should().Be(settings.Id);

                model.DisplayName.Should().Be("20Mb.test");
                model.CanBeRenamed.Should().BeFalse();
            }
        }
Example #19
0
        public void SetUp()
        {
            _settings   = new Mock <IApplicationSettings>();
            _dataSource =
                new SingleDataSourceViewModel(
                    new SingleDataSource(_logFileFactory, _scheduler, new DataSource("Foobar")
            {
                Id = DataSourceId.CreateNew()
            }),
                    _actionCenter.Object);
            _control = new LogViewerControl
            {
                DataSource = _dataSource,
                Width      = 1024,
                Height     = 768
            };

            DispatcherExtensions.ExecuteAllEvents();
        }
Example #20
0
        public void TestSearch1()
        {
            using (
                var dataSource = new SingleDataSource(_logFileFactory, _scheduler,
                                                      new DataSource(TextLogFileAcceptanceTest.File20Mb)
            {
                Id = DataSourceId.CreateNew()
            }))
            {
                var dataSourceModel = new SingleDataSourceViewModel(dataSource, _actionCenter.Object);
                var model           = new LogViewerViewModel(dataSourceModel, _actionCenter.Object, _settings, TimeSpan.Zero);

                dataSourceModel.SearchTerm = "i";
                dataSource.FilteredLogFile.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue(TimeSpan.FromSeconds(20));
                // We have waited for that filter operation to finish, HOWEVER, did not invoke the dispatcher.
                // This causes all modifications from that operation to stay in the view-model's queue

                dataSourceModel.SearchTerm = "in";
                dataSourceModel.SearchTerm = "inf";
                dataSourceModel.SearchTerm = "info";

                // Now we wait for the very last filter operation to complete
                dataSource.FilteredLogFile.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue(TimeSpan.FromSeconds(20));
                // And then dispatch ALL events at ONCE.
                // We expect the view model to completely ignore the old changes!
                model.Update();

                /*model.LogEntryCount.Should().Be(5);
                 * model.LogEntries.Select(x => x.Message)
                 *   .Should().Equal(new[]
                 *           {
                 *                   "2015-10-07 19:50:58,982 [8092, 1] INFO  SharpRemote.Hosting.OutOfProcessSiloServer (null) - Silo Server starting, args (1): \"14056\", without custom type resolver"
                 *                   ,
                 *                   "2015-10-07 19:50:59,081 [8092, 1] INFO  SharpRemote.SocketRemotingEndPointServer (null) - EndPoint '<Unnamed>' listening on 0.0.0.0:49152"
                 *                   ,
                 *                   "2015-10-07 19:50:59,171 [8092, 6] INFO  SharpRemote.AbstractIPSocketRemotingEndPoint (null) - <Unnamed>: Connected to 127.0.0.1:10348"
                 *                   ,
                 *                   "2015-10-07 19:51:42,481 [8092, EndPoint '<Unnamed>' Socket Reading] INFO  SharpRemote.AbstractSocketRemotingEndPoint (null) - Disconnecting socket '<Unnamed>' from 127.0.0.1:10348: ReadFailure"
                 *                   ,
                 *                   "2015-10-07 19:51:42,483 [8092, 6] INFO  SharpRemote.Hosting.OutOfProcessSiloServer (null) - Parent process terminated unexpectedly (exit code: -1), shutting down..."
                 *           });*/
            }
        }
        public void TestDataSourceEmpty()
        {
            var dataSource = new Mock <ISingleDataSource>();
            var logFile    = new Mock <ILogFile>();

            logFile.Setup(x => x.GetValue(LogFileProperties.EmptyReason)).Returns(ErrorFlags.None);
            logFile.Setup(x => x.GetValue(LogFileProperties.Size)).Returns(Size.Zero);
            var filteredLogFile = new Mock <ILogFile>();

            dataSource.Setup(x => x.UnfilteredLogFile).Returns(logFile.Object);
            dataSource.Setup(x => x.FilteredLogFile).Returns(filteredLogFile.Object);
            dataSource.Setup(x => x.Search).Returns(new Mock <ILogFileSearch>().Object);

            var dataSourceModel = new SingleDataSourceViewModel(dataSource.Object, _actionCenter.Object);
            var model           = new LogViewerViewModel(dataSourceModel, _actionCenter.Object, _settings.Object, TimeSpan.Zero);

            model.LogEntryCount.Should().Be(0);
            model.NoEntriesExplanation.Should().Be("The data source is empty");
            model.NoEntriesSubtext.Should().BeNull();
        }
Example #22
0
        public void TestCharacterCode()
        {
            var dataSource = new Mock <ISingleDataSource>();

            dataSource.SetupAllProperties();

            var model = new SingleDataSourceViewModel(dataSource.Object, _actionCenter.Object);

            model.CharacterCode = "ZZ";
            model.CharacterCode.Should().Be("ZZ");
            dataSource.Object.CharacterCode.Should().Be("ZZ");

            model.CharacterCode = "B";
            model.CharacterCode.Should().Be("B");
            dataSource.Object.CharacterCode.Should().Be("B");

            model.CharacterCode = null;
            model.CharacterCode.Should().BeNull();
            dataSource.Object.CharacterCode.Should().BeNull();
        }
        public void TestDataSourceDoesntExist1()
        {
            var dataSource = new Mock <ISingleDataSource>();
            var logFile    = new Mock <ILogFile>();

            logFile.Setup(x => x.GetValue(LogFileProperties.EmptyReason)).Returns(ErrorFlags.SourceDoesNotExist);
            var filteredLogFile = new Mock <ILogFile>();

            dataSource.Setup(x => x.UnfilteredLogFile).Returns(logFile.Object);
            dataSource.Setup(x => x.FullFileName).Returns(@"E:\Tailviewer\somefile.log");
            dataSource.Setup(x => x.FilteredLogFile).Returns(filteredLogFile.Object);
            dataSource.Setup(x => x.Search).Returns(new Mock <ILogFileSearch>().Object);

            var dataSourceModel = new SingleDataSourceViewModel(dataSource.Object, _actionCenter.Object);
            var model           = new LogViewerViewModel(dataSourceModel, _actionCenter.Object, _settings.Object, TimeSpan.Zero);

            model.LogEntryCount.Should().Be(0);
            model.NoEntriesExplanation.Should().Be("Can't find \"somefile.log\"");
            model.NoEntriesSubtext.Should().Be("It was last seen at E:\\Tailviewer");
        }
        public void TestDataSourceCannotBeAccessed1()
        {
            var dataSource = new Mock <ISingleDataSource>();
            var logFile    = new Mock <ILogFile>();

            logFile.Setup(x => x.GetValue(LogFileProperties.EmptyReason)).Returns(ErrorFlags.SourceCannotBeAccessed);
            var filteredLogFile = new Mock <ILogFile>();

            dataSource.Setup(x => x.UnfilteredLogFile).Returns(logFile.Object);
            dataSource.Setup(x => x.FullFileName).Returns(@"E:\Tailviewer\somefile.log");
            dataSource.Setup(x => x.FilteredLogFile).Returns(filteredLogFile.Object);
            dataSource.Setup(x => x.Search).Returns(new Mock <ILogFileSearch>().Object);

            var dataSourceModel = new SingleDataSourceViewModel(dataSource.Object, _actionCenter.Object);
            var model           = new LogViewerViewModel(dataSourceModel, _actionCenter.Object, _settings.Object, TimeSpan.Zero);

            model.LogEntryCount.Should().Be(0);
            model.NoEntriesExplanation.Should().Be("Unable to access \"somefile.log\"");
            model.NoEntriesSubtext.Should().Be("The file may be opened exclusively by another process or you are not authorized to view it");
        }
        public void TestClearAllShowAll()
        {
            var dataSource = new Mock <ISingleDataSource>();
            var model      = new SingleDataSourceViewModel(dataSource.Object, new Mock <IActionCenter>().Object);

            model.ScreenCleared.Should().BeFalse();

            model.ClearScreenCommand.Should().NotBeNull();
            model.ClearScreenCommand.CanExecute(null).Should().BeTrue("because the screen can always be cleared");
            model.ShowAllCommand.Should().NotBeNull();
            model.ShowAllCommand.CanExecute(null).Should().BeFalse("because the screen hasn't been cleared so nothing needs to be shown again");
            model.ClearScreenCommand.Execute(null);
            dataSource.Verify(x => x.ClearScreen(), Times.Once);

            model.ShowAllCommand.Should().NotBeNull();
            model.ShowAllCommand.CanExecute(null).Should().BeTrue("because the screen has been cleared and thus everything may be shown again");
            model.ShowAllCommand.Execute(null);
            dataSource.Verify(x => x.ShowAll(), Times.Once);

            model.ShowAllCommand.CanExecute(null).Should().BeFalse("because everything has been shown again and thus nothing further can be shown");
        }
        public void TestLevelFilter1([ValueSource(nameof(NotAll))] LevelFlags flags)
        {
            var dataSource = new Mock <ISingleDataSource>();
            var logFile    = new Mock <ILogFile>();

            logFile.Setup(x => x.GetValue(LogFileProperties.EmptyReason)).Returns(ErrorFlags.None);
            logFile.Setup(x => x.Count).Returns(1);
            logFile.Setup(x => x.GetValue(LogFileProperties.Size)).Returns(Size.FromBytes(1));
            var filteredLogFile = new Mock <ILogFile>();

            dataSource.Setup(x => x.UnfilteredLogFile).Returns(logFile.Object);
            dataSource.Setup(x => x.FilteredLogFile).Returns(filteredLogFile.Object);
            dataSource.Setup(x => x.LevelFilter).Returns(flags);
            dataSource.Setup(x => x.Search).Returns(new Mock <ILogFileSearch>().Object);

            var dataSourceModel = new SingleDataSourceViewModel(dataSource.Object, _actionCenter.Object);
            var model           = new LogViewerViewModel(dataSourceModel, _actionCenter.Object, _settings.Object, TimeSpan.Zero);

            model.LogEntryCount.Should().Be(0);
            model.NoEntriesExplanation.Should().Be("Not a single log entry matches the level selection");
            model.NoEntriesSubtext.Should().BeNull();
        }
Example #27
0
        public void TestAddChild3()
        {
            var dataSource = _dataSources.AddGroup();
            var model      = new MergedDataSourceViewModel(dataSource, _actionCenter.Object);

            var sources = new List <SingleDataSourceViewModel>();

            for (int i = 0; i < LogLineSourceId.MaxSources; ++i)
            {
                var source          = _dataSources.AddDataSource(i.ToString());
                var sourceViewModel = new SingleDataSourceViewModel(source, _actionCenter.Object);
                sources.Add(sourceViewModel);

                model.AddChild(sourceViewModel).Should().BeTrue("because the child should've been added");
                model.Observable.Should().Equal(sources, "because all previously added children should be there");
            }

            var tooMuch = new SingleDataSourceViewModel(_dataSources.AddDataSource("dadw"), _actionCenter.Object);

            model.AddChild(tooMuch).Should().BeFalse("because no more children can be added");
            model.Observable.Should().Equal(sources, "because only those sources which could be added should be present");
        }
Example #28
0
        public void TestInsertChild2()
        {
            var dataSource = _dataSources.AddGroup();
            var model      = new MergedDataSourceViewModel(dataSource, _actionCenter.Object);

            var child1 = new SingleDataSourceViewModel(_dataSources.AddDataSource("foo"), _actionCenter.Object);

            model.AddChild(child1);
            child1.CharacterCode.Should().Be("A");

            var child2 = new SingleDataSourceViewModel(_dataSources.AddDataSource("bar"), _actionCenter.Object);

            model.Insert(0, child2);
            model.Observable.Should().Equal(new object[]
            {
                child2, child1
            });

            const string reason = "because the merged data source is responsible for providing unique character codes";

            child2.CharacterCode.Should().Be("A", reason);
            child1.CharacterCode.Should().Be("B", reason);
        }
Example #29
0
        public void TestChangeShowElapsedTime([Values(true, false)] bool showElapsedTime)
        {
            using (var source = new SingleDataSource(_scheduler, new DataSource
            {
                Id = DataSourceId.CreateNew(),
                File = @"C:\temp\foo.txt",
                ShowElapsedTime = showElapsedTime
            }, new Mock <ILogFile>().Object, TimeSpan.Zero))
            {
                var model = new SingleDataSourceViewModel(source, _actionCenter.Object);

                var changes = new List <string>();
                model.PropertyChanged += (sender, args) => changes.Add(args.PropertyName);

                model.ShowElapsedTime = !showElapsedTime;
                changes.Should().Equal(new object[] { "ShowElapsedTime" }, "because the property should've changed once");

                model.ShowElapsedTime = !showElapsedTime;
                changes.Should().Equal(new object[] { "ShowElapsedTime" }, "because the property didn't change");

                model.ShowElapsedTime = showElapsedTime;
                changes.Should().Equal(new object[] { "ShowElapsedTime", "ShowElapsedTime" }, "because the property changed a 2nd time");
            }
        }
Example #30
0
        public void TestRemoveChild1()
        {
            var dataSource = _dataSources.AddGroup();
            var model      = new MergedDataSourceViewModel(dataSource, _actionCenter.Object);

            var child1 = new SingleDataSourceViewModel(_dataSources.AddDataSource("foo"), _actionCenter.Object);

            model.AddChild(child1);

            var child2 = new SingleDataSourceViewModel(_dataSources.AddDataSource("bar"), _actionCenter.Object);

            model.AddChild(child2);
            model.Observable.Should().Equal(new object[]
            {
                child1, child2
            });

            child1.CharacterCode.Should().Be("A");
            child2.CharacterCode.Should().Be("B");

            model.RemoveChild(child1);
            model.Observable.Should().Equal(new object[] { child2 });
            child2.CharacterCode.Should().Be("A");
        }