public void TestDataSourceDoesntExist2()
        {
            var dataSource = new Mock<IDataSource>();
            var logFile = new Mock<ILogFile>();
            logFile.Setup(x => x.Exists).Returns(false);
            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);
            var model = new LogViewerViewModel(dataSourceModel, _dispatcher, 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.Exists).Returns(true);
            listener.OnLogFileModified(logFile.Object, new LogFileSection(0, 0));
            _dispatcher.InvokeAll();

            model.NoEntriesExplanation.Should().Be("The data source is empty");
            model.NoEntriesSubtext.Should().BeNull();
        }
 public void TestAdd1()
 {
     SingleDataSource source = _dataSources.AddDataSource("foo");
     var sourceViewModel = new SingleDataSourceViewModel(source);
     _model.AddChild(sourceViewModel);
     _model.Observable.Should().Equal(sourceViewModel);
     sourceViewModel.Parent.Should().BeSameAs(_model);
 }
        public void TestCtor2()
        {
            using (var source = new SingleDataSource(_scheduler, new DataSource { Id = Guid.NewGuid(), File = @"C:\temp\foo.txt", SearchTerm = "foobar" }, new Mock<ILogFile>().Object, TimeSpan.Zero))
            {
                source.SearchTerm.Should().Be("foobar");

                var model = new SingleDataSourceViewModel(source);
                model.FileName.Should().Be("foo.txt");
                model.SearchTerm.Should().Be("foobar");
            }
        }
 public void TestRemoveCommand1()
 {
     using (
         var source =
             new SingleDataSource(_scheduler, new DataSource(@"E:\Code\SharpTail\SharpTail.Test\TestData\20Mb.test") { Id = Guid.NewGuid() }))
     {
         var model = new SingleDataSourceViewModel(source);
         model.RemoveCommand.Should().NotBeNull();
         model.RemoveCommand.CanExecute(null).Should().BeTrue();
         new Action(() => model.RemoveCommand.Execute(null)).ShouldNotThrow();
     }
 }
 public void TestRemoveCommand2()
 {
     using (
         var source =
             new SingleDataSource(_scheduler, new DataSource(@"E:\Code\SharpTail\SharpTail.Test\TestData\20Mb.test") { Id = Guid.NewGuid() }))
     {
         var model = new SingleDataSourceViewModel(source);
         var calls = new List<IDataSourceViewModel>();
         model.Remove += calls.Add;
         new Action(() => model.RemoveCommand.Execute(null)).ShouldNotThrow();
         calls.Should().Equal(new object[] {model});
     }
 }
 public void TestCtor1()
 {
     var settings = new DataSource(@"E:\Code\SharpTail\SharpTail.Test\TestData\20Mb.test")
         {
             Id = Guid.NewGuid()
         };
     using (var source = new SingleDataSource(_scheduler, settings))
     {
         var model = new SingleDataSourceViewModel(source);
         model.FullName.Should().Be(@"E:\Code\SharpTail\SharpTail.Test\TestData\20Mb.test");
         model.Id.Should().Be(settings.Id);
     }
 }
Exemplo n.º 7
0
        public void SetUp()
        {
            _dataSource = new SingleDataSourceViewModel(new SingleDataSource(_scheduler, new DataSource("Foobar") {Id = Guid.NewGuid()}));
            _control = new LogViewerControl
                {
                    DataSource = _dataSource,
                    Width = 1024,
                    Height = 768
                };

            DispatcherExtensions.ExecuteAllEvents();

            _dispatcher = new ManualDispatcher();
        }
        public void TestDataSourceDoesntExist1()
        {
            var dataSource = new Mock<IDataSource>();
            var logFile = new Mock<ILogFile>();
            logFile.Setup(x => x.Exists).Returns(false);
            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);
            var model = new LogViewerViewModel(dataSourceModel, _dispatcher, 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 TestSearch1()
        {
            var settings = new DataSource(LogFileTest.File2Mb) { Id = Guid.NewGuid() };
            using (var logFile = new LogFile(_taskScheduler, LogFileTest.File2Mb))
            using (var dataSource = new SingleDataSource(_taskScheduler, settings, logFile, TimeSpan.Zero))
            {
                var model = new SingleDataSourceViewModel(dataSource);

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

                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);
            }
        }
