public void Setup() { RxApp.MainThreadScheduler = Scheduler.CurrentThread; this.dialogNavigationService = new Mock <IDialogNavigationService>(); this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>(); this.filterStringService = new Mock <IFilterStringService>(); this.describeMetaData = new Mock <INameMetaData>(); this.describeMetaData.Setup(x => x.Name).Returns("MockedPanelDecorated"); this.panelView = new Test(true); this.panelViewModel = new TestViewModel(); this.panelViewModel2 = new TestViewModel("data source"); this.viewList = new List <IPanelView>(); this.viewList.Add(this.panelView); this.viewList.Add(new TestGrid()); this.viewModelDecoratedList = new List <Lazy <IPanelViewModel, INameMetaData> >(); this.viewModelDecoratedList.Add(new Lazy <IPanelViewModel, INameMetaData>(() => this.panelViewModel2, this.describeMetaData.Object)); this.viewModelList = new List <IPanelViewModel>(); this.viewModelList.Add(this.panelViewModel); this.viewModelList.Add(new TestGridViewModel()); this.dockLayoutViewModel = new DockLayoutViewModel(dialogNavigationService.Object); this.NavigationService = new PanelNavigationService(this.viewList, this.viewModelList, this.viewModelDecoratedList, this.dockLayoutViewModel, this.filterStringService.Object); this.session = new Mock <ISession>(); this.permissionService = new Mock <IPermissionService>(); this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object); }
public bool VerifyClosingCommandCancellation(bool userCancel) { var dialogStub = new Mock <IDialogNavigationService>(); dialogStub.Setup(d => d.NavigateModal(It.IsAny <IDialogViewModel>())) .Returns(new BaseDialogResult(userCancel)); var viewModel = new DockLayoutViewModel(dialogStub.Object); //Create panel view model stub var panelViewModelStub = new Mock <IPanelViewModel>(); panelViewModelStub.SetupAllProperties(); panelViewModelStub.SetupGet(p => p.IsDirty).Returns(true); //Add stub to dock view model viewModel.AddDockPanelViewModel(panelViewModelStub.Object); var args = new ItemCancelEventArgs(new LayoutPanel() { Content = panelViewModelStub.Object }); //Act viewModel.DockPanelClosingCommand.Execute(args); return(args.Cancel); }
public void VerifyViewModelIsSetAndSelectedWhenAdding() { var dialogMock = new Mock <IDialogNavigationService>(); var viewModel = new DockLayoutViewModel(dialogMock.Object); var panelViewModel = Mock.Of <IPanelViewModel>(); viewModel.AddDockPanelViewModel(panelViewModel); Assert.That(viewModel.DockPanelViewModels.Single(), Is.EqualTo(panelViewModel)); Assert.IsTrue(viewModel.DockPanelViewModels.Single().IsSelected); }
public PanelNavigationService( [ImportMany] IEnumerable <IPanelView> panelViewKinds, [ImportMany] IEnumerable <IPanelViewModel> panelViewModelKinds, [ImportMany] IEnumerable <Lazy <IPanelViewModel, INameMetaData> > panelViewModelDecorated, DockLayoutViewModel dockLayoutViewModel, IFilterStringService filterStringService) { var sw = new Stopwatch(); sw.Start(); logger.Debug("Instantiating the PanelNavigationService"); this.dockLayoutViewModel = dockLayoutViewModel; this.filterStringService = filterStringService; this.dockLayoutViewModel.DockPanelViewModels.ItemsRemoved.Subscribe(CleanUpPanelsAndSendCloseEvent); this.PanelViewKinds = new Dictionary <string, IPanelView>(); // TODO T2428 : PanelViewModelKinds seems to be always empty and is used only one time in the Open(Thing thing, ISession session) method. We should probably refactor this part of the code. this.PanelViewModelKinds = new Dictionary <string, IPanelViewModel>(); this.AddInViewModelViewPairs = new Dictionary <IPanelViewModel, IPanelView>(); this.PanelViewModelDecorated = new Dictionary <string, Lazy <IPanelViewModel, INameMetaData> >(); foreach (var panelView in panelViewKinds) { var panelViewName = panelView.ToString(); this.PanelViewKinds.Add(panelViewName.ToString(), panelView); logger.Trace($"Add panelView {panelViewName} "); } foreach (var panelViewModel in panelViewModelKinds) { var panelViewModelName = panelViewModel.ToString(); this.PanelViewModelKinds.Add(panelViewModelName, panelViewModel); logger.Trace($"Add panelViewModel {panelViewModelName} "); } foreach (var panelViewModel in panelViewModelDecorated) { var panelViewModelName = panelViewModel.Value.ToString(); var panelViewModelDescribeName = panelViewModel.Metadata.Name; this.PanelViewModelDecorated.Add(panelViewModelDescribeName, panelViewModel); logger.Trace($"Add panelViewModel {panelViewModelName} "); } sw.Stop(); logger.Debug($"The PanelNavigationService was instantiated in {sw.ElapsedMilliseconds} [ms] "); }
public void VerifyCloseCommandRemovesPanelViewModel() { var viewModel = new DockLayoutViewModel(Mock.Of <IDialogNavigationService>()); var panelViewModelStub = Mock.Of <IPanelViewModel>(); viewModel.AddDockPanelViewModel(panelViewModelStub); viewModel.DockPanelClosedCommand.Execute(new DockItemClosedEventArgs(null, new[] { new LayoutPanel() { Content = panelViewModelStub } })); Assert.IsEmpty(viewModel.DockPanelViewModels); }
public ShellViewModel(IDialogNavigationService dialogNavigationService, DockLayoutViewModel dockViewModel) { if (dialogNavigationService == null) { throw new ArgumentNullException(nameof(dialogNavigationService), "The dialogNavigationService may not be null"); } this.OpenSessions = new ReactiveList <ISession>(); this.OpenSessions.ChangeTrackingEnabled = true; this.OpenSessions.CountChanged.Select(x => x != 0).ToProperty(this, x => x.HasSession, out this.hasSession); CDPMessageBus.Current.Listen <SessionEvent>().Subscribe(this.SessionChangeEventHandler); this.dialogNavigationService = dialogNavigationService; this.DockViewModel = dockViewModel; this.Title = "COMET IME - Community Edition"; this.logTarget = new MemoryEventTarget(); this.logTarget.EventReceived += this.LogEventReceived; // Shall be done only once in the whole application CDP4SimpleConfigurator.AddTarget(this.ToString(), this.logTarget, LogLevel.Info); this.Sessions = new ReactiveList <SessionViewModel>(); this.Sessions.ChangeTrackingEnabled = true; this.Sessions.ItemChanged.Where(x => x.PropertyName == "IsClosed" && x.Sender.IsClosed) .Subscribe(x => this.Sessions.Remove(x.Sender)); this.Sessions.ItemChanged.Where(x => x.PropertyName == "IsClosed" && x.Sender.IsClosed) .Subscribe(x => this.CheckIfItIsSelectedSession(x.Sender)); this.Sessions.CountChanged.Subscribe(x => this.HasSessions = x != 0); this.OpenDataSourceCommand = ReactiveCommand.Create(); this.OpenDataSourceCommand.Subscribe(_ => this.ExecuteOpenDataSourceRequest()); this.SaveSessionCommand = ReactiveCommand.Create(); this.SaveSessionCommand.Subscribe(_ => this.ExecuteSaveSessionCommand()); this.OpenProxyConfigurationCommand = ReactiveCommand.Create(); this.OpenProxyConfigurationCommand.Subscribe(_ => this.ExecuteOpenProxyConfigurationCommand()); this.OpenUriManagerCommand = ReactiveCommand.Create(); this.OpenUriManagerCommand.Subscribe(_ => this.ExecuteOpenUriManagerRequest()); this.OpenPluginManagerCommand = ReactiveCommand.Create(); this.OpenPluginManagerCommand.Subscribe(_ => this.ExecuteOpenPluginManagerRequest()); this.OpenSelectIterationsCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.HasSessions)); this.OpenSelectIterationsCommand.Subscribe(s => this.ExecuteOpenSelectIterationsCommand(s as ISession)); this.CloseIterationsCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.HasOpenIterations)); this.CloseIterationsCommand.Subscribe(_ => this.ExecuteCloseIterationsCommand()); this.OpenDomainSwitchDialogCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.HasOpenIterations)); this.OpenDomainSwitchDialogCommand.Subscribe(_ => this.ExecuteOpenDomainSwitchDialogCommand()); this.WhenAnyValue(x => x.SelectedSession) .Select(x => (x != null)) .ToProperty(this, x => x.IsSessionSelected, out this.isSessionSelected); this.SelectedSession = null; this.OpenLogDialogCommand = ReactiveCommand.Create(); this.OpenLogDialogCommand.Subscribe(_ => this.ExecuteOpenLogDialog()); this.OpenAboutCommand = ReactiveCommand.Create(); this.OpenAboutCommand.Subscribe(_ => this.ExecuteOpenAboutRequest()); this.subscription = CDPMessageBus.Current.Listen <IsBusyEvent>() .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(x => { this.IsBusy = x.IsBusy; this.LoadingMessage = x.Message; }); this.CheckForUpdateCommand = ReactiveCommand.Create(); this.CheckForUpdateCommand.Subscribe(_ => this.ExecuteCheckForUpdateCommand()); this.OnClosingCommand = ReactiveCommand.CreateAsyncTask(async x => this.OnClosing(x as CancelEventArgs), RxApp.MainThreadScheduler); logger.Info("Welcome in the COMET Application"); }
public void VerifyViewModelInitialState() { var viewModel = new DockLayoutViewModel(Mock.Of <IDialogNavigationService>()); Assert.That(viewModel.DockPanelViewModels.Count(), Is.EqualTo(0)); }