Beispiel #1
0
        public void TestCtor1()
        {
            _mainWindow.Setup(x => x.SelectedSidePanel).Returns((string)null);

            var viewModel = new AnalyseMainPanelViewModel(_settings.Object,
                                                          _dataSources.Object,
                                                          _dispatcher,
                                                          _taskScheduler,
                                                          _analysisStorage.Object);

            const string reason = "because the settings don't have a panel selected and thus the view model should neither";

            viewModel.SelectedSidePanel.Should().BeNull(reason);
        }
        public void TestChangeName()
        {
            var viewModel = new AnalyseMainPanelViewModel(_settings.Object,
                                                          _dataSources.Object,
                                                          _dispatcher,
                                                          _taskScheduler,
                                                          _analysisStorage.Object);
            var analysis = new AnalysisViewModel(_dispatcher, new AnalysisViewTemplate(), new Mock <IAnalysis>().Object,
                                                 new Mock <IAnalysisStorage>().Object)
            {
                Name = "Foo"
            };

            viewModel.Analysis = analysis;
            viewModel.WindowTitle.Should().EndWith("Foo");

            analysis.Name = "Foobar";
            viewModel.WindowTitle.Should().EndWith("Foobar");
        }
        public void TestSelectAnalysis()
        {
            var viewModel = new AnalyseMainPanelViewModel(_settings.Object,
                                                          _dataSources.Object,
                                                          _dispatcher,
                                                          _taskScheduler,
                                                          _analysisStorage.Object,
                                                          _pluginRegistry);
            var analysisSidePanel = viewModel.SidePanels.OfType <AnalysesSidePanel>().First();

            viewModel.CreateAnalysisCommand.Execute(null);
            viewModel.CreateAnalysisCommand.Execute(null);
            analysisSidePanel.SelectedAnalysis = null;
            viewModel.SelectedAnalysis.Should().BeNull();

            foreach (var analysis in analysisSidePanel.Active)
            {
                analysisSidePanel.SelectedAnalysis = analysis;
                viewModel.SelectedAnalysis.Should().BeSameAs(analysis);
            }
        }
        public MainWindowViewModel(IApplicationSettings settings,
                                   DataSources dataSources,
                                   QuickFilters quickFilters,
                                   IActionCenter actionCenter,
                                   IAutoUpdater updater,
                                   ITaskScheduler taskScheduler,
                                   IAnalysisStorage analysisStorage,
                                   IDispatcher dispatcher,
                                   IPluginLoader pluginLoader)
        {
            if (dataSources == null)
            {
                throw new ArgumentNullException(nameof(dataSources));
            }
            if (quickFilters == null)
            {
                throw new ArgumentNullException(nameof(quickFilters));
            }
            if (updater == null)
            {
                throw new ArgumentNullException(nameof(updater));
            }
            if (dispatcher == null)
            {
                throw new ArgumentNullException(nameof(dispatcher));
            }

            _applicationSettings = settings;

            _plugins  = pluginLoader.Plugins;
            _settings = new SettingsMainPanelViewModel(settings);
            _actionCenterViewModel = new ActionCenterViewModel(dispatcher, actionCenter);

            _analysePanel = new AnalyseMainPanelViewModel(_applicationSettings, dataSources, dispatcher, taskScheduler, analysisStorage, pluginLoader);
            _analysePanel.PropertyChanged += AnalysePanelOnPropertyChanged;

            _logViewPanel = new LogViewMainPanelViewModel(actionCenter,
                                                          dataSources,
                                                          quickFilters,
                                                          _applicationSettings);
            _logViewPanel.PropertyChanged += LogViewPanelOnPropertyChanged;

            _timer = new DispatcherTimer
            {
                Interval = TimeSpan.FromMilliseconds(100)
            };
            _timer.Tick += TimerOnTick;
            _timer.Start();

            _autoUpdater                   = new AutoUpdateViewModel(updater, settings.AutoUpdate, dispatcher);
            _showLogCommand                = new DelegateCommand(ShowLog);
            _showGoToLineCommand           = new DelegateCommand2(ShowGoToLine);
            _showQuickNavigationCommand    = new DelegateCommand2(ShowQuickNavigation);
            _goToNextDataSourceCommand     = new DelegateCommand2(GoToNextDataSource);
            _goToPreviousDataSourceCommand = new DelegateCommand2(GoToPreviousDataSource);

            _analyseEntry = new AnalyseMainPanelEntry();
            _rawEntry     = new LogViewMainPanelEntry();
            _topEntries   = new IMainPanelEntry[]
            {
                _rawEntry,
                _analyseEntry
            };

            _settingsEntry = new SettingsMainPanelEntry();
            _pluginsEntry  = new PluginsMainPanelEntry();
            _aboutEntry    = new AboutMainPanelEntry();
            _bottomEntries = new[]
            {
                _settingsEntry,
                _pluginsEntry,
                _aboutEntry
            };

            var selectedTopEntry    = _topEntries.FirstOrDefault(x => x.Id == _applicationSettings.MainWindow.SelectedMainPanel);
            var selectedBottomEntry = _bottomEntries.FirstOrDefault(x => x.Id == _applicationSettings.MainWindow.SelectedMainPanel);

            if (selectedTopEntry != null)
            {
                SelectedTopEntry = selectedTopEntry;
            }
            else if (selectedBottomEntry != null)
            {
                SelectedBottomEntry = selectedBottomEntry;
            }
            else
            {
                SelectedTopEntry = _rawEntry;
            }
        }