Exemplo n.º 10
0
        public void TestSearch1()
        {
            using (var dataSource = new SingleDataSource(_scheduler, new DataSource(LogFileTest.File20Mb) { Id = Guid.NewGuid() }))
            {
                var dataSourceModel = new SingleDataSourceViewModel(dataSource);
                var model = new LogViewerViewModel(dataSourceModel, _dispatcher, 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!
                _dispatcher.InvokeAll();

                /*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..."
                         });*/
            }
        }
Exemplo n.º 11
0
        private IDataSourceViewModel CreateViewModel(IDataSource dataSource)
        {
            if (dataSource == null)
                throw new ArgumentNullException("dataSource");

            IDataSourceViewModel viewModel;
            var single = dataSource as SingleDataSource;
            if (single != null)
            {
                viewModel = new SingleDataSourceViewModel(single);
            }
            else
            {
                var merged = dataSource as MergedDataSource;
                if (merged != null)
                {
                    viewModel = new MergedDataSourceViewModel(merged);
                }
                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;
        }
Exemplo n.º 12
0
        public void TestDataSourceEmpty()
        {
            var dataSource = new Mock<IDataSource>();
            var logFile = new Mock<ILogFile>();
            logFile.Setup(x => x.Exists).Returns(true);
            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);
            var model = new LogViewerViewModel(dataSourceModel, _dispatcher, TimeSpan.Zero);
            model.LogEntryCount.Should().Be(0);
            model.NoEntriesExplanation.Should().Be("The data source is empty");
            model.NoEntriesSubtext.Should().BeNull();
        }
Exemplo n.º 13
0
        public void TestStringFilter()
        {
            var dataSource = new Mock<IDataSource>();
            var logFile = new Mock<ILogFile>();
            logFile.Setup(x => x.Exists).Returns(true);
            logFile.Setup(x => x.Count).Returns(1);
            logFile.Setup(x => x.FileSize).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("s");
            dataSource.Setup(x => x.LevelFilter).Returns(LevelFlags.All);
            dataSource.Setup(x => x.Search).Returns(new Mock<ILogFileSearch>().Object);

            var dataSourceModel = new SingleDataSourceViewModel(dataSource.Object);
            var model = new LogViewerViewModel(dataSourceModel, _dispatcher, TimeSpan.Zero);
            model.LogEntryCount.Should().Be(0);
            model.NoEntriesExplanation.Should().Be("Not a single log entry matches the log file filter");
            model.NoEntriesSubtext.Should().BeNull();
        }
 public void TestSetQuickFilterChain1()
 {
     var settings = new DataSource(@"E:\Code\SharpTail\SharpTail.Test\TestData\20Mb.test")
         {
             Id = Guid.NewGuid()
         };
     using (var dataSource = new SingleDataSource(_scheduler, settings))
     {
         var model = new SingleDataSourceViewModel(dataSource);
         var chain = new[] {new SubstringFilter("foobar", true)};
         model.QuickFilterChain = chain;
         model.QuickFilterChain.Should().BeSameAs(chain);
         dataSource.QuickFilterChain.Should().BeSameAs(chain);
     }
 }
Exemplo n.º 15
0
        public void TestCtor()
        {
            var source = new SingleDataSourceViewModel(new SingleDataSource(_scheduler, new DataSource("Foobar") {Id = Guid.NewGuid()}));
            source.LevelsFilter = LevelFlags.All;

            var control = new LogViewerControl
                {
                    DataSource = source
                };
            control.ShowDebug.Should().BeTrue();
            control.ShowInfo.Should().BeTrue();
            control.ShowWarning.Should().BeTrue();
            control.ShowError.Should().BeTrue();
            control.ShowFatal.Should().BeTrue();
        }