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 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() { 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..." });*/ } }
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(); }
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(); }
private void OnLogViewChanged(LogViewerViewModel oldView, LogViewerViewModel newView) { try { _changingLogView = true; if (oldView != null) { oldView.PropertyChanged -= LogViewOnPropertyChanged; } if (newView != null) { newView.PropertyChanged += LogViewOnPropertyChanged; DataSource = newView.DataSource; LogFile = newView.LogFile; Search = newView.Search; CurrentLogLine = newView.DataSource.VisibleLogLine; Select(newView.DataSource.SelectedLogLines); SetHorizontalOffset(newView.DataSource.HorizontalOffset); } else { DataSource = null; LogFile = null; } } finally { _changingLogView = false; } }
private void OpenFile(IDataSourceViewModel dataSource) { if (dataSource != null) { CurrentDataSource = dataSource; CurrentDataSourceLogView = new LogViewerViewModel( dataSource, _dispatcher); WindowTitle = string.Format("{0} - {1}", Constants.MainWindowTitle, dataSource.DisplayName); } else { CurrentDataSource = null; CurrentDataSourceLogView = null; WindowTitle = Constants.MainWindowTitle; } }
public void TestChangeLogView4() { _control.DataSource = null; var dataSource = new Mock<IDataSource>(); var logFile = new Mock<ILogFile>(); logFile.Setup(x => x.Count).Returns(100); dataSource.Setup(x => x.UnfilteredLogFile).Returns(logFile.Object); dataSource.Setup(x => x.FilteredLogFile).Returns(logFile.Object); var dataSourceViewModel = new Mock<IDataSourceViewModel>(); dataSourceViewModel.Setup(x => x.DataSource).Returns(dataSource.Object); dataSourceViewModel.Setup(x => x.SelectedLogLines).Returns(new HashSet<LogLineIndex> {new LogLineIndex(42)}); dataSourceViewModel.Setup(x => x.SearchTerm).Returns("Foobar"); var logView = new LogViewerViewModel(dataSourceViewModel.Object, _dispatcher); _control.PART_SearchBox.Text.Should().Be(string.Empty); _control.LogView = logView; _control.SelectedIndices.Should().Equal(new[] {new LogLineIndex(42)}); _control.PART_SearchBox.Text.Should().Be("Foobar"); }
public void TestChangeLogView2() { var dataSource = new Mock<IDataSource>(); var logFile = new Mock<ILogFile>(); logFile.Setup(x => x.Count).Returns(100); dataSource.Setup(x => x.UnfilteredLogFile).Returns(logFile.Object); dataSource.Setup(x => x.FilteredLogFile).Returns(logFile.Object); var dataSourceViewModel = new Mock<IDataSourceViewModel>(); dataSourceViewModel.Setup(x => x.DataSource).Returns(dataSource.Object); dataSourceViewModel.Setup(x => x.VisibleLogLine).Returns(new LogLineIndex(42)); var logView = new LogViewerViewModel(dataSourceViewModel.Object, _dispatcher); _control.LogView = logView; _control.CurrentLogLine.Should().Be(42); _control.PartListView.CurrentLine.Should().Be(42); _control.PartListView.PartTextCanvas.CurrentLine.Should().Be(42); }
public void TestChangeLogView1() { // TODO: This test requires that the template be fully loaded (or the control changed to a user control) var oldLog = new Mock<IDataSourceViewModel>(); var oldDataSource = new Mock<IDataSource>(); var oldLogFile = new Mock<ILogFile>(); oldLogFile.Setup(x => x.Count).Returns(10000); oldDataSource.Setup(x => x.FilteredLogFile).Returns(oldLogFile.Object); oldDataSource.Setup(x => x.UnfilteredLogFile).Returns(new Mock<ILogFile>().Object); oldLog.Setup(x => x.DataSource).Returns(oldDataSource.Object); oldLog.SetupProperty(x => x.VisibleLogLine); oldLog.Object.VisibleLogLine = 42; var oldLogView = new LogViewerViewModel(oldLog.Object, _dispatcher); _control.LogView = oldLogView; var newLog = new Mock<IDataSourceViewModel>(); var newDataSource = new Mock<IDataSource>(); newDataSource.Setup(x => x.FilteredLogFile).Returns(new Mock<ILogFile>().Object); newDataSource.Setup(x => x.UnfilteredLogFile).Returns(new Mock<ILogFile>().Object); newLog.Setup(x => x.DataSource).Returns(newDataSource.Object); newLog.SetupProperty(x => x.VisibleLogLine); newLog.Object.VisibleLogLine = 1; var newLogView = new LogViewerViewModel(newLog.Object, _dispatcher); _control.LogView = newLogView; oldLog.Object.VisibleLogLine.Should() .Be(42, "Because the control shouldn't have changed the VisibleLogLine of the old logview"); newLog.Object.VisibleLogLine.Should() .Be(1, "Because the control shouldn't have changed the VisibleLogLine of the old logview"); }